java.lang.IllegalStateException: Response is closed.

JBoss Issue Tracker | Vlad Arkhipov | 3 years ago
  1. 0

    Resteasy v.3 client does not allow to read the entity if an exception was thrown in the method that returns void. {code}@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(); } } {code} This code (v.2 client) works fine. {code}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)); }{code} But that code (v.3 client) fails. {code}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)); }{code} {code}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){code} The response's entity is buffered in the DefaultEntityExtractorFactory.createVoidExtractor. However ClientResponse cannot read the entity (even from the buffer) if it was closed.

    JBoss Issue Tracker | 3 years ago | Vlad Arkhipov
    java.lang.IllegalStateException: Response is closed.
  2. 0

    Resteasy v.3 client does not allow to read the entity if an exception was thrown in the method that returns void. {code}@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(); } } {code} This code (v.2 client) works fine. {code}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)); }{code} But that code (v.3 client) fails. {code}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)); }{code} {code}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){code} The response's entity is buffered in the DefaultEntityExtractorFactory.createVoidExtractor. However ClientResponse cannot read the entity (even from the buffer) if it was closed.

    JBoss Issue Tracker | 3 years ago | Vlad Arkhipov
    java.lang.IllegalStateException: Response is closed.
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Re:java.lang.IllegalStateException: response is already committed

    Terracotta | 8 years ago | eric.sun
    java.lang.IllegalStateException: response is already committed

    2 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      Response is closed.

      at org.jboss.resteasy.specimpl.BuiltResponse.abortIfClosed()
    2. RESTEasy JAX-RS Implementation
      BuiltResponse.abortIfClosed
      1. org.jboss.resteasy.specimpl.BuiltResponse.abortIfClosed(BuiltResponse.java:254)
      1 frame
    3. RESTEasy JAX-RS Client
      ClientResponse.readEntity
      1. org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:148)
      1 frame