public abstract class AdviceFilter extends OncePerRequestFilter
preHandle
,
postHandle
,
and afterCompletion
hooks.ALREADY_FILTERED_SUFFIX
filterConfig
Constructor and Description |
---|
AdviceFilter() |
Modifier and Type | Method and Description |
---|---|
void |
afterCompletion(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
Exception exception)
Called in all cases in a
finally block even if preHandle returns
false or if an exception is thrown during filter chain processing. |
protected void |
cleanup(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
Exception existing)
Executes cleanup logic in the
finally code block in the
doFilterInternal
implementation. |
void |
doFilterInternal(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain)
|
protected void |
executeChain(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain)
Actually executes the specified filter chain by calling
chain.doFilter(request,response); . |
protected void |
postHandle(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
Allows 'post' advice logic to be called, but only if no exception occurs during filter chain execution.
|
protected boolean |
preHandle(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
Returns
true if the filter chain should be allowed to continue, false otherwise. |
doFilter, getAlreadyFilteredAttributeName, isEnabled, isEnabled, setEnabled, shouldNotFilter
getName, setName, toStringBuilder
destroy, getFilterConfig, getInitParam, init, onFilterConfigSet, setFilterConfig
getContextAttribute, getContextInitParam, getServletContext, removeContextAttribute, setContextAttribute, setServletContext, toString
public AdviceFilter()
protected boolean preHandle(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws Exception
true
if the filter chain should be allowed to continue, false
otherwise.
It is called before the chain is actually consulted/executed.
The default implementation returns true
always and exists as a template method for subclasses.request
- the incoming ServletRequestresponse
- the outgoing ServletResponsetrue
if the filter chain should be allowed to continue, false
otherwise.Exception
- if there is any error.protected void postHandle(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws Exception
executeChain
throws an exception, this method will never be called. Be aware of
this when implementing logic. Most resource 'cleanup' behavior is often done in the
afterCompletion(request,response,exception)
implementation, which is guaranteed to be called for every request, even when the chain processing throws
an Exception.
The default implementation does nothing (no-op) and exists as a template method for subclasses.request
- the incoming ServletRequestresponse
- the outgoing ServletResponseException
- if an error occurs.public void afterCompletion(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Exception exception) throws Exception
finally
block even if preHandle
returns
false
or if an exception is thrown during filter chain processing. Can be used for resource
cleanup if so desired.
The default implementation does nothing (no-op) and exists as a template method for subclasses.request
- the incoming ServletRequestresponse
- the outgoing ServletResponseexception
- any exception thrown during preHandle
, executeChain
,
or postHandle
execution, or null
if no exception was thrown
(i.e. the chain processed successfully).Exception
- if an error occurs.protected void executeChain(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws Exception
chain.doFilter(request,response);
.
Can be overridden by subclasses for custom logic.request
- the incoming ServletRequestresponse
- the outgoing ServletResponsechain
- the filter chain to executeException
- if there is any error executing the chain.public void doFilterInternal(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws javax.servlet.ServletException, IOException
doFilterInternal
in class OncePerRequestFilter
request
- the incoming ServletRequestresponse
- the outgoing ServletResponsechain
- the filter chain to executejavax.servlet.ServletException
- if a servlet-related error occursIOException
- if an IO error occursprotected void cleanup(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Exception existing) throws javax.servlet.ServletException, IOException
finally
code block in the
doFilterInternal
implementation.
This implementation specifically calls
afterCompletion
as well as handles any exceptions properly.request
- the incoming ServletRequest
response
- the outgoing ServletResponse
existing
- any exception that might have occurred while executing the FilterChain
or
pre or post advice, or null
if the pre/chain/post execution did not throw an Exception
.javax.servlet.ServletException
- if any exception other than an IOException
is thrown.IOException
- if the pre/chain/post execution throw an IOException
Copyright © 2004–2019 The Apache Software Foundation. All rights reserved.