I would try a few obvious things.
First read the entire inputstream into a string and print out the string
that you got.
Reference that instead of the stream in the SOAPMessage creation. This
is just to verify you got what you think you were getting.
Change the code that does the println to a series of assignments to
local variables, first extracting the soap body, then the first child,
and then the local name. Print out each of these.
Step through this code in the debugger and examine the objects being
created.
________________________________
From: RICO [mailto:riccardo.bussandri_at_gmail.com]
Sent: Thursday, December 04, 2008 8:29 AM
To: users_at_saaj.dev.java.net
Subject: [SAAJ-USR] getSOAPBody problem
Hi,
I have a problem with saaj 1.3 and JDK 1.6
I have a simple servlet that creates a SOAPMessage beginning
from an InputStream.
When I try to get anything from the SOAPMessage (see System.out
line) I get null in console, but if I use the writeTo() method, it
works, so it seems that the object is properly created.
I need to use getSOAPBody() method to access and parse the SOAP
message.
Note: with JDK 1.5 this code works properly, but to use some
other libraries I must use JDK 1.6.
What's wrong in my code updating from JDK 1.5 to 1.6?
(In attachment java code and below the SOAP message code)
Thanks a lot
Riccardo
Here the code:
public void doPost(HttpServletRequest req, HttpServletResponse
res) throws ServletException, IOException {
res.setContentType("text/xml; charset=utf-8");
SOAPMessage soapReq = null;
SOAPMessage soapRes = null;
try {
MessageFactory msgFactory =
MessageFactory.newInstance();
soapReq = msgFactory.createMessage(null,
req.getInputStream());
soapReq.saveChanges();
soapRes = msgFactory.createMessage();
System.out.println(soapReq.getSOAPBody().getFirstChild().getLocalName())
;
soapReq.writeTo(res.getOutputStream());
} catch (SOAPException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
and the SOAP message I tried:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="
http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="
http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:doubleAnInteger
xmlns:ns1="urn:MySoapServices">
<param1 xsi:type="xsd:int">123</param1>
</ns1:doubleAnInteger>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>