Simon Fell > Its just code > compression with Axis 1.3

Tuesday, October 11, 2005

Apache Axis 1.3 just shipped (congrats Glen, Dims & folks), and it now supports HTTP request / response gzip compression, for services that run over the internet this can be a big win. By default its turned off, the easiest way I know how to turn it on is to sub class your service locator class and override the createCall method. here's an example, lets suppose you've run WSDL2Java on the sforce enterprise WSDL, you'll be left with a SforceServiceLocator class, this is the class you'll subclass, e.g.

import javax.xml.rpc.Call;
import javax.xml.rpc.ServiceException;

import org.apache.axis.transport.http.HTTPConstants;

import com.sforce.soap.enterprise.SforceServiceLocator;

public class SforceService extends SforceServiceLocator {

	public Call createCall() throws ServiceException {
		Call call = super.createCall();
		call.setProperty(HTTPConstants.MC_ACCEPT_GZIP, Boolean.TRUE);
		call.setProperty(HTTPConstants.MC_GZIP_REQUEST, Boolean.TRUE);
		return call;
	}
}

Then your client code creates an instance of this subclass rather then SforceServiceLocator directly to get an instance of the Soap proxy.

Soap svc = new SforceService().getSoap();
LoginResult lr = svc.login("user@corp.org", "thePassword");

Your request to the server is gzipped compressed (the MC_GZIP_REQUEST property), and the request advertises (via the Accept-Encoding http header) that it'll accept a gzipped response (the MC_ACCEPPT_GZIP property). In the case of an sforce call like Query which can return very large responses you can see some big decreases in message sizes, a quick test here shows that an uncompressed response of 376426 bytes compresses down to a measly 33617 bytes (approx 9% the original size)

In addition to the above, you have to configure axis to use the vastly superior CommonsHTTPSender class rather than the default HTTPSender class as its transport, this is done by changing the transport entry in the client-config.wsdd file from java:org.apache.axis.transport.http.HTTPSender to java:org.apache.axis.transport.http.CommonsHTTPSender and adding Commons HTTP to the class path.