File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes Pretty Print SOAP message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Pretty Print SOAP message" Watch "Pretty Print SOAP message" New topic

Pretty Print SOAP message

Daniel Larusso

Joined: Sep 05, 2006
Posts: 2
This is kind of a newbie question... i'm trying to pretty print my request SOAP message after a javax.xml.rpc.GenericHandler implementation adds in some custom headers in my client code.

Any idea how i do this? I'm basically trying to log the contents of the SOAPEnvelope object. Here is the code im working with:

SOAPMessageContext smc = (SOAPMessageContext)context;
SOAPEnvelope se = smc.getMessage().getSOAPPart().getEnvelope();
Daniel Larusso

Joined: Sep 05, 2006
Posts: 2
Sorry... I should have RTFM'ed a little more. SOAPMessage has a function called "writeTo" that takes an OutputStream... Solved the printing problem, but it doesn't pretty print the SOAP message.
Watsh Rajneesh
Ranch Hand

Joined: Apr 17, 2006
Posts: 110
You can use the following code to pretty print the soap message xml (code excerpted from samples code with XercesJ 2.8.0 distribution).

The usage for above writer is:
Writing to Stream:

Writing to std out:

where, xmlDoc is of type org.w3c.dom.Document but you can pass a SOAPMessage org.w3c.dom.Node type too.
[ September 11, 2006: Message edited by: Watsh Rajneesh ]

SCJP 5.0 (90%), SCDJWS 1.4 (88%), SCWCD 1.4 (82%), SCBCD 1.3 (85%)
I agree. Here's the link:
subject: Pretty Print SOAP message
It's not a secret anymore!