Merge branch '3.2.x' into master
* 3.2.x: Fix ClassCastException when setting media types Enable execution of TestNG tests in spring-test Polish support for topic branch-specific versions Segregate add'l long-running and performance tests Eliminate EBR dependencies and repository config Skip creation of IDEA metadata for spring-aspects Fix Eclipse compilation error in Gradle plugin Polish build.gradle Fix null parameterName issue in content negotiation Recursively add test dependencies
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.web.servlet.config.annotation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
@@ -36,7 +37,9 @@ import org.springframework.web.accept.ContentNegotiationManagerFactoryBean;
|
||||
*/
|
||||
public class ContentNegotiationConfigurer {
|
||||
|
||||
private ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean();
|
||||
private final ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean();
|
||||
|
||||
private final Map<String, MediaType> mediaTypes = new HashMap<String, MediaType>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -64,7 +67,7 @@ public class ContentNegotiationConfigurer {
|
||||
* still be used in conjunction with {@link #favorPathExtension(boolean)}.
|
||||
*/
|
||||
public ContentNegotiationConfigurer mediaType(String extension, MediaType mediaType) {
|
||||
this.factoryBean.getMediaTypes().put(extension, mediaType);
|
||||
this.mediaTypes.put(extension, mediaType);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -75,7 +78,7 @@ public class ContentNegotiationConfigurer {
|
||||
*/
|
||||
public ContentNegotiationConfigurer mediaTypes(Map<String, MediaType> mediaTypes) {
|
||||
if (mediaTypes != null) {
|
||||
this.factoryBean.getMediaTypes().putAll(mediaTypes);
|
||||
this.mediaTypes.putAll(mediaTypes);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -86,7 +89,7 @@ public class ContentNegotiationConfigurer {
|
||||
* still be used in conjunction with {@link #favorPathExtension(boolean)}.
|
||||
*/
|
||||
public ContentNegotiationConfigurer replaceMediaTypes(Map<String, MediaType> mediaTypes) {
|
||||
this.factoryBean.getMediaTypes().clear();
|
||||
this.mediaTypes.clear();
|
||||
mediaTypes(mediaTypes);
|
||||
return this;
|
||||
}
|
||||
@@ -157,6 +160,9 @@ public class ContentNegotiationConfigurer {
|
||||
* Return the configured {@link ContentNegotiationManager} instance
|
||||
*/
|
||||
protected ContentNegotiationManager getContentNegotiationManager() throws Exception {
|
||||
if (!this.mediaTypes.isEmpty()) {
|
||||
this.factoryBean.addMediaTypes(mediaTypes);
|
||||
}
|
||||
this.factoryBean.afterPropertiesSet();
|
||||
return this.factoryBean.getObject();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.activation.FileTypeMap;
|
||||
@@ -196,7 +197,9 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport
|
||||
@Deprecated
|
||||
public void setMediaTypes(Map<String, String> mediaTypes) {
|
||||
if (mediaTypes != null) {
|
||||
this.cnManagerFactoryBean.getMediaTypes().putAll(mediaTypes);
|
||||
Properties props = new Properties();
|
||||
props.putAll(mediaTypes);
|
||||
this.cnManagerFactoryBean.setMediaTypes(props);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user