File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SOAP response is losing Body content data

 
mark weitz
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a problem sending my SOAP message back. I have taken an example from the Sun application server. It has a simple JSP that submits to a sending servlet whcih constructs the outgoing SOAP message, opens a connection and sends it out. The receiving servlet exists on the same application server and recieves the messgaes, gets parts of the content from the SOAP message and then builds a simple response to send back.

When I run the Sun sample on the Sun application server, it works fine. When I run it under WebSphere application server, my reply message is constructed correctly but when it gets sent back to the sending servlet, the body content has disappeared.

In the receiving servlet I receive the SOAP message with no problem and can extract data from it. I then build the SOAP response and print it to to System.out just before writing it to the output stream:

System.out.println("\n************** message being sent back***************\n");
reply.writeTo(System.out);

// Write out the message on the response stream.
OutputStream os = resp.getOutputStream();
reply.writeTo(os);

os.flush();

Here is what my System.log file looks like. You can see the Body contains <Response xmlns="">This is a response</Response>.

************** message being sent back***************

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<Response xmlns="">This is a response</Response>
</soapenv:Body>
</soapenv:Envelope>


Immediately upon return from the SOAPConnection.call method in my sending servlet, I take the SOAP response message and again write it to System.out:


SOAPMessage reply = conn.call(msg, endPoint);

System.out.println("\n*****immediately after connection.call, reply is*****\n");
reply.writeTo(System.out);

Here is what my System.log file looks like after this executes. Note that I get the Response tag in the body but my data has vanished: <Response xmlns=""/>

*****immediately after connection.call, reply is*****

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<Response xmlns=""/>
</soapenv:Body>
</soapenv:Envelope>


When this code executes on the Sun application server, I get body content like this: <Response>This is a response</Response>. When I execute on WebSphere I get body content like this: <Response xmlns="">This is a response</Response> with with the xmlns=�� being added (I assume by the WebSphere soap implementation).


Can anyone explain why my body content is being removed? Any suggestions on how to fix this problem?

I've tried with an without a namespace on the body text nodes. I've tried using addBodyElement and addChildElement but no lcuk there either.

I am using WebSphere 5.1 and have not added any additional jars to WebSphere (e.g. from Java WS Dev Pack 1.6)


Thanks.
 
mark weitz
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found a solution to this problem. This is a WebSphere specific problem. It works fine under other application servers (Sun).

The response message contained one element with data.

<soapenv:Body>
<Response xmlns="">This is a response</Response>
</soapenv:Body>

However, for some reason, the WebSphere SOAP processing was stripping out the text of the Response element and returning an empty node (e.g., <Response xmlns=""/> .

To get around this problem, I moved the text node down one element

<soapenv:Body>
<Response xmlns="">
<ResponseData xmlns="">This is a response</ResponseData>
</Response>
</soapenv:Body>

By adding the extra element and moving the data down to that element, the SOAP response comes back correctly.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic