Top Description Fields Constructors Methods
org.springframework.web.servlet.mvc.method.annotation

pack-priv Class RequestResponseBodyAdviceChain

extends Object
implements RequestBodyAdvice, ResponseBodyAdvice<Object>
Class Inheritance
All Implemented Interfaces
org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice, org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice
Imports
java.io.IOException, java.lang.reflect.Type, java.util.ArrayList, .Collections, .List, org.springframework.core.MethodParameter, org.springframework.http.HttpInputMessage, .MediaType, org.springframework.http.converter.HttpMessageConverter, org.springframework.http.server.ServerHttpRequest, .ServerHttpResponse, org.springframework.lang.Nullable, org.springframework.util.CollectionUtils, org.springframework.web.method.ControllerAdviceBean

Invokes RequestBodyAdvice and ResponseBodyAdvice where each instance may be (and is most likely) wrapped with ControllerAdviceBean.
Author
Rossen Stoyanchev
Since
4.2

Field Summary

Modifier and TypeField and Description
private final List<Object>
private final List<Object>

Constructor Summary

AccessConstructor and Description
public
RequestResponseBodyAdviceChain(List<Object> requestResponseBodyAdvice)

Create an instance from a list of objects that are either of type ControllerAdviceBean or RequestBodyAdvice.

Method Summary

Modifier and TypeMethod and Description
public Object
afterBodyRead(Object
set to the converter Object before the first advice is called
body
,
HttpInputMessage
the request
inputMessage
,
MethodParameter
the target method parameter
parameter
,
Type
the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.
targetType
,
Class<? extends HttpMessageConverter<?>>
the converter used to deserialize the body
converterType
)

Implements org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.afterBodyRead.

Invoked third (and last) after the request body is converted to an Object.

public HttpInputMessage
beforeBodyRead(HttpInputMessage
the request
request
,
MethodParameter
the target method parameter
parameter
,
Type
the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.
targetType
,
Class<? extends HttpMessageConverter<?>>
the converter used to deserialize the body
converterType
)

Implements org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.beforeBodyRead.

Invoked second before the request body is read and converted.

public Object
beforeBodyWrite(Object
the body to be written
body
,
MethodParameter
the return type of the controller method
returnType
,
MediaType
the content type selected through content negotiation
contentType
,
Class<? extends HttpMessageConverter<?>>
the converter type selected to write to the response
converterType
,
ServerHttpRequest
the current request
request
,
ServerHttpResponse
the current response
response
)

Implements org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.beforeBodyWrite.

Invoked after an HttpMessageConverter is selected and just before its write method is invoked.

private List<Object>
getAdvice(Class<?> adviceType)

pack-priv static <T> List<T>
getAdviceByType(List<Object> requestResponseBodyAdvice, Class<T> adviceType)

private <A> List<A>
getMatchingAdvice(MethodParameter parameter, Class<? extends A> adviceType)

public Object
handleEmptyBody(Object
usually set to null before the first advice is called
body
,
HttpInputMessage
the request
inputMessage
,
MethodParameter
the method parameter
parameter
,
Type
the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.
targetType
,
Class<? extends HttpMessageConverter<?>>
the selected converter type
converterType
)

Implements org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.handleEmptyBody.

Invoked second (and last) if the body is empty.

private <T> Object
processBody(Object body, MethodParameter returnType, MediaType contentType, Class<? extends HttpMessageConverter<?>> converterType, ServerHttpRequest request, ServerHttpResponse response)

public boolean
supports(MethodParameter
the method parameter
param
,
Type
the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.
type
,
Class<? extends HttpMessageConverter<?>>
the selected converter type
converterType
)

Implements org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.supports.

Invoked first to determine if this interceptor applies.

public boolean
supports(MethodParameter
the return type
returnType
,
Class<? extends HttpMessageConverter<?>>
the selected converter type
converterType
)

Implements org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.supports.

Whether this component supports the given controller method return type and the selected HttpMessageConverter type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

requestBodyAdviceback to summary
private final List<Object> requestBodyAdvice
responseBodyAdviceback to summary
private final List<Object> responseBodyAdvice

Constructor Detail

