Printing SOAP messages
By ritzmann on Jun 27, 2008
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.