How to Compress Your SOAP Requests Using GZIP

This document explains how to compress SOAP requests to other Web services endpoints, using the Axis2 client API.

Date: Tue, 1st Jan, 2008
Level: Introductory
Reads: 5337 Comments: 0 | Login or register to post comments
Eran Chinthaka
Software Engineer
WSO2 Inc.
chinthaka's picture

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=@

 

Hot Topic
Hot
Topic

Google Gadgets are a nice way to develop user interfaces for distributed services. The fact that they can be hosted anywhere over a network, not necessarily in the very portal server they eventually run in makes them re-usable and allows users to quickly...

Mini Banners
WSO2Con 2010
Latest Webinar
In this webinar we'll share the range of concerns we've heard from the industry, and survey some of the new and sometimes subtle types of lock-in associated with cloud technologies.
Wednesday, 8 September, 10.00 AM (PDT)