|Revision 1.0||10.04.2013||Admin||TCPMon Tutorial|
|Revision 1.1||10.05.2013||Admin||Add Tips, bug fixes and enhancements|
When developing web services applications it’s often on demand to be able to track the SOAP messages passed along in TCP based conversation, the TCPMon is coming as the first option to capture the outgoing and incoming SOAP envelopes.
TCPMon is a open source utility debug tool, distributed under the Apache 2.0 license. It has originally being part of Axis1 and now stands as an independent project. The official web site is http://ws.apache.org/tcpmon/. It is based on a swing UI and works on almost all platforms that Java supports. It allows user record, monitor and resent the messages, This TCPMon tutorial is step-by-step guide to explain how TCPMon works and also to explain its features.
TCPMon was written by standard Java language, it has absolutely no dependencies on third party libraries. to run TCPMon, only the JDK or JRE is required.
Visit http://ws.apache.org/commons/tcpmon/download.cgi to download the 1.0 Source or binary distribution. Unzip the tcpmon-1.0-bin.zip(this latest 1.0 version was released on 27 – 03 – 2006), then navigate to the folder where you unzipped the download, there have two ways to start TCPMon:
java -cp ./tcpmon-1.0.jar org.apache.ws.commons.tcpmon.TCPMon
Once it is launched, you should see the below TCPMon UI interface.
The TCPMon usage pattern is as an intermediary. It is called explicit since the client has to point to the intermediary rather than the original endpoint in order to monitor the messages. TCPMon enables kinds of listing/proxy bridge between server and client, while client sends the soap message, it is made to connect to tcpmon, and tcpmon forwards the data/SOAP message to the real server along-with displaying it in its GUI. The following figure explains this concept.
Click on Admin tab to configure the TCPMon. Thinking that we want retrieve the all cities in a country from http://www.webservicex.net. The webservice is already up on this address and is available on the port 80.
Steps (Please see the following screen shot)
We have instructed tcpmon to listen on port 8080 and forward any requests received to www.webservicex.net. In our web service request we have to set our URL as localhost:8080. This will cause any requests to go through the tcpmon proxy, which will capture the SOAP request and then send on the request to the target hostname value. The response from the web service will also be captured by tcpmon and then forwarded on to our application.
The following XML is the SOAP request we retrieve all cities in india.
POST /globalweather.asmx HTTP/1.1 SOAPAction: "http://www.webserviceX.NET/GetCitiesByCountry" Content-Type: text/xml User-Agent: Axis/2.0 Host: www.webservicex.net:8080 Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Connection: keep-alive Content-Length: 379<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetCitiesByCountry xmlns="http://www.webserviceX.NET"> <CountryName>India</CountryName> </GetCitiesByCountry> </soap:Body> </soap:Envelope>
The following XML are the SOAP response from this web service server.
HTTP/1.1 200 OK Cache-Control: private, max-age=0 Content-Length: 8038 Content-Type: text/xml; charset=utf-8 Server: Microsoft-IIS/7.0 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Fri, 04 Oct 2013 15:05:41 GMT<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET"> <GetCitiesByCountryResult><NewDataSet> <Table> <Country>British Indian Ocean Territory</Country> </NewDataSet>...</GetCitiesByCountryResult> </GetCitiesByCountryResponse> </soap:Body> </soap:Envelope>