Package org.springframework.web.accept
Class ContentNegotiationManager
java.lang.Object
org.springframework.web.accept.ContentNegotiationManager
- All Implemented Interfaces:
- ContentNegotiationStrategy,- MediaTypeFileExtensionResolver
public class ContentNegotiationManager
extends Object
implements ContentNegotiationStrategy, MediaTypeFileExtensionResolver
Central class to determine requested media types
 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.
- Since:
- 3.2
- Author:
- Rossen Stoyanchev, Juergen Hoeller
- 
Field SummaryFields inherited from interface org.springframework.web.accept.ContentNegotiationStrategyMEDIA_TYPE_ALL_LIST
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a default instance with aHeaderContentNegotiationStrategy.A collection-based alternative toContentNegotiationManager(ContentNegotiationStrategy...).ContentNegotiationManager(ContentNegotiationStrategy... strategies) Create an instance with the given list ofContentNegotiationStrategystrategies each of which may also be an instance ofMediaTypeFileExtensionResolver.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddFileExtensionResolvers(MediaTypeFileExtensionResolver... resolvers) Register moreMediaTypeFileExtensionResolverinstances in addition to those detected at construction.Get all registered file extensions.Return all registered lookup key to media type mappings by iteratingMediaTypeFileExtensionResolvers.Return the configured content negotiation strategies.<T extends ContentNegotiationStrategy>
 TgetStrategy(Class<T> strategyType) Find aContentNegotiationStrategyof the given type.resolveFileExtensions(MediaType mediaType) Resolve the given media type to a list of file extensions.resolveMediaTypes(NativeWebRequest request) Resolve the given request to a list of media types.
- 
Constructor Details- 
ContentNegotiationManagerCreate an instance with the given list ofContentNegotiationStrategystrategies each of which may also be an instance ofMediaTypeFileExtensionResolver.- Parameters:
- strategies- the strategies to use
 
- 
ContentNegotiationManagerA collection-based alternative toContentNegotiationManager(ContentNegotiationStrategy...).- Parameters:
- strategies- the strategies to use
- Since:
- 3.2.2
 
- 
ContentNegotiationManagerpublic ContentNegotiationManager()Create a default instance with aHeaderContentNegotiationStrategy.
 
- 
- 
Method Details- 
getStrategiesReturn the configured content negotiation strategies.- Since:
- 3.2.16
 
- 
getStrategyFind aContentNegotiationStrategyof the given type.- Parameters:
- strategyType- the strategy type
- Returns:
- the first matching strategy, or nullif none
- Since:
- 4.3
 
- 
addFileExtensionResolversRegister moreMediaTypeFileExtensionResolverinstances in addition to those detected at construction.- Parameters:
- resolvers- the resolvers to add
 
- 
resolveMediaTypespublic List<MediaType> resolveMediaTypes(NativeWebRequest request) throws HttpMediaTypeNotAcceptableException Description copied from interface:ContentNegotiationStrategyResolve the given request to a list of media types. The returned list is ordered by specificity first and by quality parameter second.- Specified by:
- resolveMediaTypesin interface- ContentNegotiationStrategy
- Parameters:
- request- the current request
- Returns:
- the requested media types, or ContentNegotiationStrategy.MEDIA_TYPE_ALL_LISTif none were requested.
- Throws:
- HttpMediaTypeNotAcceptableException- if the requested media types cannot be parsed
 
- 
resolveFileExtensionsDescription copied from interface:MediaTypeFileExtensionResolverResolve the given media type to a list of file extensions.- Specified by:
- resolveFileExtensionsin interface- MediaTypeFileExtensionResolver
- Parameters:
- mediaType- the media type to resolve
- Returns:
- a list of extensions or an empty list (never null)
 
- 
getAllFileExtensionsGet all registered file extensions.At startup this method returns extensions explicitly registered with either PathExtensionContentNegotiationStrategyorParameterContentNegotiationStrategy. At runtime if there is a "path extension" strategy and itsuseRegisteredExtensionsOnlyproperty is set to "false", the list of extensions may increase as file extensions are resolved viaMediaTypeFactoryand cached.- Specified by:
- getAllFileExtensionsin interface- MediaTypeFileExtensionResolver
- Returns:
- a list of extensions or an empty list (never null)
 
- 
getMediaTypeMappingsReturn all registered lookup key to media type mappings by iteratingMediaTypeFileExtensionResolvers.- Since:
- 5.2.4
 
 
-