Announcement Announcement Module
Collapse
No announcement yet.
Exception handler returns OK when writing into response Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception handler returns OK when writing into response

    Hi,
    I'm using spring-webmvc : 3.2.3.RELEASE (and its related dependencies).

    I have this controller:
    Code:
    @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();
    	}
    }
    Whenthe "/home" method is invoked, I'm expectin to get HttpStatus.CONFLICT, but instead, I'm getting HttpStatus.OK.
    Can someone please tell me what should I do in order to get the response status from
    the annotated exception handler?
Working...
X