SPR-7000 - AnnotationMethodHandlerAdapter gives priority to media type order over quality when selecting a method
This commit is contained in:
@@ -120,8 +120,15 @@ public class RequestMappingInfoComparatorTests {
|
||||
|
||||
assertTrue(comparator.compare(html, xml) == 0);
|
||||
assertTrue(comparator.compare(xml, html) == 0);
|
||||
}
|
||||
|
||||
// See SPR-7000
|
||||
request = new MockHttpServletRequest();
|
||||
request.addHeader("Accept", "text/html;q=0.9,application/xml");
|
||||
comparator = new AnnotationMethodHandlerAdapter.RequestMappingInfoComparator(new MockComparator(), request);
|
||||
|
||||
assertTrue(comparator.compare(html, xml) > 0);
|
||||
assertTrue(comparator.compare(xml, html) < 0);
|
||||
}
|
||||
|
||||
private static class MockComparator implements Comparator<String> {
|
||||
|
||||
|
||||
@@ -1289,6 +1289,12 @@ public class ServletAnnotationControllerTests {
|
||||
response = new MockHttpServletResponse();
|
||||
servlet.service(request, response);
|
||||
assertEquals("xml", response.getContentAsString());
|
||||
|
||||
request = new MockHttpServletRequest("GET", "/something");
|
||||
request.addHeader("Accept", "text/html;q=0.9, application/xml");
|
||||
response = new MockHttpServletResponse();
|
||||
servlet.service(request, response);
|
||||
assertEquals("xml", response.getContentAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -2633,5 +2639,4 @@ public class ServletAnnotationControllerTests {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class ContentNegotiatingViewResolverTests {
|
||||
@Test
|
||||
public void getMediaTypeAcceptHeader() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test");
|
||||
request.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
||||
request.addHeader("Accept", "text/html,application/xml;q=0.9,application/xhtml+xml,*/*;q=0.8");
|
||||
List<MediaType> result = viewResolver.getMediaTypes(request);
|
||||
assertEquals("Invalid amount of media types", 4, result.size());
|
||||
assertEquals("Invalid content type", new MediaType("text", "html"), result.get(0));
|
||||
|
||||
Reference in New Issue
Block a user