public class CompositeFilter
extends java.lang.Object
Filter
that just delegates its behaviour to a chain (list) of user supplied
filters, achieving the functionality of a FilterChain
, but conveniently using only Filter
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.Modifier and Type | Class and Description |
---|---|
private static class |
CompositeFilter.VirtualFilterChain |
Modifier and Type | Field and Description |
---|---|
private java.util.List<? extends Filter> |
filters |
Constructor and Description |
---|
CompositeFilter() |
Modifier and Type | Method and 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(List) ) 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(java.util.List<? extends Filter> filters) |
public void setFilters(java.util.List<? extends Filter> filters)
public void destroy()
Filter#init(FilterConfig)
public void init(FilterConfig config) throws ServletException
ServletException
Filter#init(FilterConfig)
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, ServletException
setFilters(List)
) and executes them
in order. Each filter delegates to the next one in the list, achieving the normal behaviour of a
FilterChain
, despite the fact that this is a Filter
.java.io.IOException
ServletException
Filter#doFilter(ServletRequest, ServletResponse, FilterChain)