Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do you see the xml being sent when you invoke a service on a JAX-WS generated client?

 
Rob Dennett
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I generated client classes from wsimport for a wsdl I am supposed to interface with. When I invoke a method on the web service, e.g. public FooResponse getFoo(FooRequest request), is there a way to view the xml that is being sent to the service?

Thanks,
Rob
 
Gaurav.S Singh
Greenhorn
Posts: 5
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use wsmonitor

This tool, wsmonitor, is a light-weight, easy to use SOAP and HTTP traffic monitoring tool. This tool uses port forwarding to capture the SOAP messages and HTTP headers between a sender and a receiver and displays them nicely formatted in a graphical user interface.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SOAPui is another widely used tool for this.

Bill
 
Yogesh Gandhi
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I log the SOAP XML into the log file?
How can I?

I have the object that is being passed to the web service function.

Let say

enquire(Employee e)


I want the contents of the SOAP request XML to be logged into the log file for later debugging if required.

Is it possible?
 
Venkataprasath Padmanabhan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using any frameworks like Apache CXF or Metro.. for your webservices or client?
 
Rob Dennett
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I too would like to know how to log the xml request and response (and preferably intercept it so I can scrub it). I am just using the client I generated from wsimport. I don't believe I am using cxf or metro or axis, but I am not that experienced with web services. The client is running out of a Tomcat instance.

Can you create a javax.xml.ws.handler.LogicalHandler and use that to act as a filter?

Thanks,
Rob
 
Rob Dennett
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It worked. I created a class that implements LogicalHandler<LogicalMessageContext> and cast the service stub to a javax.xml.ws.BindingProvider and added handler to the binding provider's binding's handler chain.

Rob
 
Yogesh Gandhi
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rob,

i am very new to webservices.
can you please share the detailed code and steps using which anyone can log webservices into log file.

i am ready to write a blog on this information so that people googling it can find it on net.

request you to please share detailed steps and code if possible for beginners.
 
Rob Dennett
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the way it works is that I created a class which implements javax.xml.ws.handler.LogicalHandler<javax.xml.ws.handler.LogicalMessageContext>. In the handleMessage method, I take the LogicalMessageContext and extract the javax.xml.ws.LogicalMessage from it and use a javax.xml.transform.Transformer to transform javax.xml.ws.LogicalMessage.getPayload() into a StreamResult (which is wrapping a ByteArrayOutputStream().



 
Chintan B Shah
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using METRO 2.0 library, you can do the following in your code to see HTTP Request/Response on console(client side setting).

HttpTransportPipe.dump = true;


package to import:
import com.sun.xml.ws.transport.http.client.HttpTransportPipe;

You can do this just before invoking SOAP Call.

Thanks
Chintan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic