public class ContentNegotiationConfigurer extends Object
ContentNegotiationManager
.
By default strategies for checking the extension of the request path and
the Accept
header are registered. The path extension check will perform
lookups through the ServletContext
and the Java Activation Framework
(if present) unless media types are configured.
Constructor and Description |
---|
ContentNegotiationConfigurer(ServletContext servletContext)
Class constructor with
ServletContext . |
Modifier and Type | Method and Description |
---|---|
ContentNegotiationConfigurer |
defaultContentType(MediaType defaultContentType)
Set the default content type.
|
ContentNegotiationConfigurer |
favorParameter(boolean favorParameter)
Indicate whether a request parameter should be used to determine the
requested media type with the 2nd highest priority, i.e.
|
ContentNegotiationConfigurer |
favorPathExtension(boolean favorPathExtension)
Indicate whether the extension of the request path should be used to determine
the requested media type with the highest priority.
|
protected ContentNegotiationManager |
getContentNegotiationManager()
Return the configured
ContentNegotiationManager instance |
ContentNegotiationConfigurer |
ignoreAcceptHeader(boolean ignoreAcceptHeader)
Indicate whether the HTTP
Accept header should be ignored altogether. |
ContentNegotiationConfigurer |
ignoreUnknownPathExtensions(boolean ignore)
Whether to ignore requests that have a file extension that does not match
any mapped media types.
|
ContentNegotiationConfigurer |
mediaType(String extension,
MediaType mediaType)
Add mappings from file extensions to media types.
|
ContentNegotiationConfigurer |
mediaTypes(Map<String,MediaType> mediaTypes)
Add mappings from file extensions to media types.
|
ContentNegotiationConfigurer |
parameterName(String parameterName)
Set the parameter name that can be used to determine the requested media type
if the
favorParameter(boolean) property is true . |
ContentNegotiationConfigurer |
replaceMediaTypes(Map<String,MediaType> mediaTypes)
Add mappings from file extensions to media types replacing any previous mappings.
|
ContentNegotiationConfigurer |
useJaf(boolean useJaf)
Indicate whether to use the Java Activation Framework as a fallback option
to map from file extensions to media types.
|
public ContentNegotiationConfigurer(ServletContext servletContext)
ServletContext
.public ContentNegotiationConfigurer favorPathExtension(boolean favorPathExtension)
By default this value is set to true
in which case a request
for /hotels.pdf
will be interpreted as a request for
"application/pdf"
regardless of the Accept
header.
public ContentNegotiationConfigurer mediaType(String extension, MediaType mediaType)
If this property is not set, the Java Action Framework, if available, may
still be used in conjunction with favorPathExtension(boolean)
.
public ContentNegotiationConfigurer mediaTypes(Map<String,MediaType> mediaTypes)
If this property is not set, the Java Action Framework, if available, may
still be used in conjunction with favorPathExtension(boolean)
.
public ContentNegotiationConfigurer replaceMediaTypes(Map<String,MediaType> mediaTypes)
If this property is not set, the Java Action Framework, if available, may
still be used in conjunction with favorPathExtension(boolean)
.
public ContentNegotiationConfigurer ignoreUnknownPathExtensions(boolean ignore)
false
will result in a
HttpMediaTypeNotAcceptableException
when there is no match.
By default this is set to true
.
public ContentNegotiationConfigurer useJaf(boolean useJaf)
favorPathExtension(boolean)
is set to true
.
The default value is true
.
parameterName(java.lang.String)
,
mediaTypes(Map)
public ContentNegotiationConfigurer favorParameter(boolean favorParameter)
Accept
header.
The default value is false
. If set to to true
, a request
for /hotels?format=pdf
will be interpreted as a request for
"application/pdf"
regardless of the Accept
header.
To use this option effectively you must also configure the MediaType
type mappings via mediaTypes(Map)
.
parameterName(String)
public ContentNegotiationConfigurer parameterName(String parameterName)
favorParameter(boolean)
property is true
.
The default parameter name is "format"
.
public ContentNegotiationConfigurer ignoreAcceptHeader(boolean ignoreAcceptHeader)
Accept
header should be ignored altogether.
If set the Accept
header is checked at the
3rd highest priority, i.e. after the request path extension and
possibly a request parameter if configured.
By default this value is set to false
.
public ContentNegotiationConfigurer defaultContentType(MediaType defaultContentType)
This content type will be used when neither the request path extension,
nor a request parameter, nor the Accept
header could help determine
the requested content type.
protected ContentNegotiationManager getContentNegotiationManager() throws Exception
ContentNegotiationManager
instanceException