public class OpenApiValidationFilter
extends org.springframework.web.filter.OncePerRequestFilter
HttpServletRequest and HttpServletResponse.
Wrapping is necessary for the validation.
The Swagger Request Validator needs the pure request body for its validation. Additionally the Spring
RestController / Controller
needs the pure request body to unmarshal the JSON / form data.
But a ServletInputStream can only be read once and needs to be rewind after
successful validation against the OpenAPI / Swagger definition. So the controller can then access it again.
The same applies to response validation and writing to the ServletOutputStream.
| Constructor and Description |
|---|
OpenApiValidationFilter()
Creates a
OpenApiValidationFilter which validates incoming requests. |
OpenApiValidationFilter(boolean validateRequests,
boolean validateResponses)
Creates a
OpenApiValidationFilter which validates incoming requests and / or responses. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doFilterInternal(javax.servlet.http.HttpServletRequest servletRequest,
javax.servlet.http.HttpServletResponse servletResponse,
javax.servlet.FilterChain filterChain) |
protected boolean |
shouldNotFilterAsyncDispatch() |
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterErrorDispatchpublic OpenApiValidationFilter()
OpenApiValidationFilter which validates incoming requests.public OpenApiValidationFilter(boolean validateRequests,
boolean validateResponses)
OpenApiValidationFilter which validates incoming requests and / or responses.validateRequests - will enable request validation if truevalidateResponses - will enable response validation if trueprotected void doFilterInternal(javax.servlet.http.HttpServletRequest servletRequest,
javax.servlet.http.HttpServletResponse servletResponse,
javax.servlet.FilterChain filterChain)
throws javax.servlet.ServletException,
IOException
doFilterInternal in class org.springframework.web.filter.OncePerRequestFilterjavax.servlet.ServletExceptionIOExceptionprotected boolean shouldNotFilterAsyncDispatch()
shouldNotFilterAsyncDispatch in class org.springframework.web.filter.OncePerRequestFilterCopyright © 2016–2022 Atlassian. All rights reserved.