Golden Axis: save connections with HTTP/1.1

By default axis use HTTP/1.0 for calling webservices.

The following code

for i in 1..10:

creates 10 connection to the server:

# netstat -tuap |egrep -ic 'http.*clienthost.*ESTAB'

We can configure axis to use just one connection setting:

  • HTTP/1.1
  • transfer encoding:  chunked

this involves

  1. configuring axis client.wsdd to use Commons-Httpclient-3.0 for transport
  2. enabling pre-emptive authentication

Use CommonsHTTPClient

# find $TOMCAT/ -name axis\*.jar
# unzip axis-1.4.jar org/apache/axis/client/client-config.wsdd
# vi org/apache/axis/client/client-config.wsdd

change HTTPSender with the apache commons one and repack file:

- <transport name="http" pivot="java:org.apache.axis.transport.http.HTTPSender"/>
+ <transport name="http" pivot="java:org.apache.axis.transport.http.CommonsHTTPSender"/>
# zip -f zip axis-1.4.jar org/apache/axis/client/client-config.wsdd

Now with wireshark/ethereal/netstat you’ll see that while running you got:

# netstat -tuap |egrep -ic 'http.*clienthost.*ESTAB'

Setting PreEmptive authentication

Sniffing, you’ll notice one issue: client won’t automatically send authentication data. Instead it

  1. client send an unauth soap request
  2. server returns 401 (Authentication Required)
  3. client send the authenticated request
  4. server says ok

To force CommonsHTTPClient to send authentication data, we need to set the following property:

        System.setProperty("httpclient.authentication.preemptive", "true");

And the magic is done: jjust one connection for all the call…and your WebService Producer say thankyou!