• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Best way to print a JAXWS request and response

 
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic