jodd.servlet.filters
Class GzipFilter

java.lang.Object
  extended byjodd.servlet.filters.GzipFilter
All Implemented Interfaces:
javax.servlet.Filter

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

Compresses output with gzip, for browsers that supports it.

Configuration of this filter is based on the following initialization parameters:

This filter has been build and extend from Tomcats example.

Technical notes: i have found that this is the only way how gzip filter can be build. The first idea that comes to mind is to wrap response to some character-based wrapper, and then to gzip it to the output. This works fine except when forwarding is used: forwarded page is gzipped, but response header is no more there! I have not an idea how to fix this except from this approach presented in Tomcat.


Field Summary
protected  int threshold
          The threshold number to compress, (0 == no compression).
protected  java.lang.String uriExclude
          Comma separated string patterns to be excluded in the request URI if founded by match.
protected  java.lang.String uriMatch
          Comma separated string patterns to be found in the request URI
 
Constructor Summary
GzipFilter()
           
 
Method Summary
 void destroy()
           
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          If browser supports gzip, set the Content-Encoding response header and invoke resource with a wrapped response that collects all the output.
protected  javax.servlet.FilterConfig getFilterConfig()
           
 void init(javax.servlet.FilterConfig config)
          Filter initialization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

uriMatch

protected java.lang.String uriMatch
Comma separated string patterns to be found in the request URI


uriExclude

protected java.lang.String uriExclude
Comma separated string patterns to be excluded in the request URI if founded by match.


threshold

protected int threshold
The threshold number to compress, (0 == no compression).

Constructor Detail

GzipFilter

public GzipFilter()
Method Detail

getFilterConfig

protected javax.servlet.FilterConfig getFilterConfig()

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws javax.servlet.ServletException,
                     java.io.IOException
If browser supports gzip, set the Content-Encoding response header and invoke resource with a wrapped response that collects all the output. Extract the output and write it into a gzipped byte array. Finally, write that array to the client's output stream. If browser does not support gzip, invoke resource normally.

Specified by:
doFilter in interface javax.servlet.Filter
Parameters:
request -
response -
chain -
Throws:
javax.servlet.ServletException
java.io.IOException

init

public void init(javax.servlet.FilterConfig config)
          throws javax.servlet.ServletException
Filter initialization.

Specified by:
init in interface javax.servlet.Filter
Parameters:
config -
Throws:
javax.servlet.ServletException

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Filter


Jodd v0.24.5 Javadoc