public class ParameterContentNegotiationStrategy extends AbstractMappingContentNegotiationStrategy
ContentNegotiationStrategy
that resolves a query parameter to a key
to be used to look up a media type. The default parameter name is format
.Constructor and Description |
---|
ParameterContentNegotiationStrategy(java.util.Map<java.lang.String,MediaType> mediaTypes)
Create an instance with the given map of file extensions and media types.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
getMediaTypeKey(NativeWebRequest request)
Extract a key from the request to use to look up media types.
|
java.lang.String |
getParameterName() |
protected void |
handleMatch(java.lang.String mediaTypeKey,
MediaType mediaType)
Override to provide handling when a key is successfully resolved via
MappingMediaTypeFileExtensionResolver.lookupMediaType(java.lang.String) . |
protected MediaType |
handleNoMatch(NativeWebRequest request,
java.lang.String key)
Override to provide handling when a key is not resolved via.
|
void |
setParameterName(java.lang.String parameterName)
Set the name of the parameter to use to determine requested media types.
|
resolveMediaTypeKey, resolveMediaTypes
addMapping, getAllFileExtensions, getAllMediaTypes, getMediaTypes, lookupMediaType, resolveFileExtensions
public ParameterContentNegotiationStrategy(java.util.Map<java.lang.String,MediaType> mediaTypes)
public void setParameterName(java.lang.String parameterName)
By default this is set to "format"
.
public java.lang.String getParameterName()
protected java.lang.String getMediaTypeKey(NativeWebRequest request)
AbstractMappingContentNegotiationStrategy
getMediaTypeKey
in class AbstractMappingContentNegotiationStrategy
null
if noneprotected void handleMatch(java.lang.String mediaTypeKey, MediaType mediaType)
AbstractMappingContentNegotiationStrategy
MappingMediaTypeFileExtensionResolver.lookupMediaType(java.lang.String)
.handleMatch
in class AbstractMappingContentNegotiationStrategy
protected MediaType handleNoMatch(NativeWebRequest request, java.lang.String key) throws HttpMediaTypeNotAcceptableException
AbstractMappingContentNegotiationStrategy
MappingMediaTypeFileExtensionResolver.lookupMediaType(java.lang.String)
. Sub-classes can take further steps to
determine the media type(s). If a MediaType is returned from
this method it will be added to the cache in the base class.handleNoMatch
in class AbstractMappingContentNegotiationStrategy
HttpMediaTypeNotAcceptableException