public class MockFilterChain
extends java.lang.Object
javax.servlet.FilterChain
interface.
Used for testing the web framework; also useful for testing
custom javax.servlet.Filter
implementations.
MockFilterConfig
,
PassThroughFilterChain
Modifier and Type | Class and Description |
---|---|
private static class |
MockFilterChain.ServletFilterProxy
A filter that simply delegates to a Servlet.
|
Modifier and Type | Field and Description |
---|---|
private java.util.Iterator<Filter> |
iterator |
private ServletRequest |
request |
private ServletResponse |
response |
Modifier | Constructor and Description |
---|---|
|
MockFilterChain()
Register a single do-nothing
Filter implementation. |
private |
MockFilterChain(Filter... filters)
Create a
FilterChain with one or more Filter instances. |
|
MockFilterChain(Servlet servlet)
Create a FilterChain with a
Servlet but without filters. |
|
MockFilterChain(Servlet servlet,
Filter... filters)
Create a FilterChain with one or more
Filter instances and a Servlet . |
Modifier and Type | Method and Description |
---|---|
void |
doFilter(ServletRequest request,
ServletResponse response)
Invoke registered
Filter s and/or Servlet also saving the
request and response. |
ServletRequest |
getRequest()
Return the request that
doFilter(ServletRequest, ServletResponse) has been called with. |
ServletResponse |
getResponse()
Return the response that
doFilter(ServletRequest, ServletResponse) has been called with. |
private ServletRequest request
private ServletResponse response
private final java.util.Iterator<Filter> iterator
public MockFilterChain()
Filter
implementation. The first
invocation saves the request and response. Subsequent invocations raise
an IllegalStateException
.public MockFilterChain(Servlet servlet)
Servlet
but without filters.servlet
- the Servlet
to use in this FilterChain
public MockFilterChain(Servlet servlet, Filter... filters)
Filter
instances and a Servlet
.servlet
- the Servlet
to use in this FilterChain
filters
- the Filter
's to use in this FilterChain
private MockFilterChain(Filter... filters)
FilterChain
with one or more Filter
instances.filters
- the Filter
's to use in this FilterChain
public void doFilter(ServletRequest request, ServletResponse response) throws java.io.IOException, ServletException
Filter
s and/or Servlet
also saving the
request and response.java.io.IOException
ServletException
public ServletRequest getRequest()
doFilter(ServletRequest, ServletResponse)
has been called with.public ServletResponse getResponse()
doFilter(ServletRequest, ServletResponse)
has been called with.