spring-projects / spring-ws-samples

151 stars 132 forks source link

Content-Type needs to be Multipart/Related and with "type=text/xml" or "type=application/soap+xml" #12

Closed mwyrembl closed 4 years ago

mwyrembl commented 4 years ago

I am getting the following exception when trying to use MTOM in my web service client:

Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Content-Type needs to be Multipart/Related and with "type=text/xml" or "type=application/soap+xml" at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType(MessageImpl.java:629) at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.(MessageImpl.java:301) at com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl.(Message1_1Impl.java:65) at com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl.createMessage(SOAPMessageFactory1_1Impl.java:63) at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:190) ... 86 common frames omitted

The message looks like this:

[13.08.2020 10:32:02.320][https-jsse-nio-9998-exec-6 ][DEBUG][WebServiceAccessor.createConnection:111 ] Opening [org.springframework.ws.transport.http.HttpComponentsConnection@767912eb] to [http://localhost:9080/soap/services/FormsService?blob=mtom] [13.08.2020 10:32:02.397][https-jsse-nio-9998-exec-6 ][TRACE][WebServiceTemplate.sendRequest:653 ] Sent request [------=_Part_0_1137162597.1597307522369 Content-Type: application/xop+xml; charset=utf-8; type="text/xml"

... ------=_Part_0_1137162597.1597307522369 Content-Type: application/octet-stream Content-ID: <9e0a6621-0d82-43e7-b9c7-51de49ac37be@adobe.com> Content-Transfer-Encoding: binary ... ------=_Part_0_1137162597.1597307522369--] [13.08.2020 10:32:04.208][https-jsse-nio-9998-exec-6 ][ERROR][MessageImpl.identifyContentType:628 ] SAAJ0536: Content-Type needs to be Multipart/Related and with type=text/xml or application/soap+xml **I am using the following JRE:** openjdk version "1.8.0_222" OpenJDK Runtime Environment (Zulu 8.40.0.25-CA-win64) (build 1.8.0_222-b10) OpenJDK 64-Bit Server VM (Zulu 8.40.0.25-CA-win64) (build 25.222-b10, mixed mode)
gregturn commented 4 years ago

In our MTOM sample, the incoming enclosing request from the client is: Content-Type: application/xop+xml; charset=utf-8; type="text/xml", the same as yours.

Not quite sure what is breaking. Do you control the server? And how is your client different from our sample client?

mwyrembl commented 4 years ago

It seems that the problem is not the request but the response from the server. It has a Content-Type of:

Content-Type: multipart/related;type="application/xop+xml"; start=""; boundary="----=_Part49-217830039.1597324770713"

Because it responds with a MTOM message as well. But in the JRE there is a check in com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType that throws this exception because it expects the type to be text/xml or application/soap+xml but it is actually application/xop+xml.

Is it not allowed to get a MTOM response from the server or do you have an example for a web service client that sends a MTOM message and also receives a MTOM message as a response?

mwyrembl commented 4 years ago

The probem is that the server does not send the "start-info" Parameter in the Content-Type. That's why the check in "isMimeMultipartXOPSoap1_1Package" returns false and the last else branch throws the exception then. I have to check that with the service provider of the web service.