I am using spring -webmvc: 3.2.3.RELEASE (and its related dependencies).
I have this controller:
@Controller @RequestMapping("/home") public class HomeController { @Autowired MappingJacksonHttpMessageConverter messageConverter; @RequestMapping(method = RequestMethod.GET) public String get() { throw new RuntimeException("XXXXXX"); } @ExceptionHandler(value = java.lang.RuntimeException.class) @ResponseStatus(HttpStatus.CONFLICT) public ModelAndView runtimeExceptionAndView(ServletWebRequest webRequest) throws Exception { ModelAndView retVal = handleResponseBody("AASASAS", webRequest); return retVal; } @SuppressWarnings({ "resource", "rawtypes", "unchecked" }) private ModelAndView handleResponseBody(Object body, ServletWebRequest webRequest) throws ServletException, IOException { ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(webRequest.getResponse()); messageConverter.write(body, MediaType.APPLICATION_JSON, outputMessage); return new ModelAndView(); } }
since the / home method throws a RuntimeException that is thrown with @ExceptionHandler when the get () method is called, I expect to get HttpStatus.CONFLICT, but instead I get HttpStatus.OK. Can someone please tell me What should I do to get the response status from the processed annotation handler?
source share