JAX-WS RI and Compression
JAX-WS RI provides way to send/receive compressed messages on the client side. On the server side, many of the servlet containers like Glassfish, Tomcat provide support for compression. JAX-WS applications can take advantage of this to save bandwidth. First, let us see how we can configure the servlet containers.
See Tomcat documentation on how to configure compression. I configured Tomcat as follows:
<http-listener port="8080" ... >
<property name="compression" value="on"/>
<property name="compressionMinSize" value="20"/>
<property name="compressableMimeType" value="text/xml"/>
Now, let us see how we can configure JAX-WS clients to use compression. The client sends Accept-Encoding HTTP header to indicate its capabilities to process compressed data. If the server sends compressed data (contains Content-Encoding HTTP header), JAX-WS RI client runtime automatically uncompresses the response data. The wire traffic would like like this:
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
<S:Envelope ... </S:Envelope>
---[HTTP response 200]---
Date: Tue, 03 Jul 2007 19:04:19 GMT
null: HTTP/1.1 200 OK
[GZIP Compressed SOAP Envelope]
The way to add Accept-Encoding HTTP header is as follows:
stub = ...
Map<String, List<String>> httpHeaders = new HashMap<String, List<String>>();
Map<String, Object> ctxt = ((BindingProvider)stub).getRequestContext();
JAX-WS RI client can also send requests with compression, but currently Tomcat and GlassFish do not uncompress the requests. Also JAX-WS server runtime doesn't uncompress these requests(does anybody need it ?). So it is useful only when a server can process these requests. Anyway, the way you do this with RI is:
This tip is also captured in JAX-WS RI User Guide.