Presents your XML AND WEB SERVICES E-NEWSLETTER for November 17, 2003 <-------------------------------------------> USE APACHE'S TCP TUNNEL/MONITOR TO DEBUG SOAP One of the most common tasks during application development is debugging. With new tools and new technologies, debugging is essential to understanding what's happening and why your application is behaving like expected. To this end, the Apache Group distributes a nice application that you can use to monitor and debug your SOAP interfaces. (Note that this application only applies to SOAP implementations that use HTTP as the transport.) TCP TUNNEL/MONITOR The TCP Tunnel/Monitor application is a simple proxy application that includes a visual interface. When you run the application, you specify a host port and a target address and port. TCP Tunnel/Monitor will display a window with two text areas: * The text area on the left shows the incoming request, received by the application on the host port you specify. * The text area on the right shows the response received from the target server. You can use the application to monitor servers locally and remotely. If your Web server is local, then you'll specify a host port other than the one your Web server is currently using. For example, if you're running Tomcat on port 8080, then you can start the application with the following command: java org.apache.soap.util.net.TcpTunnelGui 8081 localhost 8080 This command runs the TcpTunnelGui class and passes in three parameters: * The first parameter specifies the port that the tool will listen on. Your SOAP client will have to be redirected to this port rather than the normal port in order to see things happen. * The second parameter is the target address (the local machine in this case). * The final parameter is the target port (in this case, where Tomcat is listening). You can point the monitor at remote servers too. Simply change the target address and port to match the host you want to monitor. For example, to monitor the messages to and from the Google Web service, you can use the following command: java org.apache.soap.util.net.TcpTunnelGui 88 api.google.com 80 In this case, your client's SOAP location is now http://localhost:88/search/beta2 instead of http://api.google.com/search/beta2. SOAP When you run your SOAP client, it sends a request to the SOAP location you've specified. In order to use this tool, the SOAP location will be different from normal. Each request is proxied by the monitor program, so you have to change the SOAP location of the service you're calling to be at host localhost and at the port you specified as the host port when starting up the tunnel. For example, if you have an existing Web service client, it may contain something like this: String soaplocation = " http://mywebservice.mydomain.com/soap/servlet/rpcrouter"; URL soapurl = new URL(soaplocation); You can easily modify this to point to the proxy: String soaplocation = " http://localhost:88/soap/servlet/rpcrouter"; URL soapurl = new URL(soaplocation); In a real application, the URL probably isn't hard-coded in the source but in a properties file (or some other externally editable file). In this case, it may make sense to have two parameters in your properties file--one that points directly to the service and another that points at the proxy address. Then you could add another property that indicates if the service is in "debug" mode and use it to dynamically change where the service client points to, like this: . . . String debugmode = myConfiguration.getProperty("debugMode"); String soaplocation; if (debugmode.equalsIgnoreCase("YES")) { soaplocation = myConfiguration.getProperty("soapLocation"); } else { soaplocation = myConfiguration.getProperty("soapLocationDebug"); } . . . HTTP AND OTHER SERVERS This tool is useful beyond just SOAP messages. It can be used to monitor any HTTP service as well, and it's not dependent on Apache Web servers. Because the tool is a generic proxy, you can use it to monitor HTTP and SOAP messages to Microsoft IIS servers, Apache Web servers, Tomcat, WebLogic, or any HTTP server. Brian Schaffner is an associate director for Fujitsu Consulting. He provides architecture, design, and development support for Fujitsu's Technology Consulting practice. ----------------------------------------