SPR-6214 - Using @ResponseBody throws HttpMediaTypeNotAcceptableException when it supports writing an acceptable MediaType
This commit is contained in:
parent
0f06771249
commit
5310035700
|
|
@ -789,7 +789,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen
|
||||||
for (Object o : messageConverter.getSupportedMediaTypes()) {
|
for (Object o : messageConverter.getSupportedMediaTypes()) {
|
||||||
MediaType supportedMediaType = (MediaType) o;
|
MediaType supportedMediaType = (MediaType) o;
|
||||||
for (MediaType acceptedMediaType : acceptedMediaTypes) {
|
for (MediaType acceptedMediaType : acceptedMediaTypes) {
|
||||||
if (supportedMediaType.includes(acceptedMediaType)) {
|
if (acceptedMediaType.includes(supportedMediaType)) {
|
||||||
messageConverter.write(returnValue, outputMessage);
|
messageConverter.write(returnValue, outputMessage);
|
||||||
this.responseArgumentUsed = true;
|
this.responseArgumentUsed = true;
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -987,6 +987,20 @@ public class ServletAnnotationControllerTests {
|
||||||
assertEquals(406, response.getStatus());
|
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
|
@Test
|
||||||
public void unsupportedRequestBody() throws ServletException, IOException {
|
public void unsupportedRequestBody() throws ServletException, IOException {
|
||||||
initServlet(RequestBodyController.class);
|
initServlet(RequestBodyController.class);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue