Browse Source

SPR-6214 - Using @ResponseBody throws HttpMediaTypeNotAcceptableException when it supports writing an acceptable MediaType

pull/23217/head
Arjen Poutsma 15 years ago
parent
commit
5310035700
  1. 2
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java
  2. 14
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java

2
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java

@ -789,7 +789,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen @@ -789,7 +789,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen
for (Object o : messageConverter.getSupportedMediaTypes()) {
MediaType supportedMediaType = (MediaType) o;
for (MediaType acceptedMediaType : acceptedMediaTypes) {
if (supportedMediaType.includes(acceptedMediaType)) {
if (acceptedMediaType.includes(supportedMediaType)) {
messageConverter.write(returnValue, outputMessage);
this.responseArgumentUsed = true;
return;

14
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java

@ -987,6 +987,20 @@ public class ServletAnnotationControllerTests { @@ -987,6 +987,20 @@ public class ServletAnnotationControllerTests {
assertEquals(406, response.getStatus());
}
@Test
public void responseBodyWildCardMediaType() throws ServletException, IOException {
initServlet(RequestBodyController.class);
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
String requestBody = "Hello World";
request.setContent(requestBody.getBytes("UTF-8"));
request.addHeader("Content-Type", "text/plain; charset=utf-8");
request.addHeader("Accept", "*/*");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals(requestBody, response.getContentAsString());
}
@Test
public void unsupportedRequestBody() throws ServletException, IOException {
initServlet(RequestBodyController.class);

Loading…
Cancel
Save