The TcpTunnelGui Tool

It is often quite useful to view the actual SOAP conversation between client and server. This can aid in understanding the intricacies of the SOAP protocol and in debugging live applications. To help you along, the Apache SOAP distribution includes a handy TcpTunnelGui tool. The tool requires three command-line parameters:

listenport

The TcpTunnelGui tool will intercept and display all messages going to the listenport.

tunnelhost

The tunnel hostname. For local installations, set this to localhost.

tunnelport

The TcpTunnelGui tool will intercept all messages and forward them to the tunnelport. For Jakarta Tomcat, set this to 8080.

For example, the following command line will intercept all messages going to port 8070 and forward them to the localhost, port 8080:

java org.apache.soap.util.net.TcpTunnelGui 8070 localhost 8080

To view your actual SOAP conversation, you must modify the client code to use port 8070. For example:

URL url = new URL ("http://localhost:8070/soap/servlet/rpcrouter");
Response resp = call.invoke (url, "");

A sample screenshot of the “Hello, SOAP!” conversation is provided in Figure 4-7. Messages from the client are displayed in the left column; messages from the server are displayed in the right column.

The TcpTunnelGui tool in action
Figure 4-7. The TcpTunnelGui tool in action

Here is the full text of a sample request message:

POST /soap/servlet/rpcrouter HTTP/1.0
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: 464
SOAPAction: ""

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
   xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
   xmlns:xsd="http://www.w3.org/1999/XMLSchema">
   <SOAP-ENV:Body>
      <ns1:sayHello
         xmlns:ns1="urn:examples:helloservice"
         SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <firstName xsi:type="xsd:string">Amy</firstName>
      </ns1:sayHello>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Here is the full text of a sample response message:

HTTP/1.0 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 484
Set-Cookie2: JSESSIONID=810j57jod1;Version=1;Discard;Path="/soap"
Set-Cookie: JSESSIONID=810j57jod1;Path=/soap
Servlet-Engine: Tomcat Web Server/3.2.1 
(JSP 1.1; Servlet 2.2; Java 1.3.0; Windows 2000 5.0 x86; 
java.vendor=Sun Microsystems Inc.)

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
   xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
   xmlns:xsd="http://www.w3.org/1999/XMLSchema">
   <SOAP-ENV:Body>
      <ns1:sayHelloResponse
         xmlns:ns1="urn:examples:helloservice"
         SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <return xsi:type="xsd:string">Hello, Amy!</return>
      </ns1:sayHelloResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Get Web Services Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.