Class HttpMessageConvertingResponseWriter

java.lang.Object
org.craftercms.commons.rest.HttpMessageConvertingResponseWriter

public class HttpMessageConvertingResponseWriter extends Object
Writes the response using a HttpMessageConverter chosen depending on the acceptable media types from the request (most of the code is just a copy from Spring's AbstractMessageConverterMethodProcessor).
Author:
avasquez
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected List<org.springframework.http.MediaType>
     
    protected org.springframework.web.accept.ContentNegotiationManager
     
    static final String
     
    static final org.springframework.http.MediaType
     
    protected List<org.springframework.http.converter.HttpMessageConverter<?>>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    HttpMessageConvertingResponseWriter(org.springframework.web.accept.ContentNegotiationManager contentNegotiationManager, List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected List<org.springframework.http.MediaType>
    getAcceptableMediaTypes(javax.servlet.http.HttpServletRequest request)
    Return the acceptable media types from the request.
    protected List<org.springframework.http.MediaType>
    getAllSupportedMediaTypes(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
    Return the media types supported by all provided message converters sorted by specificity via MediaType.sortBySpecificity(List).
    protected org.springframework.http.MediaType
    getMostSpecificMediaType(org.springframework.http.MediaType acceptType, org.springframework.http.MediaType produceType)
    Return the more specific of the acceptable and the producible media types with the q-value of the former.
    protected List<org.springframework.http.MediaType>
    getProducibleMediaTypes(Class<?> returnValueClass)
    Returns the media types that can be produced: Media types of configured converters that can write the specific return value, or MediaType.ALL
    <T> void
    writeWithMessageConverters(T returnValue, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MEDIA_TYPE_APPLICATION

      public static final org.springframework.http.MediaType MEDIA_TYPE_APPLICATION
    • LOG_KEY_WRITTEN_WITH_MESSAGE_CONVERTER

      public static final String LOG_KEY_WRITTEN_WITH_MESSAGE_CONVERTER
      See Also:
    • contentNegotiationManager

      protected org.springframework.web.accept.ContentNegotiationManager contentNegotiationManager
    • messageConverters

      protected List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters
    • allSupportedMediaTypes

      protected List<org.springframework.http.MediaType> allSupportedMediaTypes
  • Constructor Details

    • HttpMessageConvertingResponseWriter

      @ConstructorProperties({"contentNegotiationManager","messageConverters"}) public HttpMessageConvertingResponseWriter(org.springframework.web.accept.ContentNegotiationManager contentNegotiationManager, List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
  • Method Details

    • writeWithMessageConverters

      public <T> void writeWithMessageConverters(T returnValue, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, org.springframework.web.HttpMediaTypeNotAcceptableException
      Throws:
      IOException
      org.springframework.web.HttpMediaTypeNotAcceptableException
    • getProducibleMediaTypes

      protected List<org.springframework.http.MediaType> getProducibleMediaTypes(Class<?> returnValueClass)
      Returns the media types that can be produced:
      • Media types of configured converters that can write the specific return value, or
      • MediaType.ALL
    • getAcceptableMediaTypes

      protected List<org.springframework.http.MediaType> getAcceptableMediaTypes(javax.servlet.http.HttpServletRequest request) throws org.springframework.web.HttpMediaTypeNotAcceptableException
      Return the acceptable media types from the request.
      Throws:
      org.springframework.web.HttpMediaTypeNotAcceptableException
    • getMostSpecificMediaType

      protected org.springframework.http.MediaType getMostSpecificMediaType(org.springframework.http.MediaType acceptType, org.springframework.http.MediaType produceType)
      Return the more specific of the acceptable and the producible media types with the q-value of the former.
    • getAllSupportedMediaTypes

      protected List<org.springframework.http.MediaType> getAllSupportedMediaTypes(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
      Return the media types supported by all provided message converters sorted by specificity via MediaType.sortBySpecificity(List).