com.jfw.web.filter
Class CompressionFilter

java.lang.Object
  extended by com.jfw.web.filter.JFWFilter
      extended by com.jfw.web.filter.CompressionFilter
All Implemented Interfaces:
javax.servlet.Filter

public class CompressionFilter
extends JFWFilter

Implementation of javax.servlet.Filter used to compress the ServletResponse if it is bigger than a threshold.

JFW javadoc
Add this lines to web.xml for activate the filter.

  <filter>
    <filter-name>CompressionFilter</filter-name>
    <filter-class>com.jfw.web.filter.CompressionFilter</filter-class>
    <init-param>
      <param-name>compressionThreshold</param-name>
      <param-value>128</param-value>
    </init-param>
  </filter>
  
  <filter-mapping>
    <filter-name>CompressionFilter</filter-name>
    <url-pattern>*.do</url-pattern>
  </filter-mapping>
  
  <filter-mapping>
    <filter-name>CompressionFilter</filter-name>
    <url-pattern>*.jsp</url-pattern>
  </filter-mapping>
 


Field Summary
protected  int compressionThreshold
          The threshold number to compress
 
Fields inherited from class com.jfw.web.filter.JFWFilter
className, config
 
Constructor Summary
CompressionFilter()
           
 
Method Summary
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain.
 void init(javax.servlet.FilterConfig filterConfig)
           
 
Methods inherited from class com.jfw.web.filter.JFWFilter
destroy, getFilterConfig, setFilterConfig
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

compressionThreshold

protected int compressionThreshold
The threshold number to compress

Constructor Detail

CompressionFilter

public CompressionFilter()
Method Detail

init

public void init(javax.servlet.FilterConfig filterConfig)

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws java.io.IOException,
                     javax.servlet.ServletException
The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. The FilterChain passed into this method allows the Filter to pass on the request and response to the next entity in the chain.

This method first examines the request to check whether the client support compression.
It simply just pass the request and response if there is no support for compression.
If the compression support is available, it creates a CompressionServletResponseWrapper object which compresses the content and modifies the header if the content length is big enough. It then invokes the next entity in the chain using the FilterChain object (chain.doFilter()),

Throws:
java.io.IOException
javax.servlet.ServletException