net.sf.ehcache.constructs.web.filter
Class Filter
public abstract
class
Filter
extends Object
implements Filter
A generic javax.servlet.Filter with most of what we need done.
Participates in the Template Method pattern with javax.servlet.Filter.
Version: $Id: Filter.java 191 2006-09-03 22:41:48Z gregluck $
Author: Greg Luck
Method Summary |
protected boolean | acceptsEncoding(HttpServletRequest request, String name)
Checks if request accepts the named encoding. |
protected boolean | acceptsGzipEncoding(HttpServletRequest request)
Determine whether the user agent accepts GZIP encoding. |
void | destroy()
Destroys the filter. |
protected abstract void | doDestroy()
A template method that performs any Filter specific destruction tasks.
|
void | doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
Performs the filtering. |
protected abstract void | doFilter(HttpServletRequest httpRequest, HttpServletResponse httpResponse, FilterChain chain)
A template method that performs the filtering for a request.
|
protected abstract void | doInit()
A template method that performs any Filter specific initialisation tasks.
|
protected boolean | filterNotDisabled(HttpServletRequest httpRequest)
Filters can be disabled programmatically by adding a NO_FILTER parameter to the request.
|
FilterConfig | getFilterConfig()
Returns the filter config. |
void | init(FilterConfig config)
Initialises the filter. |
protected void | logRequestHeaders(HttpServletRequest request)
Logs the request headers, if debug is enabled.
|
protected String exceptionsToLogDifferently
The exceptions to log differently, as a comma separated list
protected String exceptionsToLogDifferentlyLevel
A the level of the exceptions which will be logged differently
protected FilterConfig filterConfig
The filter configuration.
public static final String NO_FILTER
If a request attribute NO_FILTER is set, then filtering will be skipped
protected boolean suppressStackTraces
Most Throwables in Web applications propagate to the user. Usually they are logged where they first
happened. Printing the stack trace once a Throwable as propagated to the servlet is sometimes
just clutters the log.
This field corresponds to an init-param of the same name. If set to true stack traces will be suppressed.
protected boolean acceptsEncoding(HttpServletRequest request, String name)
Checks if request accepts the named encoding.
protected boolean acceptsGzipEncoding(HttpServletRequest request)
Determine whether the user agent accepts GZIP encoding. This feature is part of HTTP1.1.
If a browser accepts GZIP encoding it will advertise this by including in its HTTP header:
Accept-Encoding: gzip
Requests which do not accept GZIP encoding fall into the following categories:
- Old browsers, notably IE 5 on Macintosh.
- Search robots such as yahoo. While there are quite a few bots, they only hit individual
pages once or twice a day. Note that Googlebot as of August 2004 now accepts GZIP.
- Internet Explorer through a proxy. By default HTTP1.1 is enabled but disabled when going
through a proxy. 90% of non gzip requests are caused by this.
- Site monitoring tools
As of September 2004, about 34% of requests coming from the Internet did not accept GZIP encoding.
Parameters: request
Returns: true, if the User Agent request accepts GZIP encoding
public final void destroy()
Destroys the filter. Calls template method
doDestroy to perform any filter specific
destruction tasks.
protected abstract void doDestroy()
A template method that performs any Filter specific destruction tasks.
Called from
destroy
public final void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
Performs the filtering. This method calls template method
which does the filtering.
This method takes care of error reporting and handling.
Errors are reported at Log#warn(Object) level because http tends to produce lots of errors.
protected abstract void doFilter(HttpServletRequest httpRequest, HttpServletResponse httpResponse, FilterChain chain)
A template method that performs the filtering for a request.
Called from
Filter.
protected abstract void doInit()
A template method that performs any Filter specific initialisation tasks.
Called from
init.
protected boolean filterNotDisabled(HttpServletRequest httpRequest)
Filters can be disabled programmatically by adding a
NO_FILTER parameter to the request.
This parameter is normally added to make RequestDispatcher include and forwards work.
Parameters: httpRequest the request
Returns: true if NO_FILTER is not set.
public FilterConfig getFilterConfig()
Returns the filter config.
public final void init(FilterConfig config)
Initialises the filter. Calls template method
doInit to perform any filter specific initialisation.
protected void logRequestHeaders(HttpServletRequest request)
Logs the request headers, if debug is enabled.
Parameters: request