|
|
WS-Policy and moreFabian's Blog on WS-Policy and more |
|
Friday Jun 27, 2008
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
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: Web Services, Project Metro, Project Tango, WSIT, JAX-WS Posted at 12:00PM Jun 27, 2008 by Fabian Ritzmann in Sun | Comments[7] |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 04:32 PM 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 04:48 PM 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 05:52 PM 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 05:58 PM 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 06:42 PM 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 07: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 07:57 PM EEST #