Skip Links

Blog

Posts tagged with "SOAP".

Debugging SOAP calls

Sid

Sid

09 May 2011 15:39

I’m currently working on a client project where we’re making web service calls via JAX-RPC. Web Services are hugely important and useful but I can’t be the only person to think they’re a royal pain to develop and deploy!

If you’re using Apache Axis then there are some inbuilt tools that can help work out what’s going wrong when things go wrong. The most useful is tcpmon which acts as an “app-in-the-middle” and displays your SOAP request and response.

Here’s a quick how-to in setting up tcpmon in order to intercept your development web services calls and responses. Once you start using it the rest is pretty obvious but I’ve also included some screenshots of the input and output just so you can see.

The instructions assume Windows but replace the command prompts and environment variables with the usual in *nix and it all should work the same.

  1. Open a command prompt and set the Java classpath to pick up the Axis classes (tcpmon is bundled with them)
  2. set CLASSPATH=CLASSPATH;[my axis classpath]/wsif.jar;[my axis classpath]/axis-1.4.jar;[my axis classpath]/axis-ant-1.4.jar;[my axis classpath]/commons-logging-1.0.4.jar;[my axis classpath]/commons-discovery-0.2.jar;[my axis classpath]/wsdl4j-1.5.1.jar
  3. Start tcpmon java org.apache.axis.utils.tcpmon
  4. Enter the port where you want to run tcpmon (in the example below I use 1976 but check with netstat to find a free port)
  5. Make the webservice call from your test client (the code snippet below is from a JUnit test method)
	// Note that the port is the tcpmon port and it will be forwarded to the web service port
	String endpoint = "http://localhost:1976/axis/services/PortingPort";

	Service service = new Service();
	Call call = (Call) service.createCall();

	// Prepare the call for the Web service
	call.setTargetEndpointAddress(new java.net.URL(endpoint));
	call.setOperationName("myService");
	MyParameterRequestType por = new MyParameterRequestType();
	por.setGreeting("Hello");
	call.addParameter("requestParam",new QName("http://mywsdl.endpoint.for.service/Service"),ParameterMode.IN);
	call.setReturnType(new QName("myParameterResponse"));
	call.invoke(new Object[] {por});

Below is the tcpmon “console” where you set the port that tcpmon listen on.

… and this is the request and response intercepted by tcpmon after making the test call

Tagged in: web services, SOAP, java, debugging