public abstract class AbstractMappingContentTypeResolver extends java.lang.Object implements MappingContentTypeResolver
MappingContentTypeResolver
implementations.
Maintains the actual mappings and pre-implements the overall algorithm with
sub-classes left to provide a way to extract the lookup key (e.g. file
extension, query parameter, etc) for a given exchange.Modifier and Type | Field and Description |
---|---|
private MultiValueMap<MediaType,java.lang.String> |
keyLookup
Reverse lookup for keys associated with a media type
|
private java.util.Map<java.lang.String,MediaType> |
mediaTypeLookup
Primary lookup for media types by key (e.g.
|
Constructor and Description |
---|
AbstractMappingContentTypeResolver(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 abstract java.lang.String |
extractKey(ServerWebExchange exchange)
Extract the key to use to look up a media type from the given exchange,
e.g.
|
protected java.util.List<MediaType> |
getAllMediaTypes()
Sub-classes can use this method get all mapped media types.
|
java.util.Set<java.lang.String> |
getKeys()
Return all registered keys (e.g.
|
java.util.Set<java.lang.String> |
getKeysFor(MediaType mediaType)
Resolve the given media type to a list of path extensions.
|
protected MediaType |
getMediaType(java.lang.String key)
Sub-classes can use this method to look up a MediaType by key.
|
java.util.Map<java.lang.String,MediaType> |
getMediaTypes() |
protected void |
handleMatch(java.lang.String key,
MediaType mediaType)
Override to provide handling when a key is successfully resolved via
getMediaType(String) . |
protected MediaType |
handleNoMatch(java.lang.String key)
Override to provide handling when a key is not resolved via.
|
java.util.List<MediaType> |
resolveMediaTypes(ServerWebExchange exchange)
Resolve the given request to a list of requested media types.
|
java.util.List<MediaType> |
resolveMediaTypes(java.lang.String key)
An overloaded resolve method with a pre-resolved lookup key.
|
private final java.util.Map<java.lang.String,MediaType> mediaTypeLookup
private final MultiValueMap<MediaType,java.lang.String> keyLookup
public AbstractMappingContentTypeResolver(java.util.Map<java.lang.String,MediaType> mediaTypes)
public java.util.Map<java.lang.String,MediaType> getMediaTypes()
protected MediaType getMediaType(java.lang.String key)
key
- the key converted to lower casenull
protected java.util.List<MediaType> getAllMediaTypes()
public java.util.List<MediaType> resolveMediaTypes(ServerWebExchange exchange) throws NotAcceptableStatusException
RequestedContentTypeResolver
resolveMediaTypes
in interface RequestedContentTypeResolver
exchange
- the current exchangeNotAcceptableStatusException
- if the requested media types is invalidpublic java.util.List<MediaType> resolveMediaTypes(java.lang.String key) throws NotAcceptableStatusException
key
- the key for looking up media typesNotAcceptableStatusException
protected abstract java.lang.String extractKey(ServerWebExchange exchange)
null
protected void handleMatch(java.lang.String key, MediaType mediaType)
getMediaType(String)
.protected MediaType handleNoMatch(java.lang.String key) throws NotAcceptableStatusException
getMediaType(String)
. If a MediaType is returned from
this method it will be added to the mappings.NotAcceptableStatusException
public java.util.Set<java.lang.String> getKeysFor(MediaType mediaType)
MappingContentTypeResolver
getKeysFor
in interface MappingContentTypeResolver
mediaType
- the media type to resolvenull
public java.util.Set<java.lang.String> getKeys()
MappingContentTypeResolver
getKeys
in interface MappingContentTypeResolver
null