O'Reilly logo

Java Web Services: Up and Running by Martin Kalin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Wire-Level Tracking of HTTP and SOAP Messages

Example 1-7 and Example 1-8 show an HTTP request message and an HTTP response message, respectively. Each HTTP message encapsulates a SOAP envelope. These message traces were done with the Perl client by changing the Perl use directive in Example 1-5:

use SOAP::Lite;


use SOAP::Lite +trace;

The Ruby client in Example 1-6 contains a line:

service.wiredump_file_base = 'soapmsgs'

that causes the SOAP envelopes to be saved in files on the local disk. It is possible to capture the wire-level traffic directly in Java as well, as later examples illustrate. Various options are available for tracking SOAP and HTTP messages at the wire level. Here is a short introduction to some of them.

The tcpmon utility (available at https://tcpmon.dev.java.net) is free and downloads as an executable JAR file. Its graphical user interface (GUI) is easy to use. The utility requires only three settings: the server’s name, which defaults to localhost; the server’s port, which would be set to 9876 for the TimeServer example because this is the port at which Endpoint publishes the service; and the local port, which defaults to 8080 and is the port at which tcpmon listens. With tcpmon in use, the TimeClient would send its requests to port 8080 instead of port 9876. The tcpmon utility intercepts HTTP traffic between the client and web service, displaying the full messages in its GUI.

The Metro release has utility classes for tracking HTTP and SOAP traffic. This approach does not require any change to the client or to the service code; however, an additional package must be put on the classpath and a system property must be set either at the command line or in code. The required package is in the file jaxws_ri/jaxws-rt.jar. Assuming that the environment variable METRO_HOME points to the jaxws-ri directory, here is the command that tracks HTTP and SOAP traffic between the TimeClient, which connects to the service on port 9876, and the TimeServer service. (Under Windows, $METRO_HOME becomes %METRO_HOME%.) The command is on three lines for readability:

% java -cp ".":$METRO_HOME/lib/jaxws-rt.jar \
  -Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true \

The resulting dump shows all of the SOAP traffic but not all of the HTTP headers. Message tracking also can be done on the service side.

There are various other open source and commercial products available for tracking the SOAP traffic. Among the products that are worth a look at are SOAPscope, NetSniffer, and Wireshark. The tcpdump utility comes with most Unix-type systems, including Linux and OS X, and is available on Windows as WinDump. Besides being free, tcpdump is nonintrusive in that it requires no change to either a web service or a client. The tcpdump utility dumps message traffic to the standard output. The companion utility tcptrace (http://www.tcptrace.org) can be used to analyze the dump. The remainder of this section briefly covers tcpdump as a flexible and powerful trace utility.

Under Unix-type systems, the tcpdump utility typically must be executed as superuser. There are various flagged arguments that determine how the utility works. Here is a sample invocation:

% tcpdump -i lo -A -s 1024 -l 'dst host localhost and port 9876' | tee dump.log

The utility can capture packets on any network interface. A list of such interfaces is available with the tcpdump -D (under Windows, WinDump -D), which is equivalent to the ifconfig -a command on Unix-like systems. In this example, the flag/value pair -i lo means capture packets from the interface lo, where lo is short for the localhost network interface on many Unix-like systems. The flag -A means that the captured packets should be presented in ASCII, which is useful for web packets as these typically contain text. The -s 1024 flag sets the snap length, the number of bytes that should be captured from each packet. The flag -l forces the standard output to be line buffered and easier to read; and, on the same theme, the construct | tee dump.log at the end pipes the same output that shows up on the screen (the standard output) into a local file named dump.log. Finally, the expression:

'dst host localhost and port 9876'

acts as a filter, capturing only packets whose destination is localhost on port 9876, the port on which TimeServerPublisher of Example 1-3 publishes the TimeServer service.

The tcpdump utility and the TimeServerPublisher application can be started in any order. Once both are running, the TimeClient or one of the other clients can be executed. With the sample use of tcpdump shown above, the underlying network packets are saved in the file dump.log. The file does require some editing to make it easily readable. In any case, the dump.log file captures the same SOAP envelopes shown in Examples 1-7 and 1-8.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required