Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ClientLogger beans unremovable #38670

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/src/main/asciidoc/rest-client-reactive.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,14 @@
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.

Check warning on line 1688 in docs/src/main/asciidoc/rest-client-reactive.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'by using' or 'that uses' rather than 'using'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'by using' or 'that uses' rather than 'using'.", "location": {"path": "docs/src/main/asciidoc/rest-client-reactive.adoc", "range": {"start": {"line": 1688, "column": 44}}}, "severity": "INFO"}

Check warning on line 1688 in docs/src/main/asciidoc/rest-client-reactive.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsWarnings] Consider using 'through', 'by', 'from', 'on', or 'by using' rather than 'via' unless updating existing content that uses the term. Raw Output: {"message": "[Quarkus.TermsWarnings] Consider using 'through', 'by', 'from', 'on', or 'by using' rather than 'via' unless updating existing content that uses the term.", "location": {"path": "docs/src/main/asciidoc/rest-client-reactive.adoc", "range": {"start": {"line": 1688, "column": 109}}}, "severity": "WARNING"}

For declarative clients using `@RegisterRestClient`, simply providing a CDI bean that implements `ClientLogger` is enough for that logger to be used by said clients.

Check warning on line 1690 in docs/src/main/asciidoc/rest-client-reactive.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'by using' or 'that uses' rather than 'using'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'by using' or 'that uses' rather than 'using'.", "location": {"path": "docs/src/main/asciidoc/rest-client-reactive.adoc", "range": {"start": {"line": 1690, "column": 24}}}, "severity": "INFO"}
====

== Mocking the client for tests
If you use a client injected with the `@RestClient` annotation, you can easily mock it for tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -179,8 +180,8 @@ void setupAdditionalBeans(BuildProducer<AdditionalBeanBuildItem> additionalBeans
}

@BuildStep
UnremovableBeanBuildItem makeConfigUnremovable() {
return UnremovableBeanBuildItem.beanTypes(RestClientsConfig.class);
UnremovableBeanBuildItem unremovableBeans() {
return UnremovableBeanBuildItem.beanTypes(RestClientsConfig.class, ClientLogger.class);
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,9 +63,6 @@ public class ClientCallingResource {
@Inject
InMemorySpanExporter inMemorySpanExporter;

@Inject
MyClientLogger globalClientLogger;

void init(@Observes Router router) {
router.post().handler(BodyHandler.create());

Expand All @@ -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");
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading