S33 the cloud

After all that hype about cloud and Amazon services, I decided to set up a simple S3 server on my laptop. On google code I found little-s3, a funny webapp which implements the s3 protocol and I check it out.

The guide is straightforward and the protocol implemented is mainly a GET/PUT server: a free place for testing your “cloud” infrastructure.

Here are some example methods:

1- create the object foo.html.

curl –data “@foo.html” –request PUT –header “Content-Type: text/html” “http://localhost:8080/littleS3-2.1.0/firstBucket/foo.html”

2- Retrieve an object

curl “http://localhost:8080/littleS3-2.1.0/firstBucket/foo.html”

3- Delete an object
curl –request DELETE “http://localhost:8080/littleS3-2.1.0/firstBucket/foo.html”

4- Delete a bucket
curl –request DELETE “http://localhost:8080/littleS3-2.1.0/firstBucket”

Sneaking thru webservices like a python

After the brief presentation of php webservices, here’s how to play with SOAP and Python:

>>> from SOAPpy import SOAPProxy
>>> url = 'http://rpolli@babel.it:password@horde.example.com:80/rpc.php'
>>> n = 'urn:horde'
>>> server = SOAPProxy(url, namespace=n)     1
>>> server.config.dumpSOAPOut = 1            2
>>> server.config.dumpSOAPIn = 1
>>> calendars = server.calendar.list()    3

Steps are easy:

  1. set the namespace of the xml request: this is compulsory
  2. set I/O to verbose
  3. execute the call

You can list wsdl method with a similar way:

>>> from SOAPpy import WSDL          
>>> wsdlFile = 'http://www.xmethods.net/sd/2001/TemperatureService.wsdl')
>>> server = WSDL.Proxy(wsdlFile)    
>>> server.methods.keys() 

Examples are taken from: 
http://www.diveintopython.org/soap_web_services/index.html

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:
   axis.method("doit")

creates 10 connection to the server:

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

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'
1

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!