Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-10090

Exception when using @ResponseEntity on @ExceptionHandler method

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Works as Designed
    • Affects Version/s: 3.2 RC2
    • Fix Version/s: None
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      This is a duplicate of bug SPR-7637 and SPR-6692. SPR-7637 is marked as resolved, claiming the issue has been addressed, but it is not. I am trying to do exactly this, and I get the following exception:

      00:50:42.949 ERROR annotation.AnnotationMethodHandlerExceptionResolver (AnnotationMethodHandlerExceptionResolver.java:147) Invoking request method resulted in exception : public org.springframework.http.ResponseEntity com.latencyzero.gamecenter.web.ServiceController.handleException(java.lang.Exception)
      java.lang.IllegalArgumentException: Invalid handler method return value: <500 Internal Server Error,{"resultMsg":"Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Cannot open connection","result":1},{Content-Type=[application/json;charset=UTF-8]}>
      	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.getModelAndView(AnnotationMethodHandlerExceptionResolver.java:414)
      	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.doResolveException(AnnotationMethodHandlerExceptionResolver.java:144)
      	at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136)
      	at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1148)
      	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:985)
      	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
      	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
      	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:917)
      	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:813)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:120)
      	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:798)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:97)
      

      My handler is declared as follows:

      @ExceptionHandler(org.springframework.web.bind.MissingServletRequestParameterException.class)
      public
      ResponseEntity<String>
      handleException(org.springframework.web.bind.MissingServletRequestParameterException inEx)
      {
          ...
      }
      

      According to the 3.2.0.RC2 docs, it is now acceptable. But the code seems to handle all cases except ResponseEntity: https://github.com/SpringSource/spring-framework/blob/master/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java#L376

        Attachments

          Activity

            People

            • Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              jetforme Rick Mann
              Last updater:
              Chris Beams
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                5 years, 27 weeks, 6 days ago