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
  • Constructor Details

    • AbstractMessageConverterMethodProcessor

      protected AbstractMessageConverterMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters)
      Construct with the provided list of converters only.
    • AbstractMessageConverterMethodProcessor

      protected AbstractMessageConverterMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, @Nullable org.springframework.web.accept.ContentNegotiationManager contentNegotiationManager)
      Construct with the provided 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 of AbstractMessageConverterMethodProcessor(List, ContentNegotiationManager) with an additional requestResponseBodyAdvice list for 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 of AbstractMessageConverterMethodProcessor(List, ContentNegotiationManager, List) with additional list of ErrorResponse.Interceptors for return value handling.
      Since:
      6.2
  • Method Details

    • setErrorResponseViewResolver

      public void setErrorResponseViewResolver(@Nullable ErrorResponseViewResolver errorResponseViewResolver)
      Configure an ErrorResponseViewResolver to render problem details as views when the client prefers HTML.
      Parameters:
      errorResponseViewResolver - the resolver to use, or null to always write problem details with message converters
      Since:
      7.1
    • getErrorResponseViewResolver

      public @Nullable ErrorResponseViewResolver getErrorResponseViewResolver()
      Since:
      7.1
    • createOutputMessage

      protected org.springframework.http.server.ServletServerHttpResponse createOutputMessage(org.springframework.web.context.request.NativeWebRequest webRequest)
      Create a new HttpOutputMessage from the given NativeWebRequest.
      Parameters:
      webRequest - the web request to create an output message from
      Returns:
      the output message
    • invokeErrorResponseInterceptors

      @Deprecated(since="7.1", forRemoval=true) protected void invokeErrorResponseInterceptors(org.springframework.http.ProblemDetail detail, @Nullable org.springframework.web.ErrorResponse errorResponse)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Invoke the configured ErrorResponse.Interceptor's.
      Since:
      6.2
    • invokeErrorResponseInterceptors

      protected void invokeErrorResponseInterceptors(org.springframework.http.ProblemDetail detail, @Nullable org.springframework.web.ErrorResponse errorResponse, org.springframework.http.HttpRequest request)
      Invoke the configured ErrorResponse.Interceptor's with the current request.
      Parameters:
      detail - the ProblemDetail to be rendered
      errorResponse - the ErrorResponse, or null if there isn't one
      request - the current request
      Since:
      7.1
      See Also:
      • ErrorResponse.Interceptor.handleError(ProblemDetail, ErrorResponse, HttpRequest)
    • resolveErrorView

      protected boolean resolveErrorView(org.springframework.http.ProblemDetail problemDetail, @Nullable org.springframework.web.ErrorResponse errorResponse, org.springframework.http.HttpStatusCode status, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest)
      Render the given problem detail as a view, if an ErrorResponseViewResolver is configured, the client prefers HTML, and the resolver returns a view.

      In that case, the view, model and status are applied to the ModelAndViewContainer and the response status is set. The problem detail must not be written to the response.

      Parameters:
      problemDetail - the problem detail to render
      errorResponse - the error response the problem detail is from, if any
      status - the status to use if the view does not declare one
      mavContainer - the container for the current request
      webRequest - the current request
      Returns:
      true if the problem detail is rendered as a view, false if it should be written with message converters
      Since:
      7.1
    • 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
      Throws:
      IOException
      org.springframework.web.HttpMediaTypeNotAcceptableException
      org.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
      Write the given return type to the given output message.
      Parameters:
      value - the value to write to the output message
      returnType - the type of the value
      inputMessage - the input messages, used to inspect the Accept header
      outputMessage - the output message to write to
      Throws:
      IOException - thrown in case of I/O errors
      org.springframework.web.HttpMediaTypeNotAcceptableException - thrown when the conditions indicated by the Accept header on the request cannot be met by the message converters
      org.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 extends Resource.
    • getProducibleMediaTypes

      protected List<org.springframework.http.MediaType> getProducibleMediaTypes(jakarta.servlet.http.HttpServletRequest request, Class<?> valueClass)
      Returns the media types that can be produced.
      See Also:
    • getProducibleMediaTypes

      protected List<org.springframework.http.MediaType> getProducibleMediaTypes(jakarta.servlet.http.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