public abstract class AbstractMessageConverterMethodProcessor extends AbstractMessageConverterMethodArgumentResolver implements HandlerMethodReturnValueHandler
AbstractMessageConverterMethodArgumentResolver
with the ability to handle method
return values by writing to the response with HttpMessageConverters
.Modifier and Type | Field and Description |
---|---|
private static java.util.List<MediaType> |
ALL_APPLICATION_MEDIA_TYPES |
private ContentNegotiationManager |
contentNegotiationManager |
private static UrlPathHelper |
decodingUrlPathHelper |
private PathExtensionContentNegotiationStrategy |
pathStrategy |
private static UrlPathHelper |
rawUrlPathHelper |
private static java.lang.reflect.Type |
RESOURCE_REGION_LIST_TYPE |
private java.util.Set<java.lang.String> |
safeExtensions |
private static java.util.Set<java.lang.String> |
WHITELISTED_EXTENSIONS |
private static java.util.Set<java.lang.String> |
WHITELISTED_MEDIA_BASE_TYPES |
allSupportedMediaTypes, logger, messageConverters
Modifier | Constructor and Description |
---|---|
protected |
AbstractMessageConverterMethodProcessor(java.util.List<HttpMessageConverter<?>> converters)
Constructor with list of converters only.
|
protected |
AbstractMessageConverterMethodProcessor(java.util.List<HttpMessageConverter<?>> converters,
ContentNegotiationManager contentNegotiationManager)
Constructor with list of converters and ContentNegotiationManager.
|
protected |
AbstractMessageConverterMethodProcessor(java.util.List<HttpMessageConverter<?>> converters,
ContentNegotiationManager manager,
java.util.List<java.lang.Object> requestResponseBodyAdvice)
Constructor with list of converters and ContentNegotiationManager as well
as request/response body advice instances.
|
Modifier and Type | Method and Description |
---|---|
private void |
addContentDispositionHeader(ServletServerHttpRequest request,
ServletServerHttpResponse response)
Check if the path has a file extension and whether the extension is
either
whitelisted or explicitly
registered . |
protected ServletServerHttpResponse |
createOutputMessage(NativeWebRequest webRequest)
Creates a new
HttpOutputMessage from the given NativeWebRequest . |
private java.util.List<MediaType> |
getAcceptableMediaTypes(HttpServletRequest request) |
private java.lang.reflect.Type |
getGenericType(MethodParameter returnType)
Return the generic type of the
returnType (or of the nested type
if it is an HttpEntity ). |
private MediaType |
getMostSpecificMediaType(MediaType acceptType,
MediaType produceType)
Return the more specific of the acceptable and the producible media types
with the q-value of the former.
|
protected java.util.List<MediaType> |
getProducibleMediaTypes(HttpServletRequest request,
java.lang.Class<?> valueClass)
Returns the media types that can be produced.
|
protected java.util.List<MediaType> |
getProducibleMediaTypes(HttpServletRequest request,
java.lang.Class<?> valueClass,
java.lang.reflect.Type targetType)
Returns the media types that can be produced.
|
protected java.lang.Class<?> |
getReturnValueType(java.lang.Object value,
MethodParameter returnType)
Return the type of the value to be written to the response.
|
private static PathExtensionContentNegotiationStrategy |
initPathStrategy(ContentNegotiationManager manager) |
protected boolean |
isResourceType(java.lang.Object value,
MethodParameter returnType)
Return whether the returned value or the declared return type extends
Resource . |
private boolean |
safeExtension(HttpServletRequest request,
java.lang.String extension) |
private boolean |
safeMediaType(MediaType mediaType) |
private boolean |
safeMediaTypesForExtension(NativeWebRequest request,
java.lang.String extension) |
protected <T> void |
writeWithMessageConverters(T value,
MethodParameter returnType,
NativeWebRequest webRequest)
Writes the given return value to the given web request.
|
protected <T> void |
writeWithMessageConverters(T value,
MethodParameter returnType,
ServletServerHttpRequest inputMessage,
ServletServerHttpResponse outputMessage)
Writes the given return type to the given output message.
|
adaptArgumentIfNecessary, createInputMessage, getAdvice, isBindExceptionRequired, readWithMessageConverters, readWithMessageConverters, validateIfApplicable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handleReturnValue, supportsReturnType
resolveArgument, supportsParameter
private static final java.util.Set<java.lang.String> WHITELISTED_EXTENSIONS
private static final java.util.Set<java.lang.String> WHITELISTED_MEDIA_BASE_TYPES
private static final java.util.List<MediaType> ALL_APPLICATION_MEDIA_TYPES
private static final java.lang.reflect.Type RESOURCE_REGION_LIST_TYPE
private static final UrlPathHelper decodingUrlPathHelper
private static final UrlPathHelper rawUrlPathHelper
private final ContentNegotiationManager contentNegotiationManager
private final PathExtensionContentNegotiationStrategy pathStrategy
private final java.util.Set<java.lang.String> safeExtensions
protected AbstractMessageConverterMethodProcessor(java.util.List<HttpMessageConverter<?>> converters)
protected AbstractMessageConverterMethodProcessor(java.util.List<HttpMessageConverter<?>> converters, @Nullable ContentNegotiationManager contentNegotiationManager)
protected AbstractMessageConverterMethodProcessor(java.util.List<HttpMessageConverter<?>> converters, @Nullable ContentNegotiationManager manager, @Nullable java.util.List<java.lang.Object> requestResponseBodyAdvice)
private static PathExtensionContentNegotiationStrategy initPathStrategy(ContentNegotiationManager manager)
protected ServletServerHttpResponse createOutputMessage(NativeWebRequest webRequest)
HttpOutputMessage
from the given NativeWebRequest
.webRequest
- the web request to create an output message fromprotected <T> void writeWithMessageConverters(T value, MethodParameter returnType, NativeWebRequest webRequest) throws java.io.IOException, HttpMediaTypeNotAcceptableException, HttpMessageNotWritableException
writeWithMessageConverters(Object, MethodParameter, ServletServerHttpRequest, ServletServerHttpResponse)
java.io.IOException
HttpMediaTypeNotAcceptableException
HttpMessageNotWritableException
protected <T> void writeWithMessageConverters(@Nullable T value, MethodParameter returnType, ServletServerHttpRequest inputMessage, ServletServerHttpResponse outputMessage) throws java.io.IOException, HttpMediaTypeNotAcceptableException, HttpMessageNotWritableException
value
- the value to write to the output messagereturnType
- the type of the valueinputMessage
- the input messages. Used to inspect the Accept
header.outputMessage
- the output message to write tojava.io.IOException
- thrown in case of I/O errorsHttpMediaTypeNotAcceptableException
- thrown when the conditions indicated
by the Accept
header on the request cannot be met by the message convertersHttpMessageNotWritableException
protected java.lang.Class<?> getReturnValueType(@Nullable java.lang.Object value, MethodParameter returnType)
ResponseEntity<T>
).protected boolean isResourceType(@Nullable java.lang.Object value, MethodParameter returnType)
Resource
.private java.lang.reflect.Type getGenericType(MethodParameter returnType)
returnType
(or of the nested type
if it is an HttpEntity
).protected java.util.List<MediaType> getProducibleMediaTypes(HttpServletRequest request, java.lang.Class<?> valueClass)
protected java.util.List<MediaType> getProducibleMediaTypes(HttpServletRequest request, java.lang.Class<?> valueClass, @Nullable java.lang.reflect.Type targetType)
MediaType.ALL
private java.util.List<MediaType> getAcceptableMediaTypes(HttpServletRequest request) throws HttpMediaTypeNotAcceptableException
private MediaType getMostSpecificMediaType(MediaType acceptType, MediaType produceType)
private void addContentDispositionHeader(ServletServerHttpRequest request, ServletServerHttpResponse response)
whitelisted
or explicitly
registered
.
If not, and the status is in the 2xx range, a 'Content-Disposition'
header with a safe attachment file name ("f.txt") is added to prevent
RFD exploits.private boolean safeExtension(HttpServletRequest request, @Nullable java.lang.String extension)
private boolean safeMediaTypesForExtension(NativeWebRequest request, java.lang.String extension)
private boolean safeMediaType(MediaType mediaType)