Top Description Fields Constructors Methods
org.springframework.web.accept

public Class ServletPathExtensionContentNegotiationStrategy

extends PathExtensionContentNegotiationStrategy
Class Inheritance
Annotations
@Deprecated
Imports
java.util.Map, jakarta.servlet.ServletContext, org.springframework.core.io.Resource, org.springframework.http.MediaType, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils, org.springframework.web.HttpMediaTypeNotAcceptableException, org.springframework.web.context.request.NativeWebRequest

Deprecated

as of 5.2.4. See class-level note in ContentNegotiationManagerFactoryBean on the deprecation of path extension config options.

Extends PathExtensionContentNegotiationStrategy that also uses ServletContext#getMimeType(String) to resolve file extensions.
Author
Rossen Stoyanchev
Since
3.2

Field Summary

Modifier and TypeField and Description
private final ServletContext

Constructor Summary

AccessConstructor and Description
public
ServletPathExtensionContentNegotiationStrategy(ServletContext context)

Create an instance without any mappings to start with.

public
ServletPathExtensionContentNegotiationStrategy(ServletContext servletContext, Map<String, MediaType> mediaTypes)

Create an instance with the given extension-to-MediaType lookup.

Method Summary

Modifier and TypeMethod and Description
public MediaType

Returns:

the MediaType for the extension, or null if none found
getMediaTypeForResource
(Resource
the resource to look up
resource
)

Overrides org.springframework.web.accept.PathExtensionContentNegotiationStrategy.getMediaTypeForResource.

Extends the base class PathExtensionContentNegotiationStrategy#getMediaTypeForResource with the ability to also look up through the ServletContext.
protected MediaType
Inherited from org.springframework.web.accept.PathExtensionContentNegotiationStrategy:
getMediaTypeKeysetUrlPathHelpersetUseJaf

Field Detail

servletContextback to summary
private final ServletContext servletContext

Constructor Detail

ServletPathExtensionContentNegotiationStrategyback to summary
public ServletPathExtensionContentNegotiationStrategy(ServletContext context)

Create an instance without any mappings to start with. Mappings may be added later when extensions are resolved through ServletContext#getMimeType(String) or via org.springframework.http.MediaTypeFactory.

ServletPathExtensionContentNegotiationStrategyback to summary
public ServletPathExtensionContentNegotiationStrategy(ServletContext servletContext, Map<String, MediaType> mediaTypes)

Create an instance with the given extension-to-MediaType lookup.

Method Detail

getMediaTypeForResourceback to summary
public MediaType getMediaTypeForResource(Resource resource)

Overrides org.springframework.web.accept.PathExtensionContentNegotiationStrategy.getMediaTypeForResource.

Extends the base class PathExtensionContentNegotiationStrategy#getMediaTypeForResource with the ability to also look up through the ServletContext.

Parameters
resource:Resource

the resource to look up

Returns:MediaType

the MediaType for the extension, or null if none found

Annotations
@Override
Since
4.3
handleNoMatchback to summary
protected MediaType handleNoMatch(NativeWebRequest webRequest, String extension) throws HttpMediaTypeNotAcceptableException

Overrides org.springframework.web.accept.AbstractMappingContentNegotiationStrategy.handleNoMatch.

Resolve file extension via ServletContext#getMimeType(String) and also delegate to base class for a potential org.springframework.http.MediaTypeFactory lookup.

Annotations
@Override
@Nullable