Class 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 Detail

      • 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:
        Constant Field Values
      • 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 Detail

      • HttpMessageConvertingResponseWriter

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

      • 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).