Skip to content

Commit 675ec4c

Browse files
committed
Fix issue in ContentNeogitatingViewResolver
The following commit in 3.2.3 had a side effect on CNVR: aaded7e 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
1 parent 7bab879 commit 675ec4c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
import java.util.Map;
2626
import java.util.Properties;
2727
import java.util.Set;
28+
2829
import javax.activation.FileTypeMap;
2930
import javax.servlet.ServletContext;
3031
import javax.servlet.http.HttpServletRequest;
3132
import javax.servlet.http.HttpServletResponse;
3233

3334
import org.apache.commons.logging.Log;
3435
import org.apache.commons.logging.LogFactory;
35-
3636
import org.springframework.beans.factory.BeanFactoryUtils;
3737
import org.springframework.beans.factory.InitializingBean;
3838
import org.springframework.core.OrderComparator;
@@ -307,7 +307,11 @@ public View resolveViewName(String viewName, Locale locale) throws Exception {
307307
protected List<MediaType> getMediaTypes(HttpServletRequest request) {
308308
try {
309309
ServletWebRequest webRequest = new ServletWebRequest(request);
310+
310311
List<MediaType> acceptableMediaTypes = this.contentNegotiationManager.resolveMediaTypes(webRequest);
312+
acceptableMediaTypes = acceptableMediaTypes.isEmpty() ?
313+
Collections.singletonList(MediaType.ALL) : acceptableMediaTypes;
314+
311315
List<MediaType> producibleMediaTypes = getProducibleMediaTypes(request);
312316
Set<MediaType> compatibleMediaTypes = new LinkedHashSet<MediaType>();
313317
for (MediaType acceptable : acceptableMediaTypes) {

spring-webmvc/src/test/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolverTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
import static org.junit.Assert.*;
4848
import static org.mockito.BDDMockito.*;
49+
import static org.mockito.Mockito.*;
4950

5051
/**
5152
* @author Arjen Poutsma

0 commit comments

Comments
 (0)