Printing SOAP messages

Metro has a (proprietary, may change at any time) feature that provides read access to the SOAP messages that a client exchanges with a web service. That allows to display the SOAP messages to users or log them for diagnostic purposes. Metro can be configured extensively to log SOAP messages and other properties, see http://blogs.sun.com/arungupta/entry/message_logging_in_wsit_updated, but with this feature it is possible to get the content of SOAP messages at run-time and process them with your own code any way you like.

This feature hinges on the use of the internal class com.sun.xml.ws.assembler.MessageDumpingFeature. It is very simple to use. Here is some sample code:

import com.sun.xml.ws.assembler.MessageDumpingFeature;
...

    // Prepare to plug in the code that allows to read SOAP messages
    MessageDumpingFeature messageDumper = new MessageDumpingFeature();

    // Instantiate the web service client
    YourService service = new YourService();

    // Plug in the SOAP message dumper
    YourPort port = service.getYourServicePort(messageDumper);

    // Invoke the web service
    YourResult result = port.yourmethod(yourparameter);

    // Read the SOAP messages that were exchanged
    String request = messageDumper.nextMessage();
    String response = messageDumper.nextMessage();
    ...

The Strings request and response will hold the SOAP messages that were exchanged in clear text. The same approach works with a dispatch client as well.

Tags: , , , ,

Comments:

Hi Fabian,
I have downloaded the latest WSIT jar, but the class com.sun.xml.ws.assembler.MessageDumpingFeature cannot be found in any jar provided. Where can I get this class (i.e. appropriate jar containing it)?
Cheers,
Jiri

Posted by Jiri Biba on July 01, 2008 at 09:32 AM EEST #

The binaries on the WSIT site are not updated anymore. Download the current code from https://metro.dev.java.net/ . I just downloaded from https://metro.dev.java.net/1.2/ and it definitely has the MessageDumpingFeature.

Posted by Fabian Ritzmann on July 01, 2008 at 09:48 AM EEST #

Thanks a lot, it seems to be in the webservices-rt.jar.

BTW, is there already a class providing a more convinient dumping than via the stdout - e.g. to a specified stream (StringBuffer or sth)?

Posted by Jiri Biba on July 01, 2008 at 10:52 AM EEST #

Ahh, sorry, ignore the former post regarding the stream - I can get it into a String. I was actually referring to another post somewhere else mentioning properties to be set which enabled dumping to stdout.

Anyway, how does all this tweek exactly work? Is the MessageHandlingFeature instantiation to be deployed within the project containing the web services (or actually within the service clases) to be dumped or is it enough to deploy any project and all the SOAP trafic going through Metro is dumped? Basically, I need to write a monitor filtering the SOAP dumps and reporting some of the SOAP calls somewhere else...

Posted by Jiri Biba on July 01, 2008 at 10:58 AM EEST #

You pass the MessageDumpingFeature instance into the web service client, see the example code in my blog entry. From then on, this object will record all SOAP messages between the client and the corresponding service.

In general, JAX-WS clients do not share any state. The same goes for the services. There is no central JVM-wide instance that would be able to track all web service traffic. If you wanted to trace all SOAP traffic, you would need to use a network protocol analyzer like Wireshark or a proxy.

Posted by Fabian Ritzmann on July 01, 2008 at 11:42 AM EEST #

Well, so if I want to monitor (dump) outgoing (at client) as well as incomming (at service) traffic, I basically need to instantiate MessageDumpingFeature within each client and each service to get all traffic between all:

(i) monitored clients and monitored services (duplicited dumps),

(ii) monitored clients and non-monitored services (where I cannot modify the service code) and

(iii) all non-monitored clients (where I cannot modify the client code) and monitored services,

correct? Of course, I would not be able to dump messages between both non-monitored (unmodified) clients and services...

Posted by Jiri Biba on July 01, 2008 at 12:00 PM EEST #

The MessageDumpingFeature only works with clients. There is nothing similar for services. So the only way you could monitor all messages between all clients and all services would be if you could pass your feature object into all clients.

It is not so comfortable to conduct this discussion in the blog. Could you please follow up on the Metro Users mailing list (please make sure you provide the full context in case others want to jump in): https://metro.dev.java.net/servlets/ProjectMailingListList

Posted by Fabian Ritzmann on July 01, 2008 at 12:57 PM EEST #

Post a Comment:
Comments are closed for this entry.
About

ritzmann

Search

Categories
Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today