Debug HTTP request of Java SOAP JAX-WS web service client

less than 1 minute read

Today I wanted to debug in Java a JAX-WS SOAP web service client and see the exact message that is send as an HTTP request. So after searching, I found in this StackOverflow question that if we insert the following lines before calling the service:

System.setProperty("", "true");
System.setProperty("", "true");
System.setProperty("", "true");
System.setProperty("", "true");

when we call the service it will produce the following output in logs (or console output):

---[HTTP request - http://localhost:9090/ContactRequestServicePort]---
Accept: text/xml, multipart/related
Content-Type: text/xml; charset=utf-8
SOAPAction: "newContact"
User-Agent: JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e
<?xml version="1.0" ?><S:Envelope xmlns:S=""><S:Body><ns2:newContact xmlns:ns4="" xmlns:ns3="" xmlns:ns2=""><ns2:contact><ns2:prefix>Mr</ns2:prefix><ns2:name>John</ns2:name><ns2:surname>Longjohn</ns2:surname></ns2:contact></ns2:newContact></S:Body></S:Envelope>--------------------

It works! Now we have the entire HTTP request and we can pretty print the XML which is included in the message body of HTTP request to see what we send to the web service:

<?xml version="1.0" ?><S:Envelope xmlns:S="">
        <ns2:newContact xmlns:ns4="" xmlns:ns3="" xmlns:ns2="">