public class PathExtensionContentNegotiationStrategy extends AbstractMappingContentNegotiationStrategy
The presence of the Java Activation framework is detected and enabled
automatically but the setUseJaf(boolean)
property may be used to
override that setting.
Constructor and Description |
---|
PathExtensionContentNegotiationStrategy()
Create an instance without any mappings to start with.
|
PathExtensionContentNegotiationStrategy(Map<String,org.springframework.http.MediaType> mediaTypes)
Create an instance with the given extension-to-MediaType lookup.
|
Modifier and Type | Method and Description |
---|---|
org.springframework.http.MediaType |
getMediaTypeForResource(org.springframework.core.io.Resource resource)
A public method exposing the knowledge of the path extension strategy to
resolve file extensions to a MediaType in this case for a given
Resource . |
protected String |
getMediaTypeKey(org.springframework.web.context.request.NativeWebRequest webRequest)
Sub-classes must extract the key to use to look up a media type.
|
protected org.springframework.http.MediaType |
handleNoMatch(org.springframework.web.context.request.NativeWebRequest webRequest,
String extension)
Invoked when no matching media type is found in the lookup map.
|
void |
setIgnoreUnknownExtensions(boolean ignoreUnknownExtensions)
Whether to ignore requests that have a file extension that does not match
any mapped media types.
|
void |
setUseJaf(boolean useJaf)
Indicate whether to use the Java Activation Framework to map from file
extensions to media types.
|
handleMatch, resolveMediaTypes
addMapping, getAllFileExtensions, getAllMediaTypes, lookupMediaType, resolveFileExtensions
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAllFileExtensions, resolveFileExtensions
public PathExtensionContentNegotiationStrategy(Map<String,org.springframework.http.MediaType> mediaTypes)
IllegalArgumentException
- if a media type string cannot be parsedpublic PathExtensionContentNegotiationStrategy()
public void setUseJaf(boolean useJaf)
Default is true
, i.e. the Java Activation Framework is used
(if available).
public void setIgnoreUnknownExtensions(boolean ignoreUnknownExtensions)
false
will result in a
HttpMediaTypeNotAcceptableException
.
By default this is set to true
.
protected String getMediaTypeKey(org.springframework.web.context.request.NativeWebRequest webRequest)
AbstractMappingContentNegotiationStrategy
getMediaTypeKey
in class AbstractMappingContentNegotiationStrategy
null
if the key cannot be derivedprotected org.springframework.http.MediaType handleNoMatch(org.springframework.web.context.request.NativeWebRequest webRequest, String extension) throws org.springframework.web.HttpMediaTypeNotAcceptableException
AbstractMappingContentNegotiationStrategy
handleNoMatch
in class AbstractMappingContentNegotiationStrategy
org.springframework.web.HttpMediaTypeNotAcceptableException
public org.springframework.http.MediaType getMediaTypeForResource(org.springframework.core.io.Resource resource)
Resource
. The method first looks up any explicitly registered
file extensions first and then falls back on JAF if available.resource
- the resource to look upnull
.Copyright © 2006–2018 TinyGroup. All rights reserved.