Class AbstractMessageConverterMethodProcessor
- java.lang.Object
- org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
- org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor
- All Implemented Interfaces:
HandlerMethodArgumentResolver
,HandlerMethodReturnValueHandler
- Direct Known Subclasses:
HttpEntityMethodProcessor
,RequestResponseBodyMethodProcessor
public abstract class AbstractMessageConverterMethodProcessor extends AbstractMessageConverterMethodArgumentResolver implements HandlerMethodReturnValueHandler
ExtendsAbstractMessageConverterMethodArgumentResolver
with the ability to handle method return values by writing to the response withHttpMessageConverter
s.- Since:
- 3.1
- Author:
- Arjen Poutsma, Rossen Stoyanchev
Field Summary
Fields inherited from class org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
allSupportedMediaTypes, logger, messageConverters
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractMessageConverterMethodProcessor(List<HttpMessageConverter<?>> converters)
Constructor with list of converters only.protected
AbstractMessageConverterMethodProcessor(List<HttpMessageConverter<?>> converters, ContentNegotiationManager contentNegotiationManager)
Constructor with list of converters and ContentNegotiationManager.protected
AbstractMessageConverterMethodProcessor(List<HttpMessageConverter<?>> converters, ContentNegotiationManager manager, List<Object> requestResponseBodyAdvice)
Constructor with list of converters and ContentNegotiationManager as well as request/response body advice instances.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ServletServerHttpResponse
createOutputMessage(NativeWebRequest webRequest)
Creates a newHttpOutputMessage
from the givenNativeWebRequest
.protected List<MediaType>
getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass)
protected List<MediaType>
getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass, Type declaredType)
Returns the media types that can be produced: The producible media types specified in the request mappings, or Media types of configured converters that can write the specific return value, orMediaType.ALL
protected Class<?>
getReturnValueType(Object value, MethodParameter returnType)
Return the type of the value to be written to the response.protected <T> void
writeWithMessageConverters(T value, MethodParameter returnType, ServletServerHttpRequest inputMessage, ServletServerHttpResponse outputMessage)
Writes the given return type to the given output message.protected <T> void
writeWithMessageConverters(T value, MethodParameter returnType, NativeWebRequest webRequest)
Writes the given return value to the given web request.Methods inherited from class org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
adaptArgumentIfNecessary, createInputMessage, getAdvice, isBindExceptionRequired, readWithMessageConverters, readWithMessageConverters, validateIfApplicable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.web.method.support.HandlerMethodArgumentResolver
resolveArgument, supportsParameter
Methods inherited from interface org.springframework.web.method.support.HandlerMethodReturnValueHandler
handleReturnValue, supportsReturnType
Constructor Detail
AbstractMessageConverterMethodProcessor
protected AbstractMessageConverterMethodProcessor(List<HttpMessageConverter<?>> converters)
Constructor with list of converters only.
AbstractMessageConverterMethodProcessor
protected AbstractMessageConverterMethodProcessor(List<HttpMessageConverter<?>> converters, ContentNegotiationManager contentNegotiationManager)
Constructor with list of converters and ContentNegotiationManager.
AbstractMessageConverterMethodProcessor
protected AbstractMessageConverterMethodProcessor(List<HttpMessageConverter<?>> converters, ContentNegotiationManager manager, List<Object> requestResponseBodyAdvice)
Constructor with list of converters and ContentNegotiationManager as well as request/response body advice instances.
Method Detail
createOutputMessage
protected ServletServerHttpResponse createOutputMessage(NativeWebRequest webRequest)
Creates a newHttpOutputMessage
from the givenNativeWebRequest
.- Parameters:
webRequest
- the web request to create an output message from- Returns:
- the output message
writeWithMessageConverters
protected <T> void writeWithMessageConverters(T value, MethodParameter returnType, NativeWebRequest webRequest) throws IOException, HttpMediaTypeNotAcceptableException, HttpMessageNotWritableException
Writes the given return value to the given web request. Delegates towriteWithMessageConverters(Object, MethodParameter, ServletServerHttpRequest, ServletServerHttpResponse)
writeWithMessageConverters
protected <T> void writeWithMessageConverters(T value, MethodParameter returnType, ServletServerHttpRequest inputMessage, ServletServerHttpResponse outputMessage) throws IOException, HttpMediaTypeNotAcceptableException, HttpMessageNotWritableException
Writes the given return type to the given output message.- Parameters:
value
- the value to write to the output messagereturnType
- the type of the valueinputMessage
- the input messages. Used to inspect theAccept
header.outputMessage
- the output message to write to- Throws:
IOException
- thrown in case of I/O errorsHttpMediaTypeNotAcceptableException
- thrown when the conditions indicated by theAccept
header on the request cannot be met by the message convertersHttpMessageNotWritableException
getReturnValueType
protected Class<?> getReturnValueType(Object value, MethodParameter returnType)
Return the type of the value to be written to the response. Typically this is a simple check via getClass on the value but if the value is null, then the return type needs to be examined possibly including generic type determination (e.g.ResponseEntity<T>
).
getProducibleMediaTypes
protected List<MediaType> getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass)
getProducibleMediaTypes
protected List<MediaType> getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass, Type declaredType)
Returns the media types that can be produced:- The producible media types specified in the request mappings, or
- Media types of configured converters that can write the specific return value, or
MediaType.ALL
- Since:
- 4.2