Browse Source

SPR-6935 - @ResponseBody with method that return void throws "Could not resolve view exception".

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

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

@ -447,7 +447,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator @@ -447,7 +447,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
* @return the ServletRequestDataBinder instance to use
* @throws Exception in case of invalid state or arguments
* @see ServletRequestDataBinder#bind(javax.servlet.ServletRequest)
* @see ServletRequestDataBinder#convertIfNecessary(Object, Class, MethodParameter)
* @see ServletRequestDataBinder#convertIfNecessary(Object, Class, org.springframework.core.MethodParameter)
*/
protected ServletRequestDataBinder createBinder(
HttpServletRequest request, Object target, String objectName) throws Exception {
@ -812,7 +812,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator @@ -812,7 +812,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
}
}
if (returnValue != null && AnnotationUtils.findAnnotation(handlerMethod, ResponseBody.class) != null) {
if (AnnotationUtils.findAnnotation(handlerMethod, ResponseBody.class) != null) {
handleResponseBody(returnValue, webRequest);
return null;
}
@ -861,6 +861,9 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator @@ -861,6 +861,9 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
@SuppressWarnings("unchecked")
private void handleResponseBody(Object returnValue, ServletWebRequest webRequest)
throws ServletException, IOException {
if (returnValue == null) {
return;
}
HttpInputMessage inputMessage = new ServletServerHttpRequest(webRequest.getRequest());
List<MediaType> acceptedMediaTypes = inputMessage.getHeaders().getAccept();

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

@ -1187,6 +1187,18 @@ public class ServletAnnotationControllerTests { @@ -1187,6 +1187,18 @@ public class ServletAnnotationControllerTests {
assertEquals("Invalid response status code", "application/json", response.getHeader("Content-Type"));
}
@Test
public void responseBodyVoid() throws ServletException, IOException {
initServlet(ResponseBodyVoidController.class);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/something");
request.addHeader("Accept", "text/*, */*");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals(200, response.getStatus());
}
@Test
public void headers() throws ServletException, IOException {
initServlet(HeadersController.class);
@ -2156,6 +2168,15 @@ public class ServletAnnotationControllerTests { @@ -2156,6 +2168,15 @@ public class ServletAnnotationControllerTests {
}
}
@Controller
public static class ResponseBodyVoidController {
@RequestMapping("/something")
@ResponseBody
public void handle() throws IOException {
}
}
public static class NotReadableMessageConverter implements HttpMessageConverter {
public boolean canRead(Class clazz, MediaType mediaType) {

Loading…
Cancel
Save