spring-framework / org.springframework.web.accept

Package org.springframework.web.accept

Types

ContentNegotiationManager

open class ContentNegotiationManager : ContentNegotiationStrategy, MediaTypeFileExtensionResolver

Central class to determine requested MediaType for a request. This is done by delegating to a list of configured ContentNegotiationStrategy instances.

Also provides methods to look up file extensions for a media type. This is done by delegating to the list of configured MediaTypeFileExtensionResolver instances.

ContentNegotiationManagerFactoryBean

open class ContentNegotiationManagerFactoryBean : FactoryBean<ContentNegotiationManager>, ServletContextAware, InitializingBean

Factory to create a ContentNegotiationManager and configure it with one or more ContentNegotiationStrategy instances.

As of 5.0 you can set the exact strategies to use via #setStrategies(List).

As an alternative you can also rely on the set of defaults described below which can be turned on or off or customized through the methods of this builder:

Property Setter Underlying Strategy Default Setting #setFavorPathExtension PathExtensionContentNegotiationStrategy On favorParameter ParameterContentNegotiationStrategy Off ignoreAcceptHeader HeaderContentNegotiationStrategy On defaultContentType FixedContentNegotiationStrategy Not set defaultContentTypeStrategy ContentNegotiationStrategy Not set Note: if you must use URL-based content type resolution, the use of a query parameter is simpler and preferable to the use of a path extension since the latter can cause issues with URI variables, path parameters, and URI decoding. Consider setting #setFavorPathExtension to false or otherwise set the strategies to use explicitly via #setStrategies(List).

FixedContentNegotiationStrategy

open class FixedContentNegotiationStrategy : ContentNegotiationStrategy

A ContentNegotiationStrategy that returns a fixed content type.

HeaderContentNegotiationStrategy

open class HeaderContentNegotiationStrategy : ContentNegotiationStrategy

A ContentNegotiationStrategy that checks the 'Accept' request header.

ParameterContentNegotiationStrategy

open class ParameterContentNegotiationStrategy : AbstractMappingContentNegotiationStrategy

Strategy that resolves the requested content type from a query parameter. The default query parameter name is "format".

You can register static mappings between keys (i.e. the expected value of the query parameter) and MediaType's via #addMapping(String, MediaType). As of 5.0 this strategy also supports dynamic lookups of keys via org.springframework.http.MediaTypeFactory#getMediaType.

PathExtensionContentNegotiationStrategy

open class PathExtensionContentNegotiationStrategy : AbstractMappingContentNegotiationStrategy

A ContentNegotiationStrategy that resolves the file extension in the request path to a key to be used to look up a media type.

If the file extension is not found in the explicit registrations provided to the constructor, the MediaTypeFactory is used as a fallback mechanism.

ServletPathExtensionContentNegotiationStrategy

open class ServletPathExtensionContentNegotiationStrategy : PathExtensionContentNegotiationStrategy

Extends PathExtensionContentNegotiationStrategy that also uses ServletContext#getMimeType(String) to resolve file extensions.