Browse Source

Polish media type change in ResourceHttpRequestHandler

pull/1143/head
Rossen Stoyanchev 8 years ago
parent
commit
4d3c3056ed
  1. 32
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java

32
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java

@ -48,10 +48,8 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.HttpRequestHandler; import org.springframework.web.HttpRequestHandler;
import org.springframework.web.accept.ContentNegotiationManager; import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.accept.ContentNegotiationManagerFactoryBean;
import org.springframework.web.accept.PathExtensionContentNegotiationStrategy; import org.springframework.web.accept.PathExtensionContentNegotiationStrategy;
import org.springframework.web.accept.ServletPathExtensionContentNegotiationStrategy; import org.springframework.web.accept.ServletPathExtensionContentNegotiationStrategy;
import org.springframework.web.context.request.ServletWebRequest; import org.springframework.web.context.request.ServletWebRequest;
@ -216,17 +214,10 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
} }
/** /**
* Configure a {@code ContentNegotiationManager} to determine the media types * Configure a {@code ContentNegotiationManager} to help determine the
* for resources being served. If the manager contains a path * media types for resources being served. If the manager contains a path
* extension strategy it will be used to look up the file extension * extension strategy it will be checked for registered file extension.
* of resources being served via * @param contentNegotiationManager the manager in use
* {@link PathExtensionContentNegotiationStrategy#getMediaTypeForResource
* getMediaTypeForResource}. If that fails the check is then expanded
* to use any configured content negotiation strategy against the request.
* <p>By default a {@link ContentNegotiationManagerFactoryBean} with default
* settings is used to create the manager. See the Javadoc of
* {@code ContentNegotiationManagerFactoryBean} for details
* @param contentNegotiationManager the manager to use
* @since 4.3 * @since 4.3
*/ */
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) { public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) {
@ -234,7 +225,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
} }
/** /**
* Return the specified content negotiation manager. * Return the configured content negotiation manager.
* @since 4.3 * @since 4.3
*/ */
public ContentNegotiationManager getContentNegotiationManager() { public ContentNegotiationManager getContentNegotiationManager() {
@ -516,16 +507,19 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
/** /**
* Determine the media type for the given request and the resource matched * Determine the media type for the given request and the resource matched
* to it. This implementation first tries to determine the MediaType based * to it. This implementation tries to determine the MediaType based on the
* strictly on the file extension of the Resource via * file extension of the Resource via
* {@link PathExtensionContentNegotiationStrategy#getMediaTypeForResource} * {@link ServletPathExtensionContentNegotiationStrategy#getMediaTypeForResource}.
* and then expands to check against the request via
* {@link ContentNegotiationManager#resolveMediaTypes}.
* @param request the current request * @param request the current request
* @param resource the resource to check * @param resource the resource to check
* @return the corresponding media type, or {@code null} if none found * @return the corresponding media type, or {@code null} if none found
*/ */
protected MediaType getMediaType(HttpServletRequest request, Resource resource) { protected MediaType getMediaType(HttpServletRequest request, Resource resource) {
// For backwards compatibility
MediaType mediaType = getMediaType(resource);
if (mediaType != null) {
return mediaType;
}
return this.pathExtensionStrategy.getMediaTypeForResource(resource); return this.pathExtensionStrategy.getMediaTypeForResource(resource);
} }

Loading…
Cancel
Save