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

Field Summary
protected StringexceptionsToLogDifferently
The exceptions to log differently, as a comma separated list
protected StringexceptionsToLogDifferentlyLevel
A the level of the exceptions which will be logged differently
protected FilterConfigfilterConfig
The filter configuration.
static StringNO_FILTER
If a request attribute NO_FILTER is set, then filtering will be skipped
protected booleansuppressStackTraces
Most Throwables in Web applications propagate to the user.
Method Summary
protected booleanacceptsEncoding(HttpServletRequest request, String name)
Checks if request accepts the named encoding.
protected booleanacceptsGzipEncoding(HttpServletRequest request)
Determine whether the user agent accepts GZIP encoding.
voiddestroy()
Destroys the filter.
protected abstract voiddoDestroy()
A template method that performs any Filter specific destruction tasks.
voiddoFilter(ServletRequest request, ServletResponse response, FilterChain chain)
Performs the filtering.
protected abstract voiddoFilter(HttpServletRequest httpRequest, HttpServletResponse httpResponse, FilterChain chain)
A template method that performs the filtering for a request.
protected abstract voiddoInit()
A template method that performs any Filter specific initialisation tasks.
protected booleanfilterNotDisabled(HttpServletRequest httpRequest)
Filters can be disabled programmatically by adding a NO_FILTER parameter to the request.
FilterConfiggetFilterConfig()
Returns the filter config.
voidinit(FilterConfig config)
Initialises the filter.
protected voidlogRequestHeaders(HttpServletRequest request)
Logs the request headers, if debug is enabled.

Field Detail

exceptionsToLogDifferently

protected String exceptionsToLogDifferently
The exceptions to log differently, as a comma separated list

exceptionsToLogDifferentlyLevel

protected String exceptionsToLogDifferentlyLevel
A the level of the exceptions which will be logged differently

filterConfig

protected FilterConfig filterConfig
The filter configuration.

NO_FILTER

public static final String NO_FILTER
If a request attribute NO_FILTER is set, then filtering will be skipped

suppressStackTraces

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.

Method Detail

acceptsEncoding

protected boolean acceptsEncoding(HttpServletRequest request, String name)
Checks if request accepts the named encoding.

acceptsGzipEncoding

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:

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

destroy

public final void destroy()
Destroys the filter. Calls template method doDestroy to perform any filter specific destruction tasks.

doDestroy

protected abstract void doDestroy()
A template method that performs any Filter specific destruction tasks. Called from destroy

doFilter

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.

doFilter

protected abstract void doFilter(HttpServletRequest httpRequest, HttpServletResponse httpResponse, FilterChain chain)
A template method that performs the filtering for a request. Called from Filter.

doInit

protected abstract void doInit()
A template method that performs any Filter specific initialisation tasks. Called from init.

filterNotDisabled

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.

getFilterConfig

public FilterConfig getFilterConfig()
Returns the filter config.

init

public final void init(FilterConfig config)
Initialises the filter. Calls template method doInit to perform any filter specific initialisation.

logRequestHeaders

protected void logRequestHeaders(HttpServletRequest request)
Logs the request headers, if debug is enabled.

Parameters: request