diff --git a/extensions/resteasy-reactive/rest-client/deployment/src/test/java/io/quarkus/rest/client/reactive/FileDownloadTest.java b/extensions/resteasy-reactive/rest-client/deployment/src/test/java/io/quarkus/rest/client/reactive/FileDownloadTest.java new file mode 100644 index 00000000000000..83fa21fa7497a2 --- /dev/null +++ b/extensions/resteasy-reactive/rest-client/deployment/src/test/java/io/quarkus/rest/client/reactive/FileDownloadTest.java @@ -0,0 +1,78 @@ +package io.quarkus.rest.client.reactive; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.net.URI; +import java.time.Duration; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + +import org.eclipse.microprofile.rest.client.RestClientBuilder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.rest.client.reactive.redirect.RedirectingResource; +import io.quarkus.test.QuarkusUnitTest; +import io.quarkus.test.common.http.TestHTTPResource; +import io.smallrye.mutiny.Uni; + +public class FileDownloadTest { + + private static final File TXT_FILE = new File("./src/test/resources/lorem.txt"); + + @RegisterExtension + static final QuarkusUnitTest TEST = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClasses(Client.class, RedirectingResource.class)) + .overrideRuntimeConfigKey("quarkus.rest-client.follow-redirects", "true"); + + @TestHTTPResource + URI uri; + + @Test + void test() { + Client client = RestClientBuilder.newBuilder().baseUri(uri).build(Client.class); + File file = client.file(); + assertThat(file).exists().hasSize(TXT_FILE.length()); + + java.nio.file.Path path = client.path(); + assertThat(path).exists().hasSize(TXT_FILE.length()); + + file = client.uniFile().await().atMost(Duration.ofSeconds(10)); + assertThat(file).exists().hasSize(TXT_FILE.length()); + + path = client.uniPath().await().atMost(Duration.ofSeconds(10)); + assertThat(path).exists().hasSize(TXT_FILE.length()); + } + + @Path("/test") + public interface Client { + @GET + @Path("file") + File file(); + + @GET + @Path("file") + java.nio.file.Path path(); + + @GET + @Path("file") + Uni uniFile(); + + @GET + @Path("file") + Uni uniPath(); + } + + @Path("test") + public static class Resource { + + @Path("file") + @GET + public File file() { + return TXT_FILE; + } + } +} diff --git a/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/ClientSendRequestHandler.java b/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/ClientSendRequestHandler.java index 2d0392166403d1..cbdcfb0f1c79cb 100644 --- a/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/ClientSendRequestHandler.java +++ b/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/ClientSendRequestHandler.java @@ -311,24 +311,20 @@ public void handle(AsyncResult asyncFileOpened) { new Handler<>() { @Override public void handle(AsyncResult event) { - tmpAsyncFile.flush(new Handler<>() { - public void handle(AsyncResult flushed) { - if (flushed.failed()) { - reportFinish(flushed.cause(), - requestContext); - requestContext.resume(flushed.cause()); - return; - } - - if (loggingScope != LoggingScope.NONE) { - clientLogger.logRequest( - httpClientRequest, null, false); - } - - requestContext.setTmpFilePath(tmpFilePath); - requestContext.resume(); - } - }); + if (event.failed()) { + reportFinish(event.cause(), + requestContext); + requestContext.resume(event.cause()); + return; + } + + if (loggingScope != LoggingScope.NONE) { + clientLogger.logRequest( + httpClientRequest, null, false); + } + + requestContext.setTmpFilePath(tmpFilePath); + requestContext.resume(); } }); clientResponse.resume();