通过 SOAP 代理 spring 不支持的媒体类型 multipart/related;类型="application/xop+xml";边界

Pass through SOAP proxy spring Unsupported media type multipart/related; type="application/xop+xml"; boundary

您好,我正在尝试通过 spring 中的@RestController 实现 SOAP 代理传递。为此,我按以下方式映射了一个休息控制器:

@RestController
class MyProxy {

@PostMapping(value = "/**")  
  public ResponseEntity<String> proxyPost(@RequestBody(required = false) String body, HttpServletRequest request) {}
}

常规 SOAP 请求正常。当通过代理发送 MTOM 类型的 SOAP 请求时,问题就来了。然后 spring 因无法识别的内容类型而失败。这是例外情况:

Caused by: org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is javax.servlet.ServletException: Unsupported Content-Type [multipart/related; type="application/xop+xml"; boundary="uuid:dacf4733-80b4-41bc-b2e1-db69b6beadf6"; start="<root.message@cxf.apache.org>"; start-info="text/xml"], expected [multipart/form-data]
    at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.handleParseFailure(StandardMultipartHttpServletRequest.java:124)
    at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:115)
    at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:88)
    at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:122)
    at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1205)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
    ... 60 common frames omitted
Caused by: javax.servlet.ServletException: Unsupported Content-Type [multipart/related; type="application/xop+xml"; boundary="uuid:dacf4733-80b4-41bc-b2e1-db69b6beadf6"; start="<root.message@cxf.apache.org>"; start-info="text/xml"], expected [multipart/form-data]
    at org.eclipse.jetty.server.Request.getParts(Request.java:2407)
    at javax.servlet.http.HttpServletRequestWrapper.getParts(HttpServletRequestWrapper.java:317)
    at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:95)
    ... 66 common frames omitted

当收到 multipart/* 请求时,Spring 将此委托给配置的多部分处理程序。这是默认启用的,对于这种情况应该禁用。

spring.servlet.multipart.enabled=false

将以上内容添加到您的属性中应该会禁用它并阻止解析,因此您可以在控制器中处理它。