|
|
|
|
@ -1006,6 +1006,29 @@ public class ServletHandlerMethodTests {
@@ -1006,6 +1006,29 @@ public class ServletHandlerMethodTests {
|
|
|
|
|
assertEquals(415, response.getStatus()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void consumes() throws ServletException, IOException { |
|
|
|
|
initDispatcherServlet(ConsumesController.class, null); |
|
|
|
|
|
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/something"); |
|
|
|
|
request.setContentType("application/pdf"); |
|
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
|
servlet.service(request, response); |
|
|
|
|
assertEquals("pdf", response.getContentAsString()); |
|
|
|
|
|
|
|
|
|
request = new MockHttpServletRequest("POST", "/something"); |
|
|
|
|
request.setContentType("text/html"); |
|
|
|
|
response = new MockHttpServletResponse(); |
|
|
|
|
servlet.service(request, response); |
|
|
|
|
assertEquals("text", response.getContentAsString()); |
|
|
|
|
|
|
|
|
|
request = new MockHttpServletRequest("POST", "/something"); |
|
|
|
|
request.setContentType("application/xml"); |
|
|
|
|
response = new MockHttpServletResponse(); |
|
|
|
|
servlet.service(request, response); |
|
|
|
|
assertEquals(415, response.getStatus()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void negatedContentTypeHeaders() throws ServletException, IOException { |
|
|
|
|
initDispatcherServlet(NegatedContentTypeHeadersController.class, null); |
|
|
|
|
@ -1058,6 +1081,41 @@ public class ServletHandlerMethodTests {
@@ -1058,6 +1081,41 @@ public class ServletHandlerMethodTests {
|
|
|
|
|
assertEquals(406, response.getStatus()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void produces() throws ServletException, IOException { |
|
|
|
|
initDispatcherServlet(ProducesController.class, null); |
|
|
|
|
|
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/something"); |
|
|
|
|
request.addHeader("Accept", "text/html"); |
|
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
|
servlet.service(request, response); |
|
|
|
|
assertEquals("html", response.getContentAsString()); |
|
|
|
|
|
|
|
|
|
request = new MockHttpServletRequest("GET", "/something"); |
|
|
|
|
request.addHeader("Accept", "application/xml"); |
|
|
|
|
response = new MockHttpServletResponse(); |
|
|
|
|
servlet.service(request, response); |
|
|
|
|
assertEquals("xml", response.getContentAsString()); |
|
|
|
|
|
|
|
|
|
request = new MockHttpServletRequest("GET", "/something"); |
|
|
|
|
request.addHeader("Accept", "application/xml, text/html"); |
|
|
|
|
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()); |
|
|
|
|
|
|
|
|
|
request = new MockHttpServletRequest("GET", "/something"); |
|
|
|
|
request.addHeader("Accept", "application/msword"); |
|
|
|
|
response = new MockHttpServletResponse(); |
|
|
|
|
servlet.service(request, response); |
|
|
|
|
assertEquals(406, response.getStatus()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void responseStatus() throws ServletException, IOException { |
|
|
|
|
initDispatcherServlet(ResponseStatusController.class, null); |
|
|
|
|
@ -2271,6 +2329,20 @@ public class ServletHandlerMethodTests {
@@ -2271,6 +2329,20 @@ public class ServletHandlerMethodTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
|
public static class ConsumesController { |
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/something", consumes = "application/pdf") |
|
|
|
|
public void handlePdf(Writer writer) throws IOException { |
|
|
|
|
writer.write("pdf"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/something", consumes = "text/*") |
|
|
|
|
public void handleHtml(Writer writer) throws IOException { |
|
|
|
|
writer.write("text"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
|
public static class NegatedContentTypeHeadersController { |
|
|
|
|
|
|
|
|
|
@ -2300,6 +2372,20 @@ public class ServletHandlerMethodTests {
@@ -2300,6 +2372,20 @@ public class ServletHandlerMethodTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
|
public static class ProducesController { |
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/something", produces = "text/html") |
|
|
|
|
public void handleHtml(Writer writer) throws IOException { |
|
|
|
|
writer.write("html"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/something", produces = "application/xml") |
|
|
|
|
public void handleXml(Writer writer) throws IOException { |
|
|
|
|
writer.write("xml"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
|
public static class ResponseStatusController { |
|
|
|
|
|
|
|
|
|
|