Package org.springframework.mock.web

# Class MockFilterChain

java.lang.Object
org.springframework.mock.web.MockFilterChain

All Implemented Interfaces:
  `FilterChain`

public class MockFilterChain extends Object implements FilterChain
Mock implementation of the `FilterChain` interface.

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.

Since:
  2.0.3
Author:
  Juergen Hoeller, Rob Winch, Rossen Stoyanchev
See Also:
  - `MockFilterConfig`
  - `PassThroughFilterChain`

## Constructor Summary

Constructors
Constructor
Description
`MockFilterChain()`
Create an empty `MockFilterChain` without any filters.
`MockFilterChain(Servlet servlet)`
Create a `MockFilterChain` with a `Servlet`.
`MockFilterChain(Servlet servlet, Filter... filters)`
Create a `MockFilterChain` with a `Servlet` and filters.

## Method Summary

Modifier and Type
Method
Description
`void`
`doFilter(ServletRequest request, ServletResponse response)`
Invoke registered `Filters` and/or `Servlet` also saving the request and response.
`ServletRequest`
`getRequest()`
Return the request that `doFilter(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)` has been called with.
`ServletResponse`
`getResponse()`
Return the response that `doFilter(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)` has been called with.
`void`
`reset()`
Reset this `MockFilterChain` allowing it to be invoked again.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### MockFilterChain

public MockFilterChain()
Create an empty `MockFilterChain` without any filters.

### MockFilterChain

public MockFilterChain(Servlet servlet)
Create a `MockFilterChain` with a `Servlet`.

Parameters:
  `servlet` - the `Servlet` to invoke
Since:
  3.2

### MockFilterChain

public MockFilterChain(Servlet servlet, Filter... filters)
Create a `MockFilterChain` with a `Servlet` and filters.

Parameters:
  `servlet` - the `Servlet` to invoke in this `MockFilterChain`
  `filters` - the filters to invoke in this `MockFilterChain`
Since:
  3.2

## Method Details

### getRequest

@Nullable public ServletRequest getRequest()
Return the request that `doFilter(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)` has been called with.

### getResponse

@Nullable public ServletResponse getResponse()
Return the response that `doFilter(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)` has been called with.

### doFilter

public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException
Invoke registered `Filters` and/or `Servlet` also saving the request and response.

Specified by:
  `doFilter` in interface `FilterChain`
Throws:
  `IOException`
  `ServletException`

### reset

public void reset()
Reset this `MockFilterChain` allowing it to be invoked again.