Package org.springframework.web.accept
Class ServletPathExtensionContentNegotiationStrategy
- java.lang.Object
- org.springframework.web.accept.MappingMediaTypeFileExtensionResolver
- org.springframework.web.accept.AbstractMappingContentNegotiationStrategy
- org.springframework.web.accept.PathExtensionContentNegotiationStrategy
- org.springframework.web.accept.ServletPathExtensionContentNegotiationStrategy
- All Implemented Interfaces:
ContentNegotiationStrategy,MediaTypeFileExtensionResolver
public class ServletPathExtensionContentNegotiationStrategy extends PathExtensionContentNegotiationStrategy
ExtendsPathExtensionContentNegotiationStrategythat also usesServletContext.getMimeType(String)to resolve file extensions.- Since:
- 3.2
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description ServletPathExtensionContentNegotiationStrategy(ServletContext context)Create an instance without any mappings to start with.ServletPathExtensionContentNegotiationStrategy(ServletContext servletContext, Map<String,MediaType> mediaTypes)Create an instance with the given extension-to-MediaType lookup.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MediaTypegetMediaTypeForResource(Resource resource)Extends the base classPathExtensionContentNegotiationStrategy.getMediaTypeForResource(org.springframework.core.io.Resource)with the ability to also look up through the ServletContext.protected MediaTypehandleNoMatch(NativeWebRequest webRequest, String extension)Resolve file extension viaServletContext.getMimeType(String)and also delegate to base class for a potential JAF lookup.Methods inherited from class org.springframework.web.accept.PathExtensionContentNegotiationStrategy
getMediaTypeKey, setIgnoreUnknownExtensions, setUrlPathHelper, setUseJaf
Methods inherited from class org.springframework.web.accept.AbstractMappingContentNegotiationStrategy
handleMatch, resolveMediaTypeKey, resolveMediaTypes
Methods inherited from class org.springframework.web.accept.MappingMediaTypeFileExtensionResolver
addMapping, getAllFileExtensions, getAllMediaTypes, getMediaTypes, lookupMediaType, resolveFileExtensions
Constructor Detail
ServletPathExtensionContentNegotiationStrategy
public ServletPathExtensionContentNegotiationStrategy(ServletContext context)
Create an instance without any mappings to start with. Mappings may be added later when extensions are resolved throughServletContext.getMimeType(String)or via JAF.
ServletPathExtensionContentNegotiationStrategy
public ServletPathExtensionContentNegotiationStrategy(ServletContext servletContext, Map<String,MediaType> mediaTypes)
Create an instance with the given extension-to-MediaType lookup.
Method Detail
handleNoMatch
protected MediaType handleNoMatch(NativeWebRequest webRequest, String extension) throws HttpMediaTypeNotAcceptableException
Resolve file extension viaServletContext.getMimeType(String)and also delegate to base class for a potential JAF lookup.- Overrides:
handleNoMatchin classPathExtensionContentNegotiationStrategy- Throws:
HttpMediaTypeNotAcceptableException
getMediaTypeForResource
public MediaType getMediaTypeForResource(Resource resource)
Extends the base classPathExtensionContentNegotiationStrategy.getMediaTypeForResource(org.springframework.core.io.Resource)with the ability to also look up through the ServletContext.- Overrides:
getMediaTypeForResourcein classPathExtensionContentNegotiationStrategy- Parameters:
resource- the resource to look up- Returns:
- the MediaType for the extension, or
nullif none found - Since:
- 4.3