Hi RICO,
Using JDK 6 I can print the value of
"soapReq.getSOAPBody().getFirstChild().getLocalName()" ,which is
'suresh' according sample code given below.
Can you provide the sample code that you are using so that we can try
to reproduce the error?
Thanks
Suresh
Sample Code:
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage msg = mf.createMessage(); SOAPPart sp =
msg.getSOAPPart();
SOAPEnvelope envelope = sp.getEnvelope();
SOAPHeader hdr = envelope.getHeader();
SOAPBody bdy = envelope.getBody();
// Add to body
SOAPBodyElement temp = bdy.addBodyElement(
envelope.createName("suresh", "status",
"
http://www.sun.com"));
temp.addChildElement(envelope.createName("suresh",
"status","
http://www.sun.com")).addTextNode("xwss");
temp.addChildElement("Kumar").addTextNode("Techlead");
System.out.println(msg.getSOAPBody().getFirstChild().getLocalName());
...
...
Output Produced: suresh
------=_Part_0_9627532.1228821446187
Content-Type: text/xml; charset=utf-8
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="
http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><status:suresh
xmlns:status="
http://www.sun.com"><status:suresh>xwss</status:suresh><Kumar>Techlead</Kumar></status:suresh></SOAP-ENV:Body></SOAP-ENV:Envelope>
------=_Part_0_9627532.1228821446187
V B Kumar Jayanti wrote:
> RICO wrote:
>> Thanks you for quickly replies:
>>
>> david wrote:
>>
>> 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.
>>
>> I read the InputStream from jsp page in a String and it appears
>> correct, I tried to debug sending SOAP message below and adding the line:
>>
>> SOAPBody sb = soapReq.getSOAPBody();
>>
>> I've noticed for example that the firstChild field in sb object
>> counts 5 chars (the first is a "\n" and the others empty). I did
>> debug on other objects as SOAPPart: all fields seem empty (except
>> namespaceURI and inherent fields).
>>
>> The Application Server that I'm using is Tomcat 6.0.16, I think my
>> problem is about some jar library that I need to add to my classpath
>> updating from JDK 1.5 to JDK 1.6 (I've tried with 1.6.0_07 and
>> 1.6.0_10), but I don't know which it can be.
>>
>> kumar wrote:
>>
>> If it works with JDK 1.5, it should have worked with JDK 1.6 as well.
>> The differernce i can imagine is JAXP between your JDK 1.5 and 1.6
>> runs. Can you check the JAXP which gets used in both.
>>
>> Is your suggestion "in your classpath are present jaxp-api.jar and
>> jaxp-ri.jar"?
>> Because compiling with JDK 1.5 I haven't them in my classpath and the
>> code works.
> No i meant a different version of JAXP would be in JDK 1.5 and JDK
> 1.6. I will try to reproduce it my end and get back. Tell me where
> did you get the SAAJ from for use with JDK 1.5. JDK 1.6 has its own
> builtin version of SAAJ.
>
> regards,
> kumar
>
>>
>>
>> Below java code and SOAP message.
>>
>> Thanks
>>
>> Riccardo
>>
>> 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();
>> SOAPBody sb = soapReq.getSOAPBody();
>> soapRes = msgFactory.createMessage();
>>
>>
>> System.out.println(soapReq.getSOAPBody().getFirstChild().getLocalName());
>> soapReq.writeTo(res.getOutputStream());
>>
>> } catch (SOAPException e) {
>> e.printStackTrace();
>> } catch (Exception e) {
>> e.printStackTrace();
>> }
>> }
>>
>>
>> ********** SOAP Message *********
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <soapenv:Envelope
>> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
>> <soapenv:Body>
>> <get_SAserviceDetail>
>> <input_1>
>> <concept name="ItalianWine" multiplicity="1"/>
>> </input_1>
>> <output_1>
>> <concept name="Winery" multiplicity="1"/>
>> </output_1>
>> </get_SAserviceDetail>
>> </soapenv:Body>
>> </soapenv:Envelope>
>