Update ContentNegotiationManager for unknown path exts

This change refines the logic of "mapping" content negotiation
strategies with regards to how to handle cases where no mapping is
found.

The request parameter strategy now treats request parameter values that
do not match any mapped media type as 406 errors.

The path extension strategy provides a new flag called
"ignoreUnknownExtensions" (true by default) that when set to false also
results in a 406. The same flag is also exposed through the
ContentNegotiationManagerFactoryBean and the MVC Java config.

Issue: SPR-10170
This commit is contained in:
Rossen Stoyanchev
2014-05-01 11:54:48 -04:00
parent c50887c877
commit 0d2aa51576
11 changed files with 179 additions and 46 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -94,6 +94,18 @@ public class ContentNegotiationConfigurer {
return this;
}
/**
* Whether to ignore requests that have a file extension that does not match
* any mapped media types. Setting this to {@code false} will result in a
* {@code HttpMediaTypeNotAcceptableException} when there is no match.
*
* <p>By default this is set to {@code true}.
*/
public ContentNegotiationConfigurer ignoreUnknownPathExtensions(boolean ignore) {
this.factoryBean.setIgnoreUnknownPathExtensions(ignore);
return this;
}
/**
* Indicate whether to use the Java Activation Framework as a fallback option
* to map from file extensions to media types. This is used only when