Codehaus XFire
DocumentationQuicklinksDevelopers
Sponsors |
OverviewOptional GZIP content encoding can be enabled for responses, requests, or both. DetailEnabling GZIP response compression sets the 'Accept-Encoding' header of requests to 'gzip' and if the server supports this and GZIPs the response and sets the 'Content-Encoding' header on it to 'gzip' the client will decode it. If the server does not support this non compressed responses are also handled. Enabling GZIP request compression sets the 'Content-Encoding' header of requests to 'gzip' and compresses the content. The server must support this in order for this to work because request encoding cannot be negotiated as response encoding is. ExamplesClient Use// obtain client as normal Service serviceModel = new ObjectServiceFactory().create(IDataServerService.class); XFire xfire = XFireFactory.newInstance().getXFire(); XFireProxyFactory factory = new XFireProxyFactory(xfire); try{ this.client = (IDataServerService)factory.create(serviceModel, url); }catch(MalformedURLException e){ log.error(e); } Client client = ((XFireProxy)Proxy.getInvocationHandler(this.client)).getClient(); // optionally enable compression // enable response compression client.setProperty(CommonsHttpMessageSender.GZIP_RESPONSE_ENABLED, true); // enable request compression client.setProperty(CommonsHttpMessageSender.GZIP_RESPONSE_ENABLED, true); // or just enable both client.setProperty(CommonsHttpMessageSender.GZIP_ENABLED, true); // use client as normal Server SetupThere are a number of ways to enable content encoding on the server side. Servlet FilterThe servlet filter used by xfire for testing is http://sourceforge.net/projects/pjl-comp-filter, on ibiblio it is http://www.ibiblio.org/maven2/net/sourceforge/pjl-comp-filter/pjl-comp-filter/ ; It supports request and response compression. To set it up place jar in your servlet container and add the following to your web.xml <filter> <filter-name>CompressingFilter</filter-name> <filter-class>com.planetj.servlet.filter.compression.CompressingFilter</filter-class> <init-param> <param-name>debug</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>statsEnabled</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>CompressingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> With this filter you can easily make a statistics jsp: <%@ page import="com.planetj.servlet.filter.compression.*" %> <html> <head> <title>WAR Status</title> </head> <body> <% CompressingFilterStats stats = (CompressingFilterStats)ctx.getAttribute(CompressingFilterStats.STATS_KEY); %> <h4>GZIP Servlet Statistics (com.planetj.servlet.filter.compression.CompressingFilter)</h4> <table border="1"> <tr><td>resp num compressed</td><td><%= stats.getNumResponsesCompressed() %></td></tr> <tr><td>resp num not compressed</td><td><%= stats.getTotalResponsesNotCompressed() %></td></tr> <tr><td>resp input bytes</td><td><%= stats.getResponseInputBytes() %></td></tr> <tr><td>resp compressed out bytes</td><td><%= stats.getResponseCompressedBytes() %></td></tr> <tr><td>resp mean compression ratio</td><td><%= stats.getResponseAverageCompressionRatio() %></td></tr> <tr><td>req num compressed</td><td><%= stats.getNumRequestsCompressed() %></td></tr> <tr><td>req num not compressed</td><td><%= stats.getTotalRequestsNotCompressed() %></td></tr> <tr><td>req input bytes</td><td><%= stats.getRequestInputBytes() %></td></tr> <tr><td>req compressed out bytes</td><td><%= stats.getRequestCompressedBytes() %></td></tr> <tr><td>req mean compression ratio</td><td><%= stats.getRequestAverageCompressionRatio() %></td></tr> </table> </body> </html> mod_deflateOne of many other ways is to use http://httpd.apache.org/docs/2.0/mod/mod_deflate.html. |