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

java.lang.IllegalStateException: Response is closed if trying to read the entity from response for methods that return void

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • Major
    • 3.0.7.Final
    • 3.0.6.Final
    • jaxrs
    • None

    Description

      Resteasy v.3 client does not allow to read the entity if an exception was thrown in the method that returns void.

      @Path("test")
      public interface IService {
          @POST
          @Path("test")
          public void test() throws Exception;
      }
      
      public class Service implements IService {
          @Override
          public void test() throws Exception {
              throw new Exception("Blah");
          }
      }
      
      @Provider
      public class ServerExceptionHandler implements ExceptionMapper<Exception> {
          public Response toResponse(Exception exception) {
              return Response.serverError().entity("Blah blah blah").build();
          }
      }
      

      This code (v.2 client) works fine.

      IService service = ProxyFactory.create(IService.class, "http://localhost:8080/resteasy-test/test");
      try {
          service.test();
      } catch (ClientResponseFailure e) {
          Response resp = e.getResponse();
          System.out.println(((ClientResponse) resp).getEntity(String.class));
      }

      But that code (v.3 client) fails.

      ResteasyClient client = new ResteasyClientBuilder().build();
      ResteasyWebTarget target = (ResteasyWebTarget) client.target("http://localhost:8080/resteasy-test/test");
      IService service = target.proxy(IService.class);
      try {
          service.test();
      } catch (InternalServerErrorException e) {
          Response resp = e.getResponse();
          System.out.println(resp.readEntity(String.class));
      }
      Exception in thread "main" java.lang.IllegalStateException: Response is closed.
      	at org.jboss.resteasy.specimpl.BuiltResponse.abortIfClosed(BuiltResponse.java:254)
      	at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:148)
      	at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:217)

      The response's entity is buffered in the DefaultEntityExtractorFactory.createVoidExtractor. However ClientResponse cannot read the entity (even from the buffer) if it was closed.

      Attachments

        Issue Links

          Activity

            People

              patriot1burke@gmail.com Bill Burke (Inactive)
              pref_jira Vlad Arkhipov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: