SPR-6686 - @ResponseBody throws HttpMediaTypeNotAcceptableException if client accepts "*/*"

This commit is contained in:
Arjen Poutsma
2010-01-15 10:23:59 +00:00
parent f7952fccc8
commit 8d5fc2bf91
8 changed files with 167 additions and 12 deletions

View File

@@ -864,6 +864,9 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
if (acceptedMediaTypes.isEmpty()) {
acceptedMediaTypes = Collections.singletonList(MediaType.ALL);
}
else {
Collections.sort(acceptedMediaTypes);
}
HttpOutputMessage outputMessage = new ServletServerHttpResponse(webRequest.getResponse());
Class<?> returnValueType = returnValue.getClass();
List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
@@ -872,7 +875,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
allSupportedMediaTypes.addAll(messageConverter.getSupportedMediaTypes());
for (MediaType acceptedMediaType : acceptedMediaTypes) {
if (messageConverter.canWrite(returnValueType, acceptedMediaType)) {
messageConverter.write(returnValue, null, outputMessage);
messageConverter.write(returnValue, acceptedMediaType, outputMessage);
this.responseArgumentUsed = true;
return;
}