public class RequestedContentTypeResolverBuilder
extends java.lang.Object
CompositeContentTypeResolver
and configure it with
one or more RequestedContentTypeResolver
instances with build style
methods. The following table shows methods, resulting strategy instances, and
if in use by default:
Property Setter | Underlying Strategy | Default Setting |
---|---|---|
favorPathExtension |
Path Extension resolver |
On |
favorParameter |
Parameter resolver |
Off |
ignoreAcceptHeader |
Header resolver |
Off |
defaultContentType(org.springframework.http.MediaType) |
Fixed content resolver |
Not set |
defaultContentTypeResolver(org.springframework.web.reactive.accept.RequestedContentTypeResolver) |
RequestedContentTypeResolver |
Not set |
The order in which resolvers are configured is fixed. Config methods may
only turn individual resolvers on or off. If you need a custom order for any
reason simply instantiate {@link CompositeContentTypeResolver}
directly.
For the path extension and parameter resolvers you may explicitly add
mediaTypes(Map)
. This will be used to resolve path extensions or a
parameter value such as "json" to a media type such as "application/json".
The path extension strategy will also use the Java Activation framework
(JAF), if available, to resolve a path extension to a MediaType. You may
suppress
the use of JAF.
Modifier and Type | Field and Description |
---|---|
private RequestedContentTypeResolver |
contentTypeResolver |
private boolean |
favorParameter |
private boolean |
favorPathExtension |
private boolean |
ignoreAcceptHeader |
private boolean |
ignoreUnknownPathExtensions |
private java.util.Map<java.lang.String,MediaType> |
mediaTypes |
private java.lang.String |
parameterName |
private java.lang.Boolean |
useJaf |
Constructor and Description |
---|
RequestedContentTypeResolverBuilder() |
Modifier and Type | Method and Description |
---|---|
CompositeContentTypeResolver |
build() |
RequestedContentTypeResolverBuilder |
defaultContentType(MediaType contentType)
Set the default content type to use when no content type is requested.
|
RequestedContentTypeResolverBuilder |
defaultContentTypeResolver(RequestedContentTypeResolver resolver)
Set a custom
RequestedContentTypeResolver to use to determine
the content type to use when no content type is requested. |
RequestedContentTypeResolverBuilder |
favorParameter(boolean favorParameter)
Whether a request parameter ("format" by default) should be used to
determine the requested media type.
|
RequestedContentTypeResolverBuilder |
favorPathExtension(boolean favorPathExtension)
Whether the path extension in the URL path should be used to determine
the requested media type.
|
RequestedContentTypeResolverBuilder |
ignoreAcceptHeader(boolean ignoreAcceptHeader)
Whether to disable checking the 'Accept' request header.
|
RequestedContentTypeResolverBuilder |
ignoreUnknownPathExtensions(boolean ignore)
Whether to ignore requests with path extension that cannot be resolved
to any media type.
|
RequestedContentTypeResolverBuilder |
mediaType(java.lang.String key,
MediaType mediaType)
Alternative to
mediaTypes to add a single mapping. |
RequestedContentTypeResolverBuilder |
mediaTypes(java.util.Map<java.lang.String,MediaType> mediaTypes)
Add a mapping from a key, extracted from a path extension or a query
parameter, to a MediaType.
|
RequestedContentTypeResolverBuilder |
parameterName(java.lang.String parameterName)
Set the query parameter name to use when
favorParameter is on. |
RequestedContentTypeResolverBuilder |
useJaf(boolean useJaf)
When
favorPathExtension is set, this
property determines whether to allow use of JAF (Java Activation Framework)
to resolve a path extension to a specific MediaType. |
private boolean favorPathExtension
private boolean favorParameter
private boolean ignoreAcceptHeader
private java.util.Map<java.lang.String,MediaType> mediaTypes
private boolean ignoreUnknownPathExtensions
private java.lang.Boolean useJaf
private java.lang.String parameterName
private RequestedContentTypeResolver contentTypeResolver
public RequestedContentTypeResolverBuilder favorPathExtension(boolean favorPathExtension)
By default this 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 RequestedContentTypeResolverBuilder mediaTypes(java.util.Map<java.lang.String,MediaType> mediaTypes)
The path extension strategy will also try to use JAF (if present) to
resolve path extensions. To change this behavior see useJaf
.
mediaTypes
- media type mappingspublic RequestedContentTypeResolverBuilder mediaType(java.lang.String key, MediaType mediaType)
mediaTypes
to add a single mapping.public RequestedContentTypeResolverBuilder ignoreUnknownPathExtensions(boolean ignore)
false
will result in an
HttpMediaTypeNotAcceptableException
if
there is no match.
By default this is set to true
.
public RequestedContentTypeResolverBuilder useJaf(boolean useJaf)
favorPathExtension
is set, this
property determines whether to allow use of JAF (Java Activation Framework)
to resolve a path extension to a specific MediaType.
By default this is not set in which case
PathExtensionContentNegotiationStrategy
will use JAF if available.
public RequestedContentTypeResolverBuilder favorParameter(boolean favorParameter)
media type mappings
.
By default this is set to false
.
parameterName
public RequestedContentTypeResolverBuilder parameterName(java.lang.String parameterName)
favorParameter
is on.
The default parameter name is "format"
.
public RequestedContentTypeResolverBuilder ignoreAcceptHeader(boolean ignoreAcceptHeader)
By default this value is set to false
.
public RequestedContentTypeResolverBuilder defaultContentType(MediaType contentType)
By default this is not set.
public RequestedContentTypeResolverBuilder defaultContentTypeResolver(RequestedContentTypeResolver resolver)
RequestedContentTypeResolver
to use to determine
the content type to use when no content type is requested.
By default this is not set.
public CompositeContentTypeResolver build()