SPR-6935 - @ResponseBody with method that return void throws "Could not resolve view exception".
This commit is contained in:
parent
57993d871e
commit
eddc5b8898
|
|
@ -447,7 +447,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||||
* @return the ServletRequestDataBinder instance to use
|
* @return the ServletRequestDataBinder instance to use
|
||||||
* @throws Exception in case of invalid state or arguments
|
* @throws Exception in case of invalid state or arguments
|
||||||
* @see ServletRequestDataBinder#bind(javax.servlet.ServletRequest)
|
* @see ServletRequestDataBinder#bind(javax.servlet.ServletRequest)
|
||||||
* @see ServletRequestDataBinder#convertIfNecessary(Object, Class, MethodParameter)
|
* @see ServletRequestDataBinder#convertIfNecessary(Object, Class, org.springframework.core.MethodParameter)
|
||||||
*/
|
*/
|
||||||
protected ServletRequestDataBinder createBinder(
|
protected ServletRequestDataBinder createBinder(
|
||||||
HttpServletRequest request, Object target, String objectName) throws Exception {
|
HttpServletRequest request, Object target, String objectName) throws Exception {
|
||||||
|
|
@ -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);
|
handleResponseBody(returnValue, webRequest);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -861,6 +861,9 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void handleResponseBody(Object returnValue, ServletWebRequest webRequest)
|
private void handleResponseBody(Object returnValue, ServletWebRequest webRequest)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
|
if (returnValue == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
HttpInputMessage inputMessage = new ServletServerHttpRequest(webRequest.getRequest());
|
HttpInputMessage inputMessage = new ServletServerHttpRequest(webRequest.getRequest());
|
||||||
List<MediaType> acceptedMediaTypes = inputMessage.getHeaders().getAccept();
|
List<MediaType> acceptedMediaTypes = inputMessage.getHeaders().getAccept();
|
||||||
|
|
|
||||||
|
|
@ -1187,6 +1187,18 @@ public class ServletAnnotationControllerTests {
|
||||||
assertEquals("Invalid response status code", "application/json", response.getHeader("Content-Type"));
|
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
|
@Test
|
||||||
public void headers() throws ServletException, IOException {
|
public void headers() throws ServletException, IOException {
|
||||||
initServlet(HeadersController.class);
|
initServlet(HeadersController.class);
|
||||||
|
|
@ -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 static class NotReadableMessageConverter implements HttpMessageConverter {
|
||||||
|
|
||||||
public boolean canRead(Class clazz, MediaType mediaType) {
|
public boolean canRead(Class clazz, MediaType mediaType) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue