| Author |
Best way to print a JAXWS request and response
|
Arjun Reddy
Ranch Hand
Joined: Nov 10, 2007
Posts: 622
|
|
Hi All,
I want to be able to print the request and response in the logs and was wondering whats the best way to do it.
Thanks,
Arjun
|
Be Humble... Be Nice.
|
 |
Christopher Nortje
Greenhorn
Joined: Jul 09, 2010
Posts: 16
|
|
Have a look at JAX-WS Handler’s.
http://www.java-tips.org/java-ee-tips/java-api-for-xml-web-services/writing-a-handler-in-jax-ws.html
|
 |
Alex Hurtt
Ranch Hand
Joined: Oct 26, 2010
Posts: 98
|
|
If you are using the sun/oracle reference implementation I believe you can set the following system property which is slightly easier than inserting a custom handler in the handler chain.
com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true
|
 |
Arjun Reddy
Ranch Hand
Joined: Nov 10, 2007
Posts: 622
|
|
Thanks Christopher and Alex for replying.
Christopher- I was looking at the link you replied back and I have a question. How do I get a reference to the SOAPMessageContext?
|
 |
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
|
|
|
The handleMesssge method that you will implement takes a reference to SOAPMessageContext.
|
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
|
 |
Arjun Reddy
Ranch Hand
Joined: Nov 10, 2007
Posts: 622
|
|
Bosun Bello wrote:The handleMesssge method that you will implement takes a reference to SOAPMessageContext.
Sorry I meant, I need to call the handleMessage method passing in the SoapMessageContext right? So How do I get the SoapMessageContext?
Thanks.
|
 |
Alex Hurtt
Ranch Hand
Joined: Oct 26, 2010
Posts: 98
|
|
Arjun Reddy wrote:Thanks Christopher and Alex for replying.
Christopher- I was looking at the link you replied back and I have a question. How do I get a reference to the SOAPMessageContext?
If you're going to go the handler route, then if you need a SOAPMessageContext you should write a Handler that implements SOAPHandler. The JAXWS runtime will pass the handleMessage() method of your handler an instance of SOAPMessageContext. From the SOAPMessageContext you can get a SOAPMessage with the getMessage() method. This will allow you programmatic access to all elements of the entire SOAP message envelope. If, on the other hand, you only need access to the message body payload, you can implement the LogicalHandler interface in which case the JAXWS runtime will give the handleMessage() method a LogicalMessageContext on which you may invoke getMessage() to obtain a LogicalMessage. From this LogicalMessage you can invoke one of its getPayload(...) methods to get the body contents of the message as a couple different types...
Better yet...here, read this: http://jax-ws.java.net/articles/handlers_introduction.html
and this:
http://download.oracle.com/javase/6/docs/api/index.html?javax/xml/ws/handler/soap/SOAPMessageContext.html
|
 |
Alex Hurtt
Ranch Hand
Joined: Oct 26, 2010
Posts: 98
|
|
Arjun Reddy wrote:
Bosun Bello wrote:The handleMesssge method that you will implement takes a reference to SOAPMessageContext.
Sorry I meant, I need to call the handleMessage method passing in the SoapMessageContext right? So How do I get the SoapMessageContext?
Thanks.
You don't explicitly call your handleMessage() method. You just implement it and the JAXWS runtime will invoke it for you at the appropriate point in the message handling chain assuming you have registered your handler with the JAXWS runtime either programmatically or by external XML configuration somehow.
|
 |
Arjun Reddy
Ranch Hand
Joined: Nov 10, 2007
Posts: 622
|
|
Alex Hurtt wrote:
Arjun Reddy wrote:
Bosun Bello wrote:The handleMesssge method that you will implement takes a reference to SOAPMessageContext.
Sorry I meant, I need to call the handleMessage method passing in the SoapMessageContext right? So How do I get the SoapMessageContext?
Thanks.
You don't explicitly call your handleMessage() method. You just implement it and the JAXWS runtime will invoke it for you at the appropriate point in the message handling chain assuming you have registered your handler with the JAXWS runtime either programmatically or by external XML configuration somehow.
Thanks a lot Alex. I am able to print the request and response now to the logs. I have one question though. Right now, its printing in one line and is hard to verify. How do I print it properly?
|
 |
 |
|
|
subject: Best way to print a JAXWS request and response
|
|
|