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

When forwarding an AbortedResponse response body is lost

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 3.1.0.Final, 3.0.20.Final
    • 3.0.5.Final, 3.0.10.Final, 3.0.19.Final, 3.1.0.CR2, 3.1.0.CR3
    • jaxrs
    • None
    • Hide

      Run below example and call the /resteasy-client-abort-problem/showproblem endpoint:

      package resteasyclientabortproblem;
      
      import javax.ws.rs.GET;
      import javax.ws.rs.Path;
      import javax.ws.rs.Produces;
      import javax.ws.rs.client.Client;
      import javax.ws.rs.client.ClientBuilder;
      import javax.ws.rs.client.ClientRequestContext;
      import javax.ws.rs.client.ClientRequestFilter;
      import javax.ws.rs.core.Response;
      import java.io.IOException;
      
      import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
      import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;
      
      @Path("/")
      public class ClientAbortProblem implements ClientRequestFilter {
      
          @Override
          public void filter(ClientRequestContext requestContext) throws IOException {
              requestContext.abortWith(Response.ok("This is an aborted response").header("Aborted", "true").type(TEXT_PLAIN_TYPE).build());
          }
      
          @Path("/showproblem")
          @GET
          @Produces({TEXT_PLAIN})
          public Response showProblem() {
              Client c = ClientBuilder.newClient().register(this);
              return c.target("http://doesnotmattersinceitisaborted").request().get();
              // the problem is that the response body is lost somehow. I would have expected the text "This is an aborted response"
              // but the body is empty and the Content-Length header says 0. The Aborted: true header comes back as expected and so does the content type
              // i have run the same test against jersey and here i get the body
          }
      }
      
      Show
      Run below example and call the /resteasy-client-abort-problem/showproblem endpoint: package resteasyclientabortproblem; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; import javax.ws.rs.core.Response; import java.io.IOException; import static javax.ws.rs.core.MediaType.TEXT_PLAIN; import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE; @Path( "/" ) public class ClientAbortProblem implements ClientRequestFilter { @Override public void filter(ClientRequestContext requestContext) throws IOException { requestContext.abortWith(Response.ok( "This is an aborted response" ).header( "Aborted" , " true " ).type(TEXT_PLAIN_TYPE).build()); } @Path( "/showproblem" ) @GET @Produces({TEXT_PLAIN}) public Response showProblem() { Client c = ClientBuilder.newClient().register( this ); return c.target( "http: //doesnotmattersinceitisaborted" ).request().get(); // the problem is that the response body is lost somehow. I would have expected the text "This is an aborted response" // but the body is empty and the Content-Length header says 0. The Aborted: true header comes back as expected and so does the content type // i have run the same test against jersey and here i get the body } }

      When a service calls another service through the jaxrs client and there is a a ClientRequestFilter that calls abortWith(...), the response body is lost when passing the aborted response back in the original request.

      I have tested against various versions to check for regession, I have also tested against jersey where it works as expected.

      I can push my entire test project to github if it makes it easier to reproduce.

            rsigal@redhat.com Ronald Sigal
            djarnis73 Jens Teglhus Møller (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: