Class AbstractMessageConverterMethodProcessor
java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor
- All Implemented Interfaces:
org.springframework.web.method.support.HandlerMethodArgumentResolver,org.springframework.web.method.support.HandlerMethodReturnValueHandler
- Direct Known Subclasses:
HttpEntityMethodProcessor,RequestResponseBodyMethodProcessor
public abstract class AbstractMessageConverterMethodProcessor
extends AbstractMessageConverterMethodArgumentResolver
implements org.springframework.web.method.support.HandlerMethodReturnValueHandler
Extends
AbstractMessageConverterMethodArgumentResolver with the ability to handle method
return values by writing to the response with HttpMessageConverters.- Since:
- 3.1
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Brian Clozel, Juergen Hoeller, Sebastien Deleuze
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
AbstractMessageConverterMethodArgumentResolver.ConverterType -
Field Summary
Fields inherited from class org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
logger, messageConverters -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractMessageConverterMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters) Constructor with list of converters only.protectedAbstractMessageConverterMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, org.springframework.web.accept.ContentNegotiationManager contentNegotiationManager) Constructor with list of converters and ContentNegotiationManager.protectedAbstractMessageConverterMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, org.springframework.web.accept.ContentNegotiationManager manager, List<Object> requestResponseBodyAdvice) Variant ofAbstractMessageConverterMethodProcessor(List)with an additionalContentNegotiationManagerfor return value handling.protectedAbstractMessageConverterMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, org.springframework.web.accept.ContentNegotiationManager manager, List<Object> requestResponseBodyAdvice, List<org.springframework.web.ErrorResponse.Interceptor> interceptors) Variant ofAbstractMessageConverterMethodProcessor(List, ContentNegotiationManager, List)with additional list ofErrorResponse.Interceptors for return value handling. -
Method Summary
Modifier and TypeMethodDescriptionprotected org.springframework.http.server.ServletServerHttpResponsecreateOutputMessage(org.springframework.web.context.request.NativeWebRequest webRequest) Creates a newHttpOutputMessagefrom the givenNativeWebRequest.protected List<org.springframework.http.MediaType>getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass) Returns the media types that can be produced.protected List<org.springframework.http.MediaType>getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass, Type targetType) Returns the media types that can be produced.protected Class<?>getReturnValueType(Object value, org.springframework.core.MethodParameter returnType) Return the type of the value to be written to the response.protected voidinvokeErrorResponseInterceptors(org.springframework.http.ProblemDetail detail, org.springframework.web.ErrorResponse errorResponse) Invoke the configuredErrorResponse.Interceptor's.protected booleanisResourceType(Object value, org.springframework.core.MethodParameter returnType) Return whether the returned value or the declared return type extendsResource.protected <T> voidwriteWithMessageConverters(T value, org.springframework.core.MethodParameter returnType, org.springframework.http.server.ServletServerHttpRequest inputMessage, org.springframework.http.server.ServletServerHttpResponse outputMessage) Writes the given return type to the given output message.protected <T> voidwriteWithMessageConverters(T value, org.springframework.core.MethodParameter returnType, org.springframework.web.context.request.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, getNestedTypeIfNeeded, getSupportedMediaTypes, isBindExceptionRequired, readWithMessageConverters, readWithMessageConverters, validateIfApplicableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.web.method.support.HandlerMethodArgumentResolver
resolveArgument, supportsParameterMethods inherited from interface org.springframework.web.method.support.HandlerMethodReturnValueHandler
handleReturnValue, supportsReturnType
-
Constructor Details
-
AbstractMessageConverterMethodProcessor
protected AbstractMessageConverterMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters) Constructor with list of converters only. -
AbstractMessageConverterMethodProcessor
protected AbstractMessageConverterMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, @Nullable org.springframework.web.accept.ContentNegotiationManager contentNegotiationManager) Constructor with list of converters and ContentNegotiationManager. -
AbstractMessageConverterMethodProcessor
protected AbstractMessageConverterMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, @Nullable org.springframework.web.accept.ContentNegotiationManager manager, @Nullable List<Object> requestResponseBodyAdvice) Variant ofAbstractMessageConverterMethodProcessor(List)with an additionalContentNegotiationManagerfor return value handling. -
AbstractMessageConverterMethodProcessor
protected AbstractMessageConverterMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, @Nullable org.springframework.web.accept.ContentNegotiationManager manager, @Nullable List<Object> requestResponseBodyAdvice, List<org.springframework.web.ErrorResponse.Interceptor> interceptors) Variant ofAbstractMessageConverterMethodProcessor(List, ContentNegotiationManager, List)with additional list ofErrorResponse.Interceptors for return value handling.- Since:
- 6.2
-
-
Method Details
-
createOutputMessage
protected org.springframework.http.server.ServletServerHttpResponse createOutputMessage(org.springframework.web.context.request.NativeWebRequest webRequest) Creates a newHttpOutputMessagefrom the givenNativeWebRequest.- Parameters:
webRequest- the web request to create an output message from- Returns:
- the output message
-
invokeErrorResponseInterceptors
protected void invokeErrorResponseInterceptors(org.springframework.http.ProblemDetail detail, @Nullable org.springframework.web.ErrorResponse errorResponse) Invoke the configuredErrorResponse.Interceptor's.- Since:
- 6.2
-
writeWithMessageConverters
protected <T> void writeWithMessageConverters(T value, org.springframework.core.MethodParameter returnType, org.springframework.web.context.request.NativeWebRequest webRequest) throws IOException, org.springframework.web.HttpMediaTypeNotAcceptableException, org.springframework.http.converter.HttpMessageNotWritableException Writes the given return value to the given web request. Delegates towriteWithMessageConverters(Object, MethodParameter, ServletServerHttpRequest, ServletServerHttpResponse)- Throws:
IOExceptionorg.springframework.web.HttpMediaTypeNotAcceptableExceptionorg.springframework.http.converter.HttpMessageNotWritableException
-
writeWithMessageConverters
protected <T> void writeWithMessageConverters(@Nullable T value, org.springframework.core.MethodParameter returnType, org.springframework.http.server.ServletServerHttpRequest inputMessage, org.springframework.http.server.ServletServerHttpResponse outputMessage) throws IOException, org.springframework.web.HttpMediaTypeNotAcceptableException, org.springframework.http.converter.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 theAcceptheader.outputMessage- the output message to write to- Throws:
IOException- thrown in case of I/O errorsorg.springframework.web.HttpMediaTypeNotAcceptableException- thrown when the conditions indicated by theAcceptheader on the request cannot be met by the message convertersorg.springframework.http.converter.HttpMessageNotWritableException- thrown if a given message cannot be written by a converter, or if the content-type chosen by the server has no compatible converter.
-
getReturnValueType
protected Class<?> getReturnValueType(@Nullable Object value, org.springframework.core.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 (for example,ResponseEntity<T>). -
isResourceType
protected boolean isResourceType(@Nullable Object value, org.springframework.core.MethodParameter returnType) Return whether the returned value or the declared return type extendsResource. -
getProducibleMediaTypes
protected List<org.springframework.http.MediaType> getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass) Returns the media types that can be produced. -
getProducibleMediaTypes
protected List<org.springframework.http.MediaType> getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass, @Nullable Type targetType) Returns the media types that can be produced. The resulting media types are:- 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
-