Question

I have a problem related to parsing a SOAP message.
This is the message:

------=_Part_3_5438437.1107262647279

Content-Type: text/xml

<?xml version="1.0" encoding="UTF-8"?>
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Body>
    <content>
     [...]
     </content>
  </soap-env:Body>
</soap-env:Envelope>

------=_Part_3_5438437.1107262647279
Content-Type: text/plain; charset=ISO-8859-1

text
------=_Part_3_5438437.1107262647279--

This is an extract of my Java servlet, which should receive and parse the message:

messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
message = messageFactory.createMessage(mimeHeaders, req.getInputStream());

To test the servlet, I'm using JMeter. I put the SOAP message in the raw post body of an HTTP Request. In the header I put this: Content-type multipart/related;boundary=----=_Part_3_5438437.1107262647279

Problem number 1: it seems that the parsing in SAAJ is bugged, because debugging I see that boundary is seen as ----null, as if = can be used as a token and nothing more. So I removed it, both from the body and from the header. This is a huge problem, because I can't change the input I receive, but let's pretend I can for a while. Ok, this moves me forward to problem number 2: now the boundary is parsed correctly, but I obtain this exception: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Bad Content-Type for SOAP Part : text/plain

Ok, I believe I know how to solve it, I have to add the type in Content-type header: Content-type multipart/related;type=text/xml;boundary=----_Part_3_5438437.1107262647279

Yes, but of course I have another nasty exception: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Unable to internalize message at com.sun.xml.messaging.saaj.soap.MessageImpl.parseContentType(MessageImpl.java:337)

I'm using saaj-impl-1.3.18 and saaj-api-1.3.3.
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11-402-11D50b)
Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode)

Was it helpful?

Solution

The solution to problem number 2 lies in the empty line here:

------=_Part_3_5438437.1107262647279

Content-Type: text/xml

It must go away, otherwise the content type is assumed to be text/plain by default. Thanks to Brian Joh http://twitter.com/brianwjoh for pointing this out.
For problem number 1 I solved it simply by putting boundary value between ". The same apply for type.

 type="text/xml";boundary="----=_Part_3_5438437.1107262647279"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top