39
39
* Participates in the Template Method pattern with {@link javax.servlet.Filter}.
41
41
* @author <a href="mailto:gluck@thoughtworks.com">Greg Luck</a>
42
* @version $Id: Filter.java 519 2007-07-27 07:11:45Z gregluck $
42
* @version $Id: Filter.java 604 2008-04-25 02:20:57Z gregluck $
44
44
public abstract class Filter implements javax.servlet.Filter {
80
80
* {@link #doFilter(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,javax.servlet.FilterChain) } which does the filtering.
81
81
* This method takes care of error reporting and handling.
82
82
* Errors are reported at {@link Log#warn(Object)} level because http tends to produce lots of errors.
83
84
* @throws IOException if an IOException occurs during this method it will be rethrown and will not be wrapped
85
86
public final void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
187
* Initialises the filter. Calls template method {@link #doInit()} to perform any filter specific initialisation.
188
* Initialises the filter.
190
* Calls template method {@link #doInit(javax.servlet.FilterConfig)} to perform any filter specific initialisation.
189
public final void init(final FilterConfig config) throws ServletException {
192
public final void init(final FilterConfig filterConfig) throws ServletException {
192
this.filterConfig = config;
193
processInitParams(config);
195
this.filterConfig = filterConfig;
196
processInitParams(filterConfig);
195
198
// Attempt to initialise this filter
199
doInit(filterConfig);
197
200
} catch (final Exception e) {
198
201
LOG.fatal("Could not initialise servlet filter.", e);
199
202
throw new ServletException("Could not initialise servlet filter.", e);
203
private void processInitParams(final FilterConfig config) throws ServletException {
207
* Processes initialisation parameters. These are configured in web.xml in accordance with the
208
* Servlet specification using the following syntax:
213
* <param-name>blah</param-name>
214
* <param-value>blahvalue</param-value>
219
* @throws ServletException
221
protected void processInitParams(final FilterConfig config) throws ServletException {
204
222
String exceptions = config.getInitParameter("exceptionsToLogDifferently");
205
223
String level = config.getInitParameter("exceptionsToLogDifferentlyLevel");
206
224
String suppressStackTracesString = config.getInitParameter("suppressStackTraces");
314
332
* A template method that performs any Filter specific initialisation tasks.
315
333
* Called from {@link #init(FilterConfig)}.
334
* @param filterConfig
317
protected abstract void doInit() throws Exception;
336
protected abstract void doInit(FilterConfig filterConfig) throws Exception;
320
339
* Returns the filter config.