Package org.craftercms.commons.rest
Class HttpMessageConvertingResponseWriter
java.lang.Object
org.craftercms.commons.rest.HttpMessageConvertingResponseWriter
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 -
Constructor Summary
ConstructorsConstructorDescriptionHttpMessageConvertingResponseWriter
(org.springframework.web.accept.ContentNegotiationManager contentNegotiationManager, List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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 viaMediaType.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, orMediaType.ALL
<T> void
writeWithMessageConverters
(T returnValue, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
-
Field Details
-
MEDIA_TYPE_APPLICATION
public static final org.springframework.http.MediaType MEDIA_TYPE_APPLICATION -
LOG_KEY_WRITTEN_WITH_MESSAGE_CONVERTER
- See Also:
-
contentNegotiationManager
protected org.springframework.web.accept.ContentNegotiationManager contentNegotiationManager -
messageConverters
-
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 viaMediaType.sortBySpecificity(List)
.
-