一直在寻找和测试。
到目前为止我发现了什么:
- 处理程序.. 将soap 消息作为原始xml 输出到控制台输出这是非常好的解决方案。但是,对于HTTP标头(使用MimeHeaders),输出似乎太少了。例如在客户端我只得到
Accept : text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type : text/xml; charset=utf-8
Content-Length : 260
Run Code Online (Sandbox Code Playgroud)
- 系统属性
System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true");
System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", "true");
System.setProperty("com.sun.xml.ws.util.pipe.StandaloneTubeAssembler.dump", "true");
System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true");
System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dump", "true");
Run Code Online (Sandbox Code Playgroud)
这是完美的输出到控制台、完整的 http 标头和肥皂消息。但不能自定义用于日志记录、操作标题/消息。这是一个示例
---[HTTP request - http://localhost:8080/Testmart/TestMartCatalogService]---
Accept: text/xml, multipart/related
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
User-Agent: JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getProducts xmlns:ns2="http://www.testmart.com"><arg0>books</arg0></ns2:getProducts></S:Body></S:Envelope>--------------------
---[HTTP response - http://localhost:8080/Testmart/TestMartCatalogService - …Run Code Online (Sandbox Code Playgroud) 我找到了针对此异常和原因的多种解决方案,但都没有奏效,而且似乎不合逻辑。
我有如下 REST 服务类
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.MediaType;
import java.util.Map;
@RestController
public class UserRestService {
@RequestMapping(value = "/userLogin", method = RequestMethod.POST, produces = MediaType.APPLICATION_XML_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody ResponseEntity<Map> login(@RequestBody Map<String, String> name) {
ResponseEntity<Map> res = null;
name.values().forEach(System.out::println);
return new ResponseEntity<Map>(name, HttpStatus.OK);
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我尝试创建一个 POST 请求,请求主体为 JSON,响应为 XML,在此过程中打印请求。这只是一个简单的例子,但是当请求被正确打印时,这意味着它已被接收并编组到 Map。但是响应状态是 406(不可接受)
日志中的异常是
John
30
null
2018-08-16 14:05:48.440 WARN 22820 --- [nio-8080-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable …Run Code Online (Sandbox Code Playgroud) http ×1
http-headers ×1
jackson ×1
jakarta-ee ×1
jaxb ×1
soap ×1
spring-boot ×1
web-services ×1
xml ×1