aspose file tools*
The moose likes Web Services and the fly likes How do you see the xml being sent when you invoke a service on a JAX-WS generated client? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "How do you see the xml being sent when you invoke a service on a JAX-WS generated client?" Watch "How do you see the xml being sent when you invoke a service on a JAX-WS generated client?" New topic
Author

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

Rob Dennett
Ranch Hand

Joined: Dec 07, 2010
Posts: 81
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

Joined: Feb 04, 2012
Posts: 5

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

Joined: Mar 22, 2000
Posts: 12825
    
    5
SOAPui is another widely used tool for this.

Bill
Yogesh Gandhi
Ranch Hand

Joined: Dec 05, 2008
Posts: 212
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

Joined: Jul 14, 2011
Posts: 10
Are you using any frameworks like Apache CXF or Metro.. for your webservices or client?
Rob Dennett
Ranch Hand

Joined: Dec 07, 2010
Posts: 81
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

Joined: Dec 07, 2010
Posts: 81
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

Joined: Dec 05, 2008
Posts: 212
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

Joined: Dec 07, 2010
Posts: 81
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

Joined: Sep 23, 2008
Posts: 83
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.


SCJA 1.0
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How do you see the xml being sent when you invoke a service on a JAX-WS generated client?