From 4f22bf7b7193edabb28b2c7a36b48f0a5352bb0f Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Fri, 10 Jan 2025 10:13:28 +0200 Subject: [PATCH] Take follow-redirects config into account for programmatic client created This property (as other config properties) is meant to apply to all clients, including ones created programmatically. Users can still override this by using .followRedirects() on the builder --- ...rogrammaticClientWithGlobalConfigTest.java | 44 +++++++++++++++++++ .../runtime/RestClientBuilderImpl.java | 4 +- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 extensions/resteasy-reactive/rest-client/deployment/src/test/java/io/quarkus/rest/client/reactive/redirect/RedirectTestForProgrammaticClientWithGlobalConfigTest.java diff --git a/extensions/resteasy-reactive/rest-client/deployment/src/test/java/io/quarkus/rest/client/reactive/redirect/RedirectTestForProgrammaticClientWithGlobalConfigTest.java b/extensions/resteasy-reactive/rest-client/deployment/src/test/java/io/quarkus/rest/client/reactive/redirect/RedirectTestForProgrammaticClientWithGlobalConfigTest.java new file mode 100644 index 0000000000000..7d3c9d1760237 --- /dev/null +++ b/extensions/resteasy-reactive/rest-client/deployment/src/test/java/io/quarkus/rest/client/reactive/redirect/RedirectTestForProgrammaticClientWithGlobalConfigTest.java @@ -0,0 +1,44 @@ +package io.quarkus.rest.client.reactive.redirect; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.net.URI; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.core.Response; + +import org.eclipse.microprofile.rest.client.RestClientBuilder; +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.quarkus.test.common.http.TestHTTPResource; + +public class RedirectTestForProgrammaticClientWithGlobalConfigTest { + + @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 shouldRedirect() { + Client client = RestClientBuilder.newBuilder().baseUri(uri).build(Client.class); + Response call = client.call(3); + assertThat(call.getStatus()).isEqualTo(200); + } + + @RegisterRestClient(configKey = "cl") + @Path("/redirect/302") + public interface Client { + @GET + Response call(@QueryParam("redirects") Integer redirects); + } +} diff --git a/extensions/resteasy-reactive/rest-client/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/RestClientBuilderImpl.java b/extensions/resteasy-reactive/rest-client/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/RestClientBuilderImpl.java index a498404808278..c27a1eb7f1e32 100644 --- a/extensions/resteasy-reactive/rest-client/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/RestClientBuilderImpl.java +++ b/extensions/resteasy-reactive/rest-client/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/RestClientBuilderImpl.java @@ -71,7 +71,7 @@ public class RestClientBuilderImpl implements RestClientBuilder { private final List paramConverterProviders = new ArrayList<>(); private URI uri; - private boolean followRedirects; + private Boolean followRedirects; private QueryParamStyle queryParamStyle; private MultivaluedMap headers = new CaseInsensitiveMap<>(); @@ -438,7 +438,7 @@ public T build(Class aClass) throws IllegalStateException, RestClientDefi exceptionMappers.sort(Comparator.comparingInt(ResponseExceptionMapper::getPriority)); redirectHandlers.sort(Comparator.comparingInt(RedirectHandler::getPriority)); clientBuilder.register(new MicroProfileRestClientResponseFilter(exceptionMappers)); - clientBuilder.followRedirects(followRedirects); + clientBuilder.followRedirects(followRedirects != null ? followRedirects : restClients.followRedirects().orElse(false)); RestClientsConfig.RestClientLoggingConfig logging = restClients.logging();