Published on

How to Print Out Jaxb Requests and Responses

Authors

When testing a web service client it is significantly easier to see what is going on if you can see what XML requests and responses looks like. There are a number of ways of doing this like adding a SOAP handler into your client that logs out all requests and responses. This is amazing for production but while deving we want something faster. You could use something like Wireshark or Fiddler to intercept requests. With Fiddler you would add the following JVM arguments to make Fiddler a proxy so you can intercept requests:

-DproxySet=true -DproxyHost=127.0.0.1 -DproxyPort=8888

But this is also a bit cumbersome.

The quickest and easier approach I have found is to set the following system variables when you initialize your test class which outputs the request, response and headers to the console:

init {
 System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true")
 System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", "true")
 System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true")
 System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dump", "true")
}