Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1142

resteasy-client thrown exceptions during resteasy-jaxrs resource invocation causes IllegalStateException indigestion

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 4.0.0.Beta7, 3.6.3.Final
    • 3.0.9.Final, 3.0.10.Final, 3.6.2.Final
    • jaxrs
    • None

    Description

      Consider a simple Resource:

          @Path("/")
          public static class FetchResource {
              @Path("/test")
              @GET
              public String get() {
                  ClientBuilder.newClient().target(ADDR + "/404").request().get(String.class);
              }
          }
      

      The Client throws a NotFoundException, as expected. But if this exception is unhandled, the server will think that the local code thew this exception instead, since it is a subclass of WebApplicationException! Then, the ExceptionHandler#handleException blows up during #unwrapException because it tries to read the Entity that was set, but the entity is long-closed:

      [Mon Dec 15 17:25:21 PST 2014] Unexpected problem running servlet
      java.lang.IllegalStateException: Response is closed.
      	at org.jboss.resteasy.specimpl.BuiltResponse.abortIfClosed(BuiltResponse.java:254)
      	at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.abortIfClosed(ClientResponse.java:322)
      	at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.getEntity(ClientResponse.java:77)
      	at org.jboss.resteasy.core.ExceptionHandler.unwrapException(ExceptionHandler.java:125)
      	at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:74)
      	at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)
      	at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)
      	at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)
      	at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
      	at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
      	at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
      	at org.jboss.resteasy.plugins.server.tjws.TJWSServletDispatcher.service(TJWSServletDispatcher.java:40)
      

      I can see two justifiable results:

      1) The server knows this is a Client-thrown exception and responds with the generic "500 Internal Server Error: uncaught exception" same as any other thrown RuntimeException (e.g. a NullPointerException) would generate.

      2) The server correctly unwraps the Client exception and returns a 404 not found as the final result

      I personally think #1 is more correct. But either way the current behavior is certainly broken.

      I have a test case here:
      https://github.com/stevenschlansker/resteasy-client-server-exception

      Attachments

        Issue Links

          Activity

            People

              rsigal@redhat.com Ronald Sigal
              stevenschlansker Steven Schlansker
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: