public abstract class AbstractMappingContentTypeResolver extends 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.Constructor and Description |
---|
AbstractMappingContentTypeResolver(Map<String,MediaType> mediaTypes)
Create an instance with the given map of file extensions and media types.
|
Modifier and Type | Method and Description |
---|---|
protected abstract String |
extractKey(ServerWebExchange exchange)
Extract the key to use to look up a media type from the given exchange,
e.g.
|
protected List<MediaType> |
getAllMediaTypes()
Sub-classes can use this method get all mapped media types.
|
Set<String> |
getKeys()
Return all registered keys (e.g.
|
Set<String> |
getKeysFor(MediaType mediaType)
Resolve the given media type to a list of path extensions.
|
protected MediaType |
getMediaType(String key)
Sub-classes can use this method to look up a MediaType by key.
|
Map<String,MediaType> |
getMediaTypes() |
protected void |
handleMatch(String key,
MediaType mediaType)
Override to provide handling when a key is successfully resolved via
getMediaType(String) . |
protected MediaType |
handleNoMatch(String key)
Override to provide handling when a key is not resolved via.
|
List<MediaType> |
resolveMediaTypes(ServerWebExchange exchange)
Resolve the given request to a list of requested media types.
|
List<MediaType> |
resolveMediaTypes(String key)
An overloaded resolve method with a pre-resolved lookup key.
|
protected MediaType getMediaType(String key)
key
- the key converted to lower casenull
protected List<MediaType> getAllMediaTypes()
public List<MediaType> resolveMediaTypes(ServerWebExchange exchange) throws NotAcceptableStatusException
RequestedContentTypeResolver
resolveMediaTypes
in interface RequestedContentTypeResolver
exchange
- the current exchangeNotAcceptableStatusException
- if the requested media types is invalidpublic List<MediaType> resolveMediaTypes(String key) throws NotAcceptableStatusException
key
- the key for looking up media typesNotAcceptableStatusException
protected abstract String extractKey(ServerWebExchange exchange)
null
protected void handleMatch(String key, MediaType mediaType)
getMediaType(String)
.protected MediaType handleNoMatch(String key) throws NotAcceptableStatusException
getMediaType(String)
. If a MediaType is returned from
this method it will be added to the mappings.NotAcceptableStatusException
public Set<String> getKeysFor(MediaType mediaType)
MappingContentTypeResolver
getKeysFor
in interface MappingContentTypeResolver
mediaType
- the media type to resolvenull
public Set<String> getKeys()
MappingContentTypeResolver
getKeys
in interface MappingContentTypeResolver
null