public class CompressionFilter extends Object implements javax.servlet.Filter
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 a GZIP output stream 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.
Modifier and Type | Field and Description |
---|---|
static boolean |
DISABLED |
Constructor and Description |
---|
CompressionFilter() |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
void |
doFilter(javax.servlet.ServletRequest _req,
javax.servlet.ServletResponse _rsp,
javax.servlet.FilterChain filterChain) |
static UncaughtExceptionHandler |
getUncaughtExceptionHandler(javax.servlet.ServletContext context) |
static boolean |
has(javax.servlet.ServletRequest req)
Is this request already wrapped into
CompressionFilter ? |
void |
init(javax.servlet.FilterConfig filterConfig) |
static void |
setUncaughtExceptionHandler(javax.servlet.ServletContext context,
UncaughtExceptionHandler handler) |
public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException
init
in interface javax.servlet.Filter
javax.servlet.ServletException
public void doFilter(javax.servlet.ServletRequest _req, javax.servlet.ServletResponse _rsp, javax.servlet.FilterChain filterChain) throws IOException, javax.servlet.ServletException
doFilter
in interface javax.servlet.Filter
IOException
javax.servlet.ServletException
public void destroy()
destroy
in interface javax.servlet.Filter
public static void setUncaughtExceptionHandler(javax.servlet.ServletContext context, UncaughtExceptionHandler handler)
public static UncaughtExceptionHandler getUncaughtExceptionHandler(javax.servlet.ServletContext context)
public static boolean has(javax.servlet.ServletRequest req)
CompressionFilter
?Copyright © 2013. All rights reserved.