com.elasticpath.commons.filter.impl
Class CompressionFilter

java.lang.Object
  extended by com.elasticpath.commons.filter.impl.CompressionFilter
All Implemented Interfaces:
javax.servlet.Filter

public class CompressionFilter
extends java.lang.Object
implements javax.servlet.Filter

Implementation of javax.servlet.Filter used to compress the ServletResponse.


Constructor Summary
CompressionFilter()
           
 
Method Summary
 void destroy()
          Called by the web container to indicate to a filter that it is being taken out of service.
 void doFilter(javax.servlet.ServletRequest inRequest, javax.servlet.ServletResponse inResponse, javax.servlet.FilterChain inFilterChain)
          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)
          Called by the web container to indicate to a filter that it is being placed into service.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompressionFilter

public CompressionFilter()
Method Detail

destroy

public void destroy()
Called by the web container to indicate to a filter that it is being taken out of service. This method is only called once all threads within the filter's doFilter method have exited or after a timeout period has passed. After the web container calls this method, it will not call the doFilter method again on this instance of the filter.

Specified by:
destroy in interface javax.servlet.Filter

doFilter

public void doFilter(javax.servlet.ServletRequest inRequest,
                     javax.servlet.ServletResponse inResponse,
                     javax.servlet.FilterChain inFilterChain)
              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()).

Specified by:
doFilter in interface javax.servlet.Filter
Parameters:
inRequest - -the request
inResponse - -the response
inFilterChain - - the filter chain
Throws:
javax.servlet.ServletException - - if something goes wrong
java.io.IOException - - if something goes wrong

init

public void init(javax.servlet.FilterConfig filterConfig)
Called by the web container to indicate to a filter that it is being placed into service. The servlet container calls the init method exactly once after instantiating the filter. The init method must complete successfully before the filter is asked to do any filtering work.

Specified by:
init in interface javax.servlet.Filter
Parameters:
filterConfig - - the filerConfig.