public class MockFilterChain extends Object implements javax.servlet.FilterChain
Mock implementation of the FilterChain
interface. Used
for testing the web framework; also useful for testing custom
Filter
implementations.
A MockFilterChain
can be configured with one or more filters and a
Servlet to invoke. The first time the chain is called, it invokes all filters
and the Servlet, and saves the request and response. Subsequent invocations
raise an IllegalStateException
unless reset()
is called.
MockFilterConfig
,
PassThroughFilterChain
Constructor and Description |
---|
MockFilterChain()
Register a single do-nothing
Filter implementation. |
MockFilterChain(javax.servlet.Servlet servlet)
Create a FilterChain with a Servlet.
|
MockFilterChain(javax.servlet.Servlet servlet,
javax.servlet.Filter... filters)
Create a
FilterChain with Filter's and a Servlet. |
Modifier and Type | Method and Description |
---|---|
void |
doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
Invoke registered
Filter s and/or Servlet also saving the
request and response. |
javax.servlet.ServletRequest |
getRequest()
Return the request that
doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse) has been called with. |
javax.servlet.ServletResponse |
getResponse()
Return the response that
doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse) has been called with. |
void |
reset()
Reset the
MockFilterChain allowing it to be invoked again. |
public MockFilterChain()
Filter
implementation. The first
invocation saves the request and response. Subsequent invocations raise
an IllegalStateException
unless reset()
is called.public MockFilterChain(javax.servlet.Servlet servlet)
servlet
- the Servlet to invokepublic MockFilterChain(javax.servlet.Servlet servlet, javax.servlet.Filter... filters)
FilterChain
with Filter's and a Servlet.servlet
- the Servlet
to invoke in this FilterChain
filters
- the Filter
's to invoke in this FilterChain
public javax.servlet.ServletRequest getRequest()
doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
has been called with.public javax.servlet.ServletResponse getResponse()
doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
has been called with.public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws IOException, javax.servlet.ServletException
Filter
s and/or Servlet
also saving the
request and response.doFilter
in interface javax.servlet.FilterChain
IOException
javax.servlet.ServletException
public void reset()
MockFilterChain
allowing it to be invoked again.Copyright © 2015. All rights reserved.