Polish SPR-12286
Issue: SPR-12286
This commit is contained in:
@@ -61,8 +61,6 @@ public class ContentNegotiationManagerFactoryBean
|
||||
|
||||
private String parameterName = "format";
|
||||
|
||||
private MediaType defaultContentType;
|
||||
|
||||
private ContentNegotiationStrategy defaultNegotiationStrategy;
|
||||
|
||||
private ContentNegotiationManager contentNegotiationManager;
|
||||
@@ -186,7 +184,7 @@ public class ContentNegotiationManagerFactoryBean
|
||||
* determine the requested content type.
|
||||
*/
|
||||
public void setDefaultContentType(MediaType defaultContentType) {
|
||||
this.defaultContentType = defaultContentType;
|
||||
this.defaultNegotiationStrategy = new FixedContentNegotiationStrategy(defaultContentType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,7 +194,7 @@ public class ContentNegotiationManagerFactoryBean
|
||||
* the requested content type.
|
||||
* @since 4.1.2
|
||||
*/
|
||||
public void setDefaultContentType(ContentNegotiationStrategy defaultStrategy) {
|
||||
public void setDefaultContentTypeStrategy(ContentNegotiationStrategy defaultStrategy) {
|
||||
this.defaultNegotiationStrategy = defaultStrategy;
|
||||
}
|
||||
|
||||
@@ -235,10 +233,6 @@ public class ContentNegotiationManagerFactoryBean
|
||||
strategies.add(new HeaderContentNegotiationStrategy());
|
||||
}
|
||||
|
||||
if (this.defaultContentType != null) {
|
||||
strategies.add(new FixedContentNegotiationStrategy(this.defaultContentType));
|
||||
}
|
||||
|
||||
if(this.defaultNegotiationStrategy != null) {
|
||||
strategies.add(defaultNegotiationStrategy);
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
||||
// SPR-12286
|
||||
@Test
|
||||
public void setDefaultContentTypeWithStrategy() throws Exception {
|
||||
this.factoryBean.setDefaultContentType(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON));
|
||||
this.factoryBean.setDefaultContentTypeStrategy(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON));
|
||||
this.factoryBean.afterPropertiesSet();
|
||||
ContentNegotiationManager manager = this.factoryBean.getObject();
|
||||
|
||||
|
||||
@@ -162,6 +162,9 @@ public class ContentNegotiationConfigurer {
|
||||
* <p>This content type will be used when neither the request path extension,
|
||||
* nor a request parameter, nor the {@code Accept} header could help determine
|
||||
* the requested content type.
|
||||
* <p>Note that this method achieves the same goal as {@code defaultContentTypeStrategy}, so both
|
||||
* shouldn't be used at the same time.
|
||||
* @see #defaultContentTypeStrategy(org.springframework.web.accept.ContentNegotiationStrategy)
|
||||
*/
|
||||
public ContentNegotiationConfigurer defaultContentType(MediaType defaultContentType) {
|
||||
this.factoryBean.setDefaultContentType(defaultContentType);
|
||||
@@ -173,10 +176,13 @@ public class ContentNegotiationConfigurer {
|
||||
* <p>This content type will be used when neither the request path extension,
|
||||
* nor a request parameter, nor the {@code Accept} header could help determine
|
||||
* the requested content type.
|
||||
* <p>Note that this method achieves the same goal as {@code defaultContentType}, so both
|
||||
* shouldn't be used at the same time.
|
||||
* @since 4.1.2
|
||||
* @see #defaultContentType(org.springframework.http.MediaType)
|
||||
*/
|
||||
public ContentNegotiationConfigurer defaultContentType(ContentNegotiationStrategy defaultStrategy) {
|
||||
this.factoryBean.setDefaultContentType(defaultStrategy);
|
||||
public ContentNegotiationConfigurer defaultContentTypeStrategy(ContentNegotiationStrategy defaultStrategy) {
|
||||
this.factoryBean.setDefaultContentTypeStrategy(defaultStrategy);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -113,8 +113,8 @@ public class ContentNegotiationConfigurerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultContentTypeWithStrategy() throws Exception {
|
||||
this.configurer.defaultContentType(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON));
|
||||
public void setDefaultContentTypeStrategy() throws Exception {
|
||||
this.configurer.defaultContentTypeStrategy(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON));
|
||||
ContentNegotiationManager manager = this.configurer.getContentNegotiationManager();
|
||||
|
||||
assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest));
|
||||
|
||||
Reference in New Issue
Block a user