Announcement Announcement Module
Collapse
No announcement yet.
@ExceptionHandler doesnt work with ResponseEntity Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ExceptionHandler doesnt work with ResponseEntity

    Hello
    I'm trying to return a Responseentity object inside my @ExceptionHandler method but it complains about IllegalArugment ?
    Anyone able to use this feature?

    Code:
    ERROR: org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver - Invoking request method resulted in exception : public org.springframework.http.ResponseEntity sri.ws.RestErrorHandling.handleIOException(java.lang.Throwable,javax.servlet.http.HttpServletRequest)
    java.lang.IllegalArgumentException: Invalid handler method return value: org.springframework.http.ResponseEntity@9a912e
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.getModelAndView(AnnotationMethodHandlerExceptionResolver.java:387)
    	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.doResolveException(AnnotationMethodHandlerExceptionResolver.java:133)
    	at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136)
    	at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:987)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:811)

  • #2
    Hello

    1) Can you post your source code? Some detail you could be missing
    2) Can you post the complete error stack trace?

    Comment


    • #3
      The code is like this, the method gets called so nothing wrong with the call. Only return value has the problem.

      Code:
      @RequestMapping(value="/returnError")
      	 public ResponseEntity<String> returnError(){
      		 String message = "Exception occured";
      		 return new ResponseEntity<String>(message, HttpStatus.BAD_REQUEST);
      	 }

      Comment


      • #4
        Hello

        Your code seems be OK

        I just checked the API ResponseEntity and has this example

        Code:
         @RequestMapping("/handle")
         public ResponseEntity<String> handle() {
           HttpHeaders responseHeaders = new HttpHeaders();
           responseHeaders.set("MyResponseHeader", "MyValue");
           return new ResponseEntity<String>("Hello World", responseHeaders, HttpStatus.CREATED);
         }
        Try with the code above, Let me know what happen

        Comment


        • #5
          Well that worked for me earlier the only issue is when it is annotated with @ExceptionHandler, i get that error i posted before.

          Thanks for looking though.

          Comment


          • #6
            Message converters are not supported for @ExceptionHandler's yet.

            Take a look at this nitegate's post for details.

            Comment

            Working...
            X