org.kohsuke.stapler.compression
Class CompressionFilter

java.lang.Object
  extended by org.kohsuke.stapler.compression.CompressionFilter
All Implemented Interfaces:
javax.servlet.Filter

public class CompressionFilter
extends Object
implements javax.servlet.Filter

Pimps up HttpServletResponse so that it understands "Content-Encoding: gzip" and compress the response.

When exceptions are processed within web applications, different unrelated parts of the webapp can end up calling ServletResponse.getOutputStream(). This fundamentally doesn't work with the notion that the application needs to process "Content-Encoding:gzip" on its own. Such app has to maintain GZIPOutputStream on its own, since HttpServletResponse doesn't know that its output is written through a compressed stream.

Another place this break-down can be seen is when a servlet throws an exception that the container handles. It tries to render an error page, but of course it wouldn't know that "Content-Encoding:gzip" is set, so it will fail to write in the correct format.

The only way to properly fix this is to make HttpServletResponse smart enough that it returns the compression-transparent stream from ServletResponse.getOutputStream() (and it would also have to process the exception thrown from the app.) This filter does exactly that.

Author:
Kohsuke Kawaguchi

Field Summary
static boolean DISABLED
           
 
Constructor Summary
CompressionFilter()
           
 
Method Summary
 void destroy()
           
 void doFilter(javax.servlet.ServletRequest _req, javax.servlet.ServletResponse _rsp, javax.servlet.FilterChain filterChain)
           
static boolean has(javax.servlet.ServletRequest req)
          Is this request already wrapped into CompressionFilter?
 void init(javax.servlet.FilterConfig filterConfig)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DISABLED

public static boolean DISABLED
Constructor Detail

CompressionFilter

public CompressionFilter()
Method Detail

init

public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
Specified by:
init in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException

doFilter

public void doFilter(javax.servlet.ServletRequest _req,
                     javax.servlet.ServletResponse _rsp,
                     javax.servlet.FilterChain filterChain)
              throws IOException,
                     javax.servlet.ServletException
Specified by:
doFilter in interface javax.servlet.Filter
Throws:
IOException
javax.servlet.ServletException

destroy

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

has

public static boolean has(javax.servlet.ServletRequest req)
Is this request already wrapped into CompressionFilter?



Copyright © 2013. All Rights Reserved.