public class RequestResponseBodyMethodProcessor extends AbstractMessageConverterMethodProcessor
@RequestBody
and handles return
values from methods annotated with @ResponseBody
by reading and writing
to the body of the request or response with an HttpMessageConverter
.
An @RequestBody
method argument is also validated if it is annotated
with @javax.validation.Valid
. In case of validation failure,
MethodArgumentNotValidException
is raised and results in an HTTP 400
response status code if DefaultHandlerExceptionResolver
is configured.
Modifier and Type | Field and Description |
---|---|
private static java.util.List<HttpMethod> |
SUPPORTED_METHODS |
allSupportedMediaTypes, logger, messageConverters
Constructor and Description |
---|
RequestResponseBodyMethodProcessor(java.util.List<HttpMessageConverter<?>> converters)
Basic constructor with converters only.
|
RequestResponseBodyMethodProcessor(java.util.List<HttpMessageConverter<?>> converters,
ContentNegotiationManager manager)
Basic constructor with converters and
ContentNegotiationManager . |
RequestResponseBodyMethodProcessor(java.util.List<HttpMessageConverter<?>> converters,
ContentNegotiationManager manager,
java.util.List<java.lang.Object> requestResponseBodyAdvice)
Complete constructor for resolving
@RequestBody and handling
@ResponseBody . |
RequestResponseBodyMethodProcessor(java.util.List<HttpMessageConverter<?>> converters,
java.util.List<java.lang.Object> requestResponseBodyAdvice)
Complete constructor for resolving
@RequestBody method arguments. |
Modifier and Type | Method and Description |
---|---|
void |
handleReturnValue(java.lang.Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest)
Handle the given return value by adding attributes to the model and
setting a view or setting the
ModelAndViewContainer.setRequestHandled(boolean) flag to true
to indicate the response has been handled directly. |
protected <T> java.lang.Object |
readWithMessageConverters(NativeWebRequest webRequest,
MethodParameter methodParam,
java.lang.reflect.Type paramType)
Create the method argument value of the expected parameter type by
reading from the given request.
|
java.lang.Object |
resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest,
WebDataBinderFactory binderFactory)
Throws MethodArgumentNotValidException if validation fails.
|
boolean |
supportsParameter(MethodParameter parameter)
Whether the given method parameter is
supported by this resolver.
|
boolean |
supportsReturnType(MethodParameter returnType)
Whether the given method return type is
supported by this handler.
|
createOutputMessage, getProducibleMediaTypes, getProducibleMediaTypes, getReturnValueType, writeWithMessageConverters, writeWithMessageConverters
createInputMessage, getAdvice, isBindExceptionRequired, readWithMessageConverters, validateIfApplicable
private static final java.util.List<HttpMethod> SUPPORTED_METHODS
public RequestResponseBodyMethodProcessor(java.util.List<HttpMessageConverter<?>> converters)
@RequestBody
. For handling @ResponseBody
consider also
providing a ContentNegotiationManager
.public RequestResponseBodyMethodProcessor(java.util.List<HttpMessageConverter<?>> converters, ContentNegotiationManager manager)
ContentNegotiationManager
.
Suitable for resolving @RequestBody
and handling
@ResponseBody
without Request~
or
ResponseBodyAdvice
.public RequestResponseBodyMethodProcessor(java.util.List<HttpMessageConverter<?>> converters, java.util.List<java.lang.Object> requestResponseBodyAdvice)
@RequestBody
method arguments.
For handling @ResponseBody
consider also providing a
ContentNegotiationManager
.public RequestResponseBodyMethodProcessor(java.util.List<HttpMessageConverter<?>> converters, ContentNegotiationManager manager, java.util.List<java.lang.Object> requestResponseBodyAdvice)
@RequestBody
and handling
@ResponseBody
.public boolean supportsParameter(MethodParameter parameter)
HandlerMethodArgumentResolver
parameter
- the method parameter to checktrue
if this resolver supports the supplied parameter;
false
otherwisepublic boolean supportsReturnType(MethodParameter returnType)
HandlerMethodReturnValueHandler
returnType
- the method return type to checktrue
if this handler supports the supplied return type;
false
otherwisepublic java.lang.Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws java.lang.Exception
parameter
- the method parameter to resolve. This parameter must
have previously been passed to HandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter)
which must
have returned true
.mavContainer
- the ModelAndViewContainer for the current requestwebRequest
- the current requestbinderFactory
- a factory for creating WebDataBinder
instancesnull
HttpMessageNotReadableException
- if RequestBody.required()
is true
and there is no body content or if there is no suitable
converter to read the content with.java.lang.Exception
- in case of errors with the preparation of argument valuesprotected <T> java.lang.Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter methodParam, java.lang.reflect.Type paramType) throws java.io.IOException, HttpMediaTypeNotSupportedException
AbstractMessageConverterMethodArgumentResolver
readWithMessageConverters
in class AbstractMessageConverterMethodArgumentResolver
T
- the expected type of the argument value to be createdwebRequest
- the current requestmethodParam
- the method argumentparamType
- the type of the argument value to be createdjava.io.IOException
- if the reading from the request failsHttpMediaTypeNotSupportedException
- if no suitable message converter is foundpublic void handleReturnValue(java.lang.Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws java.io.IOException, HttpMediaTypeNotAcceptableException
HandlerMethodReturnValueHandler
ModelAndViewContainer.setRequestHandled(boolean)
flag to true
to indicate the response has been handled directly.returnValue
- the value returned from the handler methodreturnType
- the type of the return value. This type must have
previously been passed to HandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter)
which must
have returned true
.mavContainer
- the ModelAndViewContainer for the current requestwebRequest
- the current requestjava.io.IOException
HttpMediaTypeNotAcceptableException