org.springframework.web.servlet.mvc.method.annotation
Class RequestResponseBodyMethodProcessor
java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor
org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor
- All Implemented Interfaces:
- org.springframework.web.method.support.HandlerMethodArgumentResolver, org.springframework.web.method.support.HandlerMethodReturnValueHandler
public class RequestResponseBodyMethodProcessor
- extends AbstractMessageConverterMethodProcessor
Resolves method arguments annotated with @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 a 400 response status code if DefaultHandlerExceptionResolver
is configured.
- Since:
- 3.1
- Author:
- Arjen Poutsma, Rossen Stoyanchev
Method Summary |
void |
handleReturnValue(java.lang.Object returnValue,
org.springframework.core.MethodParameter returnType,
org.springframework.web.method.support.ModelAndViewContainer mavContainer,
org.springframework.web.context.request.NativeWebRequest webRequest)
|
protected
|
readWithMessageConverters(org.springframework.http.HttpInputMessage inputMessage,
org.springframework.core.MethodParameter methodParam,
java.lang.Class<T> paramType)
Creates the method argument value of the expected parameter type by reading from the given HttpInputMessage. |
java.lang.Object |
resolveArgument(org.springframework.core.MethodParameter parameter,
org.springframework.web.method.support.ModelAndViewContainer mavContainer,
org.springframework.web.context.request.NativeWebRequest webRequest,
org.springframework.web.bind.support.WebDataBinderFactory binderFactory)
|
boolean |
supportsParameter(org.springframework.core.MethodParameter parameter)
|
boolean |
supportsReturnType(org.springframework.core.MethodParameter returnType)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
RequestResponseBodyMethodProcessor
public RequestResponseBodyMethodProcessor(java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
supportsParameter
public boolean supportsParameter(org.springframework.core.MethodParameter parameter)
supportsReturnType
public boolean supportsReturnType(org.springframework.core.MethodParameter returnType)
resolveArgument
public java.lang.Object resolveArgument(org.springframework.core.MethodParameter parameter,
org.springframework.web.method.support.ModelAndViewContainer mavContainer,
org.springframework.web.context.request.NativeWebRequest webRequest,
org.springframework.web.bind.support.WebDataBinderFactory binderFactory)
throws java.lang.Exception
-
- Throws:
org.springframework.web.bind.MethodArgumentNotValidException
- if validation fails
org.springframework.http.converter.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
readWithMessageConverters
protected <T> java.lang.Object readWithMessageConverters(org.springframework.http.HttpInputMessage inputMessage,
org.springframework.core.MethodParameter methodParam,
java.lang.Class<T> paramType)
throws java.io.IOException,
org.springframework.web.HttpMediaTypeNotSupportedException
- Description copied from class:
AbstractMessageConverterMethodArgumentResolver
- Creates the method argument value of the expected parameter type by reading from the given HttpInputMessage.
- Overrides:
readWithMessageConverters
in class AbstractMessageConverterMethodArgumentResolver
- Type Parameters:
T
- the expected type of the argument value to be created- Parameters:
inputMessage
- the HTTP input message representing the current requestmethodParam
- the method argumentparamType
- the type of the argument value to be created
- Returns:
- the created method argument value
- Throws:
java.io.IOException
- if the reading from the request fails
org.springframework.web.HttpMediaTypeNotSupportedException
- if no suitable message converter is found
handleReturnValue
public void handleReturnValue(java.lang.Object returnValue,
org.springframework.core.MethodParameter returnType,
org.springframework.web.method.support.ModelAndViewContainer mavContainer,
org.springframework.web.context.request.NativeWebRequest webRequest)
throws java.io.IOException,
org.springframework.web.HttpMediaTypeNotAcceptableException
- Throws:
java.io.IOException
org.springframework.web.HttpMediaTypeNotAcceptableException