quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.82k stars 2.69k forks source link

use Response from RestClient for direct return in api resource broken in 2.5.0 final (but work in 2.4.0 final) #21818

Closed Fabrice-Deshayes-aka-Xtream closed 2 years ago

Fabrice-Deshayes-aka-Xtream commented 2 years ago

Describe the bug

My application is a kind of proxy. It exposes an api, who get its response for another enabler which is requested using RestClient.

Here is the rest client

@Path("/api/v1/supervision")
@RegisterRestClient
public interface ProxyService {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/order")
    Response getOrders(
            @HeaderParam(X_OAPI_API_KEY) String apiKey,
            @QueryParam("page") int page,
            @QueryParam("size") int size,
            @QueryParam("filter") String filter
    );
}

Here is the api resource

@Path("/api/v1/supervision")
public class ProxyResources {

    @Inject
    @RestClient
    ProxyService proxyService;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/order/")
    public Response getOrders(
            @HeaderParam(X_OAPI_API_KEY) String apiKey,
            @QueryParam("page") int page,
            @QueryParam("size") int size,
            @QueryParam("filter") String filter) {
        return proxyService.getOrders(apiKey, page, size, filter);
    }
}

Expected behavior

Until quarkus 2.4.0 final, all is working. The restclient get a Response, which is used as the api resource response. The json body and http status are preserved between the restclient and api resource layers.

Actual behavior

After switching to 2.5.0 final, the json response body is corrupted. The beginning of the body is truncated, the end also. The browser seems to stay in progress waiting for a full json response which never come.

We try to bypass the problem by rewriting the Response on the api resource class like this, but it doesn't work

return Response.fromResponse(proxyService.getOrders(apiKey, page, size, filter)).build();

We try to bypass the problem by rewriting the Response on the api resource class like this, and it works

Response response = proxyService.getOrders(apiKey, page, size, filter);
String jsonRead = IOUtils.toString((InputStream) response.getEntity(), Charset.defaultCharset());
return Response.status(response.getStatus()).entity(jsonRead).build();

How to Reproduce?

The problem occurs with quarkus 2.5.0 final, without graalvm (and also with graalvm native version). It seems that the mechanism which create a Response from another Response has an issue.

Output of uname -a or ver

Linux xtream-pc 5.10.79-1-MANJARO #1 SMP PREEMPT Fri Nov 12 20:26:09 UTC 2021 x86_64 GNU/Linux

Output of java -version

openjdk version "11.0.13" 2021-10-19 OpenJDK Runtime Environment (build 11.0.13+8) OpenJDK 64-Bit Server VM (build 11.0.13+8, mixed mode)

GraalVM version (if different from Java)

issue occurs without graalvm

Quarkus version or git rev

2.5.0 final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.3

Additional information

No response

geoand commented 2 years ago

I am pretty sure this is the same problem as https://github.com/quarkusio/quarkus/issues/21602.

So I am going to close this as it's fixed and the fixed will be available in 2.5.1.Final. When that comes out, please try it again and if the problem is not solved, please comment on the issue (and attach a project that exhibits the problematic behavior)