RequestResponseBodyAdviceChainback to summary
public RequestResponseBodyAdviceChain(List<Object> requestResponseBodyAdvice)

Create an instance from a list of objects that are either of type ControllerAdviceBean or RequestBodyAdvice.

Method Detail

afterBodyReadback to summary
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)

Implements org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.afterBodyRead.

Doc from org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.afterBodyRead.

Invoked third (and last) after the request body is converted to an Object.

Parameters
body:Object

set to the converter Object before the first advice is called

inputMessage:HttpInputMessage

the request

parameter:MethodParameter

the target method parameter

targetType:Type

the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.

converterType:Class<? extends HttpMessageConverter<?>>

the converter used to deserialize the body

Returns:Object

the same body or a new instance

Annotations
@Override
beforeBodyReadback to summary
public HttpInputMessage beforeBodyRead(HttpInputMessage request, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) throws IOException

Implements org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.beforeBodyRead.

Doc from org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.beforeBodyRead.

Invoked second before the request body is read and converted.

Parameters
request:HttpInputMessage

the request

parameter:MethodParameter

the target method parameter

targetType:Type

the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.

converterType:Class<? extends HttpMessageConverter<?>>

the converter used to deserialize the body

Returns:HttpInputMessage

the input request or a new instance (never null)

Annotations
@Override
beforeBodyWriteback to summary
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType contentType, Class<? extends HttpMessageConverter<?>> converterType, ServerHttpRequest request, ServerHttpResponse response)

Implements org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.beforeBodyWrite.

Doc from org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.beforeBodyWrite.

Invoked after an HttpMessageConverter is selected and just before its write method is invoked.

Parameters
body:Object

the body to be written

returnType:MethodParameter

the return type of the controller method

contentType:MediaType

the content type selected through content negotiation

converterType:Class<? extends HttpMessageConverter<?>>

the converter type selected to write to the response

request:ServerHttpRequest

the current request

response:ServerHttpResponse

the current response

Returns:Object

the body that was passed in or a modified (possibly new) instance

Annotations
@Override
@Nullable
getAdviceback to summary
private List<Object> getAdvice(Class<?> adviceType)
getAdviceByTypeback to summary
pack-priv static <T> List<T> getAdviceByType(List<Object> requestResponseBodyAdvice, Class<T> adviceType)
Annotations
@SuppressWarnings:unchecked
getMatchingAdviceback to summary
private <A> List<A> getMatchingAdvice(MethodParameter parameter, Class<? extends A> adviceType)
Annotations
@SuppressWarnings:unchecked
handleEmptyBodyback to summary
public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)

Implements org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.handleEmptyBody.

Doc from org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.handleEmptyBody.

Invoked second (and last) if the body is empty.

Parameters
body:Object

usually set to null before the first advice is called

inputMessage:HttpInputMessage

the request

parameter:MethodParameter

the method parameter

targetType:Type

the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.

converterType:Class<? extends HttpMessageConverter<?>>

the selected converter type

Returns:Object

the value to use, or null which may then raise an HttpMessageNotReadableException if the argument is required

Annotations
@Override
@Nullable
processBodyback to summary
private <T> Object processBody(Object body, MethodParameter returnType, MediaType contentType, Class<? extends HttpMessageConverter<?>> converterType, ServerHttpRequest request, ServerHttpResponse response)
Annotations
@SuppressWarnings:unchecked
@Nullable
supportsback to summary
public boolean supports(MethodParameter param, Type type, Class<? extends HttpMessageConverter<?>> converterType)

Implements org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.supports.

Doc from org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.supports.

Invoked first to determine if this interceptor applies.

Parameters
param:MethodParameter

the method parameter

type:Type

the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.

converterType:Class<? extends HttpMessageConverter<?>>

the selected converter type

Returns:boolean

whether this interceptor should be invoked or not

Annotations
@Override
supportsback to summary
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType)

Implements org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.supports.

Doc from org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.supports.

Whether this component supports the given controller method return type and the selected HttpMessageConverter type.

Parameters
returnType:MethodParameter

the return type

converterType:Class<? extends HttpMessageConverter<?>>

the selected converter type

Returns:boolean

true if beforeBodyWrite should be invoked; false otherwise

Annotations
@Override