Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Best way to print a JAXWS request and response

 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Christopher Nortje
Greenhorn
Posts: 16
 
Alex Hurtt
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The handleMesssge method that you will implement takes a reference to SOAPMessageContext.
 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!