From 53e45b5531c23f4b2d6aaaf8e820624c83becf63 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 8 Feb 2024 09:42:02 +0200 Subject: [PATCH 1/2] Make ClientLogger beans unremovable There is no reason why users should be forced to annotate their ClientLogger beans with `@Unremovable` Closes: #38658 --- .../deployment/RestClientReactiveProcessor.java | 5 +++-- .../it/rest/client/main/ClientCallingResource.java | 12 +++++------- .../quarkus/it/rest/client/main/MyClientLogger.java | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java index 839f1de001b1b..9aad6b9433586 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java @@ -60,6 +60,7 @@ import org.jboss.jandex.MethodInfo; import org.jboss.jandex.Type; import org.jboss.logging.Logger; +import org.jboss.resteasy.reactive.client.api.ClientLogger; import org.jboss.resteasy.reactive.client.interceptors.ClientGZIPDecodingInterceptor; import org.jboss.resteasy.reactive.client.spi.MissingMessageBodyReaderErrorMessageContextualizer; import org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames; @@ -179,8 +180,8 @@ void setupAdditionalBeans(BuildProducer additionalBeans } @BuildStep - UnremovableBeanBuildItem makeConfigUnremovable() { - return UnremovableBeanBuildItem.beanTypes(RestClientsConfig.class); + UnremovableBeanBuildItem unremovableBeans() { + return UnremovableBeanBuildItem.beanTypes(RestClientsConfig.class, ClientLogger.class); } @BuildStep diff --git a/integration-tests/rest-client-reactive/src/main/java/io/quarkus/it/rest/client/main/ClientCallingResource.java b/integration-tests/rest-client-reactive/src/main/java/io/quarkus/it/rest/client/main/ClientCallingResource.java index 950fe0ea3b9cf..11a803ea70741 100644 --- a/integration-tests/rest-client-reactive/src/main/java/io/quarkus/it/rest/client/main/ClientCallingResource.java +++ b/integration-tests/rest-client-reactive/src/main/java/io/quarkus/it/rest/client/main/ClientCallingResource.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.json.JsonMapper; import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter; +import io.quarkus.arc.Arc; import io.quarkus.it.rest.client.main.MyResponseExceptionMapper.MyException; import io.quarkus.it.rest.client.main.selfsigned.ExternalSelfSignedClient; import io.quarkus.it.rest.client.main.wronghost.WrongHostClient; @@ -62,9 +63,6 @@ public class ClientCallingResource { @Inject InMemorySpanExporter inMemorySpanExporter; - @Inject - MyClientLogger globalClientLogger; - void init(@Observes Router router) { router.post().handler(BodyHandler.create()); @@ -82,9 +80,9 @@ void init(@Observes Router router) { String url = rc.body().asString(); ClientWithClientLogger client = QuarkusRestClientBuilder.newBuilder().baseUri(URI.create(url)) .build(ClientWithClientLogger.class); - globalClientLogger.reset(); + Arc.container().instance(MyClientLogger.class).get().reset(); client.call(); - if (globalClientLogger.wasUsed()) { + if (Arc.container().instance(MyClientLogger.class).get().wasUsed()) { success(rc, "global client logger was used"); } else { fail(rc, "global client logger was not used"); @@ -106,9 +104,9 @@ void init(@Observes Router router) { }); router.post("/call-cdi-client-with-global-client-logger").blockingHandler(rc -> { - globalClientLogger.reset(); + Arc.container().instance(MyClientLogger.class).get().reset(); clientWithClientLogger.call(); - if (globalClientLogger.wasUsed()) { + if (Arc.container().instance(MyClientLogger.class).get().wasUsed()) { success(rc, "global client logger was used"); } else { fail(rc, "global client logger was not used"); diff --git a/integration-tests/rest-client-reactive/src/main/java/io/quarkus/it/rest/client/main/MyClientLogger.java b/integration-tests/rest-client-reactive/src/main/java/io/quarkus/it/rest/client/main/MyClientLogger.java index 2e8c4cd8dc635..cc22d15b31a79 100644 --- a/integration-tests/rest-client-reactive/src/main/java/io/quarkus/it/rest/client/main/MyClientLogger.java +++ b/integration-tests/rest-client-reactive/src/main/java/io/quarkus/it/rest/client/main/MyClientLogger.java @@ -12,7 +12,7 @@ @ApplicationScoped public class MyClientLogger implements ClientLogger { - public final AtomicBoolean used = new AtomicBoolean(false); + private final AtomicBoolean used = new AtomicBoolean(false); @Override public void setBodySize(int bodySize) { From 5cffe27f653efd69b48e56051152db5117712b52 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 8 Feb 2024 09:46:50 +0200 Subject: [PATCH 2/2] Slightly improve of ClientLogger --- docs/src/main/asciidoc/rest-client-reactive.adoc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/src/main/asciidoc/rest-client-reactive.adoc b/docs/src/main/asciidoc/rest-client-reactive.adoc index 21e3b34086a45..7203210e58b95 100644 --- a/docs/src/main/asciidoc/rest-client-reactive.adoc +++ b/docs/src/main/asciidoc/rest-client-reactive.adoc @@ -1681,7 +1681,14 @@ quarkus.rest-client.logging.body-limit=50 quarkus.log.category."org.jboss.resteasy.reactive.client.logging".level=DEBUG ---- -TIP: REST Client Reactive uses a default `ClientLogger` implementation. You can change it by providing a custom `ClientLogger` instance through CDI or when programmatically creating your client. +[TIP] +==== +REST Client Reactive uses a default `ClientLogger` implementation, which can be swapped out for a custom implementation. + +When setting up the client programmatically using the `QuarkusRestClientBuilder`, the `ClientLogger` is set via the `clientLogger` method. + +For declarative clients using `@RegisterRestClient`, simply providing a CDI bean that implements `ClientLogger` is enough for that logger to be used by said clients. +==== == Mocking the client for tests If you use a client injected with the `@RestClient` annotation, you can easily mock it for tests.