How to Configure Axis 1.4 WS Client (Java) to accept GZIP compressed SOAP messages.

In this blog I will explain how to write an Axis 1.4 Client that can accept GZIP compressed SOAP messages. The GZIP compression feature of Axis 1.x is not well documented on the Apache website, so you have to search for it in blogs like this one. You can also use Axis 1.x to write server side code to compress SOAP messages, but I will not cover that in this blog.

Steps to write Axis 1.4 Client code:

  1. Create the Axis Client code: Run wsdl2java on your wsdl to generate the client side stubs. Write code to connect to the correct web service endpoint. You can find examples on the Axis website and numerous blogs.
  2. Use a TCP/IP monitoring software so that you can see the request and response messages. If you’re using Eclipse, there’s already a built-in “TCP/IP Monitor”. The monitor will tunnel a TCP connection from a local port to the web service endpoint. Set the Monitor Type to TCP/IP and not HTTP.
  3. Test that you can get to the web service using the TCP/IP monitor. (Compression in not enabled at this point)
  4. Add an HTTP Header to the request to inform the server that the client accepts GZIP compression. (HTTP Header is not to be confused with the SOAP Header).
  5. URL url = new URL(”www.acme.corp/webservice/MyService”);
    AcmeServiceLocator service = new AcmeServiceLocator();
    AcmeServicePortType port = service.getacmeServiceHttpPort(url);
    ((Stub) port)._setProperty(HTTPConstants.MC_ACCEPT_GZIP,Boolean.TRUE);
    QueryResult result = port.queryMyStore(param);
  6. Change the Axis Client configuration file to use “CommonsHTTPSender” instead of the default “HTTPSender” as the http transport. This transport knows how to deal with GZIP compression, the default one does not. The Axis configuration file can be found in the Axis.jar (client-config.wsdd). This file needs to be modified to use “CommonsHTTPSender”, see below. (I tested this configuration with Axis 1.4; older versions might have a slightly different configuration) The updated client-config.wsdd file needs to be put on the Classpath.
  7. <?xml version=”1.0″ encoding=”UTF-8″?>
    <deployment name=”defaultClientConfig”
    xmlns=”http://xml.apache.org/axis/wsdd/”
    xmlns:java=”http://xml.apache.org/axis/wsdd/providers/java”>
    <globalConfiguration>
    <parameter name=”disablePrettyXML” value=”true”/>
    <parameter name=”enableNamespacePrefixOptimization” value=”false”/>
    </globalConfiguration>
    <transport name=”http” pivot=”java:org.apache.axis.transport.http.CommonsHTTPSender”/>
    <transport name=”http” pivot=”java:org.apache.axis.transport.http.HTTPSender”/>
    <transport name=”local” pivot=”java:org.apache.axis.transport.local.LocalSender”/>
    <transport name=”java” pivot=”java:org.apache.axis.transport.java.JavaSender”/>
    </deployment>
  8. Now run your code! In the TCP/IP monitor you should see the HTTP Header “Accept-Encoding: gzip” in the request. In the response you should see the HTTP Header “Content-encoding: gzip” and some binary data on the bottom. This is the server telling the client that it is sending back GZIP-ed data.
  9. *** Request Message ***
    POST /webservice/MyService HTTP/1.1
    Content-Type: text/xml; charset=utf-8
    SOAPAction: “”
    User-Agent: Axis/1.4
    Accept-Encoding: gzip
    Host: localhost:9001
    Transfer-Encoding: chunked
    28a
    <?xml version=”1.0″ encoding=”UTF-8″?><soapenv:Envelope …

    *** Response Message ***
    Server: Sun-ONE-Web-Server/6.1
    Date: Thu, 27 Aug 2009 15:42:25 GMT
    Content-type: text/xml;charset=UTF-8
    X-powered-by: Servlet 2.4; JBoss-4.0.5.GA Tomcat-5.5
    Content-encoding: gzip
    Vary: Accept-Encoding
    Transfer-encoding: chunked
    479

  • Share/Bookmark

Leave a Reply

You must be logged in to post a comment.