Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log SOAP messages & HTTP headers programmatically in server or client side?

Been searching for long on this and testing.

I want simply to log SOAP message details and the transport protocol request/response (header) along with it.

What I've found so far:

- Handlers .. to output the soap messages as raw xml on console output this is very good solution. However, for HTTP header (MimeHeaders used) it seems the output is too little. For example on client I get only

Accept : text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type : text/xml; charset=utf-8
Content-Length : 260

- System properties

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.util.pipe.StandaloneTubeAssembler.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");

This is perfect as output to the console, full http headers & soap message. But not customize-able for logging, manipulating the header/message. Here is a sample

---[HTTP request - http://localhost:8080/Testmart/TestMartCatalogService]---
Accept: text/xml, multipart/related
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
User-Agent: JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getProducts xmlns:ns2="http://www.testmart.com"><arg0>books</arg0></ns2:getProducts></S:Body></S:Envelope>--------------------

---[HTTP response - http://localhost:8080/Testmart/TestMartCatalogService - 200]---
null: HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 414
Content-Type: text/xml;charset=UTF-8
Date: Sat, 30 Sep 2017 11:42:56 GMT
Server: JBoss-EAP/7
X-Powered-By: Undertow/1
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/><soap:Body><ns1:getProductsResponse xmlns:ns1="http://www.testmart.com"><return xmlns=""><item>Inferno</item><item>Joyland</item><item>The Game Of Thrones</item></return></ns1:getProductsResponse><TestBodyElement>hahahaha</TestBodyElement></soap:Body></soap:Envelope>--------------------

- Eclipse TCP/IP Monitor OR WireShark

Both are perfect for monitoring as the previous solution but programmatic solution like the first one with output like this (or previous) solution would extremely perfect to control it inside the code.

So is there another way or something I might missed to use like the Handlers or in the Handlers that would output details like the dump configuration does ? Any suggestions are very appreciated.

like image 339
Anddo Avatar asked Oct 29 '22 01:10

Anddo


1 Answers

The solution I is by using getResponseContext()

Map<String, Object> responseHeaders;
responseHeaders = sourceDispatch.getResponseContext();
Object cookie = responseHeaders.get("javax.xml.ws.http.response.headers");
like image 165
Muhammad Attia Avatar answered Nov 09 '22 23:11

Muhammad Attia