Package org.craftercms.commons.rest
Class HttpMessageConvertingResponseWriter
- java.lang.Object
-
- org.craftercms.commons.rest.HttpMessageConvertingResponseWriter
-
public class HttpMessageConvertingResponseWriter extends Object
Writes the response using aHttpMessageConverterchosen depending on the acceptable media types from the request (most of the code is just a copy from Spring'sAbstractMessageConverterMethodProcessor).- Author:
- avasquez
-
-
Field Summary
Fields Modifier and Type Field Description protected List<org.springframework.http.MediaType>allSupportedMediaTypesprotected org.springframework.web.accept.ContentNegotiationManagercontentNegotiationManagerstatic StringLOG_KEY_WRITTEN_WITH_MESSAGE_CONVERTERstatic org.springframework.http.MediaTypeMEDIA_TYPE_APPLICATIONprotected List<org.springframework.http.converter.HttpMessageConverter<?>>messageConverters
-
Constructor Summary
Constructors Constructor Description HttpMessageConvertingResponseWriter(org.springframework.web.accept.ContentNegotiationManager contentNegotiationManager, List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
-
Method Summary
All Methods Instance Methods Concrete Methods 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 viaMediaType.sortBySpecificity(List).protected org.springframework.http.MediaTypegetMostSpecificMediaType(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> voidwriteWithMessageConverters(T returnValue, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
-
-
-
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:
IOExceptionorg.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).
-
-