Sunday, January 7, 2007

HTTP compression has improved a lot the download time of content from
servers. In the context of Web Service it could be very interesting to
also use HTTP compression to improve the network traffic. Firs, I am
explaining how to compress a SOAP response when you have a Web Service
running in Oracle Containers for J2EE (OC4J) using a generic servlet
filter. I have to give credit to http://www.thomas-bayer.com/
since he has created the Filter and documented how to do such thing
using Axis.

So you can take a look to the following article for more details, you
can read the 2 following article, or jump to the next paragraph that
explains how to configure your JAX-RPC based service to send compressed
HTTP response.

In this sample I am showing how to compress the SOAP response
using a servlet filter, it is also possible to use some other Oracle
infrastructure element to achieve that such as Oracle HTTP
Server/Apache, or Oracle Webcache.

1- Install
the compression filter library in your application

Download the compression filter library 2wayfilter-1.2.jar
and copy it into the Web application's WEB-INF/lib folder

2-
Configure your application to use the filter

The configuration of a servlet filter is
done using
the web.xml where you reference which servlet or URL will be using the
filter. As you may knowin JAX-RPC, the HTTP endpoint of a service are
exposed as servlet and defined in the web.xml. You can choose to
compress all the endpoint/URL or create a new servlet mapping, that
will become a new SOAP endpoint and only compress this one. If you take
the option of creating a new endpoint keep in mind that it will not be
added to the WSDL automatically, so the client application will have to
point explicitly to the compressed endpoint URL to take benefits of it.

In this basic configuration you have only changed the servlet that is
the HTTP endpoint of your service. So the compressed endpoint is not
present in the WSDL, but you can use any of the URL to create your
proxy.

When you have created your proxy, if you want to access the endpoint
that will return the compressed response you must be sure that you are
calling the correct endpoint. You can set the endpoint using the setEndpoint method, of your Web
Service client.

This is it!
I will in a next post explain how you can using the Oracle Web Service
client API send a compressed request that will have to be uncompressed
on the server using the same filter.

Had a go at doing this with JAX-WS but no luck so far - can compress servlets in same web app ok but when I try and reference my web service (exposed as EJB 3.0 stateless session bean). They're bound to the default web application so I modified the web.xml for that default webapp. Any thoughts - seems an easy alternative to webcache