Top Navigation
Show Content

How to Compress Your SOAP Requests Using GZIP

Applies To

1. Axis2/Java 1.3 or later

2. JDK 1.4 or later

 

Why Compress Requests?

Compressing SOAP requests might be a good idea if your SOAP message is large and/or when you want to reduce network bandwidth usage. Implementations of the HTTP protocol enable the use of GZip as a standard way of compressing requests sent over it.

Enabling Compression

Axis2 uses the HTTP implementation from Apache Commons HttpClient project. It is very easy to compress your requests using the Axis2 client API.

You just have to set the following property,

org.apache.axis2.transport.http.HTTPConstants.MC_GZIP_REQUEST

to:

Boolean.TRUE

using the Options object used by your client object. 

The following shows how you can do this in your client code.

//get the Options object used by your client
Option options = client.getOptions();
//set the property
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.MC_GZIP_REQUEST, Boolean.TRUE);

Once you set this property, Axis2 not only makes sure your request is compressed using GZip, but also adds the proper content encoding headers so that the receiving end can decode the message correctly.

i.e.

Content-Encoding: gzip

Axis2 HTTP transport listeners can handle GZip requests, without any additional configuration, if the proper HTTP headers are present.

 

Author : Eran Chinthaka, Member-Apache Software Foundation. eran(dot)chinthakaXgmail.com, where X=@