class RequestResponseBodyAdviceChain extends java.lang.Object implements RequestBodyAdvice, ResponseBodyAdvice<java.lang.Object>
RequestBodyAdvice
and ResponseBodyAdvice
where each
instance may be (and is most likely) wrapped with
ControllerAdviceBean
.Modifier and Type | Field and Description |
---|---|
private java.util.List<java.lang.Object> |
requestBodyAdvice |
private java.util.List<java.lang.Object> |
responseBodyAdvice |
Constructor and Description |
---|
RequestResponseBodyAdviceChain(java.util.List<java.lang.Object> requestResponseBodyAdvice)
Create an instance from a list of objects that are either of type
ControllerAdviceBean or RequestBodyAdvice . |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
afterBodyRead(java.lang.Object body,
HttpInputMessage inputMessage,
MethodParameter parameter,
java.lang.reflect.Type targetType,
java.lang.Class<? extends HttpMessageConverter<?>> converterType)
Invoked third (and last) after the request body is converted to an Object.
|
HttpInputMessage |
beforeBodyRead(HttpInputMessage request,
MethodParameter parameter,
java.lang.reflect.Type targetType,
java.lang.Class<? extends HttpMessageConverter<?>> converterType)
Invoked second before the request body is read and converted.
|
java.lang.Object |
beforeBodyWrite(java.lang.Object body,
MethodParameter returnType,
MediaType contentType,
java.lang.Class<? extends HttpMessageConverter<?>> converterType,
ServerHttpRequest request,
ServerHttpResponse response)
Invoked after an
HttpMessageConverter is selected and just before
its write method is invoked. |
private java.util.List<java.lang.Object> |
getAdvice(java.lang.Class<?> adviceType) |
private <A> java.util.List<A> |
getMatchingAdvice(MethodParameter parameter,
java.lang.Class<? extends A> adviceType) |
java.lang.Object |
handleEmptyBody(java.lang.Object body,
HttpInputMessage inputMessage,
MethodParameter parameter,
java.lang.reflect.Type targetType,
java.lang.Class<? extends HttpMessageConverter<?>> converterType)
Invoked second (and last) if the body is empty.
|
private void |
initAdvice(java.util.List<java.lang.Object> requestResponseBodyAdvice) |
private <T> java.lang.Object |
processBody(java.lang.Object body,
MethodParameter returnType,
MediaType contentType,
java.lang.Class<? extends HttpMessageConverter<?>> converterType,
ServerHttpRequest request,
ServerHttpResponse response) |
boolean |
supports(MethodParameter returnType,
java.lang.Class<? extends HttpMessageConverter<?>> converterType)
Whether this component supports the given controller method return type
and the selected
HttpMessageConverter type. |
boolean |
supports(MethodParameter param,
java.lang.reflect.Type type,
java.lang.Class<? extends HttpMessageConverter<?>> converterType)
Invoked first to determine if this interceptor applies.
|
private final java.util.List<java.lang.Object> requestBodyAdvice
private final java.util.List<java.lang.Object> responseBodyAdvice
public RequestResponseBodyAdviceChain(java.util.List<java.lang.Object> requestResponseBodyAdvice)
ControllerAdviceBean
or RequestBodyAdvice
.private void initAdvice(java.util.List<java.lang.Object> requestResponseBodyAdvice)
private java.util.List<java.lang.Object> getAdvice(java.lang.Class<?> adviceType)
public boolean supports(MethodParameter param, java.lang.reflect.Type type, java.lang.Class<? extends HttpMessageConverter<?>> converterType)
RequestBodyAdvice
supports
in interface RequestBodyAdvice
param
- the method parametertype
- the target type, not necessarily the same as the method
parameter type, e.g. for HttpEntity<String>
.converterType
- the selected converter typepublic boolean supports(MethodParameter returnType, java.lang.Class<? extends HttpMessageConverter<?>> converterType)
ResponseBodyAdvice
HttpMessageConverter
type.supports
in interface ResponseBodyAdvice<java.lang.Object>
returnType
- the return typeconverterType
- the selected converter typetrue
if ResponseBodyAdvice.beforeBodyWrite(T, org.springframework.core.MethodParameter, org.springframework.http.MediaType, java.lang.Class<? extends org.springframework.http.converter.HttpMessageConverter<?>>, org.springframework.http.server.ServerHttpRequest, org.springframework.http.server.ServerHttpResponse)
should be invoked, false
otherwisepublic java.lang.Object handleEmptyBody(java.lang.Object body, HttpInputMessage inputMessage, MethodParameter parameter, java.lang.reflect.Type targetType, java.lang.Class<? extends HttpMessageConverter<?>> converterType)
RequestBodyAdvice
handleEmptyBody
in interface RequestBodyAdvice
body
- set to null
before the first advice is calledinputMessage
- the requestparameter
- the method parametertargetType
- the target type, not necessarily the same as the method
parameter type, e.g. for HttpEntity<String>
.converterType
- the selected converter typenull
which may then raise an
HttpMessageNotReadableException
if the argument is required.public HttpInputMessage beforeBodyRead(HttpInputMessage request, MethodParameter parameter, java.lang.reflect.Type targetType, java.lang.Class<? extends HttpMessageConverter<?>> converterType) throws java.io.IOException
RequestBodyAdvice
beforeBodyRead
in interface RequestBodyAdvice
request
- the requestparameter
- the target method parametertargetType
- the target type, not necessarily the same as the method
parameter type, e.g. for HttpEntity<String>
.converterType
- the converter used to deserialize the bodynull
java.io.IOException
public java.lang.Object afterBodyRead(java.lang.Object body, HttpInputMessage inputMessage, MethodParameter parameter, java.lang.reflect.Type targetType, java.lang.Class<? extends HttpMessageConverter<?>> converterType)
RequestBodyAdvice
afterBodyRead
in interface RequestBodyAdvice
body
- set to the converter Object before the 1st advice is calledinputMessage
- the requestparameter
- the target method parametertargetType
- the target type, not necessarily the same as the method
parameter type, e.g. for HttpEntity<String>
.converterType
- the converter used to deserialize the bodypublic java.lang.Object beforeBodyWrite(java.lang.Object body, MethodParameter returnType, MediaType contentType, java.lang.Class<? extends HttpMessageConverter<?>> converterType, ServerHttpRequest request, ServerHttpResponse response)
ResponseBodyAdvice
HttpMessageConverter
is selected and just before
its write method is invoked.beforeBodyWrite
in interface ResponseBodyAdvice<java.lang.Object>
body
- the body to be writtenreturnType
- the return type of the controller methodcontentType
- the content type selected through content negotiationconverterType
- the converter type selected to write to the responserequest
- the current requestresponse
- the current responseprivate <T> java.lang.Object processBody(java.lang.Object body, MethodParameter returnType, MediaType contentType, java.lang.Class<? extends HttpMessageConverter<?>> converterType, ServerHttpRequest request, ServerHttpResponse response)
private <A> java.util.List<A> getMatchingAdvice(MethodParameter parameter, java.lang.Class<? extends A> adviceType)