Package org.springframework.web.filter
Class CompositeFilter
- java.lang.Object
- org.springframework.web.filter.CompositeFilter
- All Implemented Interfaces:
Filter
public class CompositeFilter extends Object implements Filter
A generic composite servletFilter
that just delegates its behavior to a chain (list) of user-supplied filters, achieving the functionality of aFilterChain
, but conveniently using onlyFilter
instances.This is useful for filters that require dependency injection, and can therefore be set up in a Spring application context. Typically, this composite would be used in conjunction with
DelegatingFilterProxy
, so that it can be declared in Spring but applied to a servlet context.- Since:
- 3.1
- Author:
- Dave Syer
Constructor Summary
Constructors Constructor Description CompositeFilter()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroy()
Clean up all the filters supplied, calling each one's destroy method in turn, but in reverse order.void
doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
Forms a temporary chain from the list of delegate filters supplied (setFilters(java.util.List<? extends javax.servlet.Filter>)
) and executes them in order.void
init(FilterConfig config)
Initialize all the filters, calling each one's init method in turn in the order supplied.void
setFilters(List<? extends Filter> filters)
Constructor Detail
CompositeFilter
public CompositeFilter()
Method Detail
setFilters
public void setFilters(List<? extends Filter> filters)
init
public void init(FilterConfig config) throws ServletException
Initialize all the filters, calling each one's init method in turn in the order supplied.- Specified by:
init
in interfaceFilter
- Parameters:
config
- aFilterConfig
object containing the filter's configuration and initialization parameters- Throws:
ServletException
- if an exception has occurred that interferes with the filter's normal operation- See Also:
Filter.init(FilterConfig)
doFilter
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
Forms a temporary chain from the list of delegate filters supplied (setFilters(java.util.List<? extends javax.servlet.Filter>)
) and executes them in order. Each filter delegates to the next one in the list, achieving the normal behavior of aFilterChain
, despite the fact that this is aFilter
.- Specified by:
doFilter
in interfaceFilter
- Parameters:
request
- theServletRequest
object contains the client's requestresponse
- theServletResponse
object contains the filter's responsechain
- theFilterChain
for invoking the next filter or the resource- Throws:
IOException
- if an I/O related error has occurred during the processingServletException
- if an exception occurs that interferes with the filter's normal operation- See Also:
Filter.doFilter(ServletRequest, ServletResponse, FilterChain)
destroy
public void destroy()
Clean up all the filters supplied, calling each one's destroy method in turn, but in reverse order.- Specified by:
destroy
in interfaceFilter
- See Also:
Filter.init(FilterConfig)