Fix issue in ContentNeogitatingViewResolver

The following commit in 3.2.3 had a side effect on CNVR:
aaded7e30b

It appears that CNVR doesn't treat a request for "*/*" differently
from a request that does not request content types. Both should be
interpreted as "any content type is acceptable". This fix ensures
that CNVR treats these two cases the same way.

Issue: SPR-10683
master
Rossen Stoyanchev 11 years ago
parent 7bab879623
commit 675ec4c3e2
  1. 6
      spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java
  2. 1
      spring-webmvc/src/test/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolverTests.java

@ -25,6 +25,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import javax.activation.FileTypeMap; import javax.activation.FileTypeMap;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -32,7 +33,6 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.OrderComparator; import org.springframework.core.OrderComparator;
@ -307,7 +307,11 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport
protected List<MediaType> getMediaTypes(HttpServletRequest request) { protected List<MediaType> getMediaTypes(HttpServletRequest request) {
try { try {
ServletWebRequest webRequest = new ServletWebRequest(request); ServletWebRequest webRequest = new ServletWebRequest(request);
List<MediaType> acceptableMediaTypes = this.contentNegotiationManager.resolveMediaTypes(webRequest); List<MediaType> acceptableMediaTypes = this.contentNegotiationManager.resolveMediaTypes(webRequest);
acceptableMediaTypes = acceptableMediaTypes.isEmpty() ?
Collections.singletonList(MediaType.ALL) : acceptableMediaTypes;
List<MediaType> producibleMediaTypes = getProducibleMediaTypes(request); List<MediaType> producibleMediaTypes = getProducibleMediaTypes(request);
Set<MediaType> compatibleMediaTypes = new LinkedHashSet<MediaType>(); Set<MediaType> compatibleMediaTypes = new LinkedHashSet<MediaType>();
for (MediaType acceptable : acceptableMediaTypes) { for (MediaType acceptable : acceptableMediaTypes) {

@ -46,6 +46,7 @@ import org.springframework.web.servlet.ViewResolver;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*; import static org.mockito.BDDMockito.*;
import static org.mockito.Mockito.*;
/** /**
* @author Arjen Poutsma * @author Arjen Poutsma

Loading…
Cancel
Save