|
48 | 48 | import org.springframework.util.ObjectUtils;
|
49 | 49 | import org.springframework.util.ResourceUtils;
|
50 | 50 | import org.springframework.util.StringUtils;
|
51 |
| -import org.springframework.web.HttpMediaTypeNotAcceptableException; |
52 | 51 | import org.springframework.web.HttpRequestHandler;
|
53 | 52 | import org.springframework.web.accept.ContentNegotiationManager;
|
54 |
| -import org.springframework.web.accept.ContentNegotiationManagerFactoryBean; |
55 | 53 | import org.springframework.web.accept.PathExtensionContentNegotiationStrategy;
|
56 | 54 | import org.springframework.web.accept.ServletPathExtensionContentNegotiationStrategy;
|
57 | 55 | import org.springframework.web.context.request.ServletWebRequest;
|
@@ -216,25 +214,18 @@ public ResourceRegionHttpMessageConverter getResourceRegionHttpMessageConverter(
|
216 | 214 | }
|
217 | 215 |
|
218 | 216 | /**
|
219 |
| - * Configure a {@code ContentNegotiationManager} to determine the media types |
220 |
| - * for resources being served. If the manager contains a path |
221 |
| - * extension strategy it will be used to look up the file extension |
222 |
| - * of resources being served via |
223 |
| - * {@link PathExtensionContentNegotiationStrategy#getMediaTypeForResource |
224 |
| - * getMediaTypeForResource}. If that fails the check is then expanded |
225 |
| - * to use any configured content negotiation strategy against the request. |
226 |
| - * <p>By default a {@link ContentNegotiationManagerFactoryBean} with default |
227 |
| - * settings is used to create the manager. See the Javadoc of |
228 |
| - * {@code ContentNegotiationManagerFactoryBean} for details |
229 |
| - * @param contentNegotiationManager the manager to use |
| 217 | + * Configure a {@code ContentNegotiationManager} to help determine the |
| 218 | + * media types for resources being served. If the manager contains a path |
| 219 | + * extension strategy it will be checked for registered file extension. |
| 220 | + * @param contentNegotiationManager the manager in use |
230 | 221 | * @since 4.3
|
231 | 222 | */
|
232 | 223 | public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) {
|
233 | 224 | this.contentNegotiationManager = contentNegotiationManager;
|
234 | 225 | }
|
235 | 226 |
|
236 | 227 | /**
|
237 |
| - * Return the specified content negotiation manager. |
| 228 | + * Return the configured content negotiation manager. |
238 | 229 | * @since 4.3
|
239 | 230 | */
|
240 | 231 | public ContentNegotiationManager getContentNegotiationManager() {
|
@@ -516,17 +507,20 @@ protected boolean isInvalidPath(String path) {
|
516 | 507 |
|
517 | 508 | /**
|
518 | 509 | * Determine the media type for the given request and the resource matched
|
519 |
| - * to it. This implementation first tries to determine the MediaType based |
520 |
| - * strictly on the file extension of the Resource via |
521 |
| - * {@link PathExtensionContentNegotiationStrategy#getMediaTypeForResource} |
522 |
| - * and then expands to check against the request via |
523 |
| - * {@link ContentNegotiationManager#resolveMediaTypes}. |
| 510 | + * to it. This implementation tries to determine the MediaType based on the |
| 511 | + * file extension of the Resource via |
| 512 | + * {@link ServletPathExtensionContentNegotiationStrategy#getMediaTypeForResource}. |
524 | 513 | * @param request the current request
|
525 | 514 | * @param resource the resource to check
|
526 | 515 | * @return the corresponding media type, or {@code null} if none found
|
527 | 516 | */
|
528 | 517 | @SuppressWarnings("deprecation")
|
529 | 518 | protected MediaType getMediaType(HttpServletRequest request, Resource resource) {
|
| 519 | + // For backwards compatibility |
| 520 | + MediaType mediaType = getMediaType(resource); |
| 521 | + if (mediaType != null) { |
| 522 | + return mediaType; |
| 523 | + } |
530 | 524 | return this.pathExtensionStrategy.getMediaTypeForResource(resource);
|
531 | 525 | }
|
532 | 526 |
|
|
0 commit comments