How do you print a SOAP response? I have been trying to do the following but its not printing the actual soap message. Its just giving me some sort of description.

SOAPMessage reply = connection.call(message, destination);
String myreply = reply.getSOAPPart().getContent().toString();

Try writeTo method of the SOAPMessage abstract class: message.writeTo(System.out);

Thanks for the quick response. The problem I was having using the WriteTo method is I need to store the SOAP message in a string to output to a JTextArea. Is there an easy way to do this? Sorry I am still new to java.

There are two ways:
- You can either call the getSOAPBody() and getSOAPHeader() methods and manually construct the entire pretty-printed SOAP message
- Use the ByteArrayOutputStream class instance and pass it to the writeTo() method. Retrieve the resulting string using the getString() method or use new String(outputStream.getBytes(), "UTF-8") in case you are using a specific encoding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.