Skip to content

Commit

Permalink
Prevent double registration of MpPublisherMessageBodyReader in rest c…
Browse files Browse the repository at this point in the history
…lient

Fixes: quarkusio#17627
(cherry picked from commit caf5236)
  • Loading branch information
geoand authored and gsmet committed Jun 3, 2021
1 parent 41856fa commit ab84907
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.quarkus.restclient.deployment;

import io.quarkus.builder.item.MultiBuildItem;

/**
* Used to ignore providers that were discovered via the common lookup mechanisms
* but for one reason or another should not be applied to the rest client
*/
final class IgnoreClientProviderBuildItem extends MultiBuildItem {

private final String providerClassName;

public IgnoreClientProviderBuildItem(String providerClassName) {
this.providerClassName = providerClassName;
}

public String getProviderClassName() {
return providerClassName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.jboss.resteasy.microprofile.client.DefaultResponseExceptionMapper;
import org.jboss.resteasy.microprofile.client.RestClientProxy;
import org.jboss.resteasy.microprofile.client.async.AsyncInterceptorRxInvokerProvider;
import org.jboss.resteasy.microprofile.client.publisher.MpPublisherMessageBodyReader;
import org.jboss.resteasy.spi.ResteasyConfiguration;

import io.quarkus.arc.BeanDestroyer;
Expand Down Expand Up @@ -420,14 +421,26 @@ private String getAnnotationParameter(ClassInfo classInfo, String parameterName)
return value.asString();
}

@BuildStep
IgnoreClientProviderBuildItem ignoreMPPublisher() {
// hack to remove a provider that is manually registered QuarkusRestClientBuilder
return new IgnoreClientProviderBuildItem(MpPublisherMessageBodyReader.class.getName());
}

@BuildStep
@Record(ExecutionTime.STATIC_INIT)
void registerProviders(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
JaxrsProvidersToRegisterBuildItem jaxrsProvidersToRegisterBuildItem,
List<IgnoreClientProviderBuildItem> ignoreClientProviderBuildItems,
CombinedIndexBuildItem combinedIndexBuildItem,
ResteasyInjectionReadyBuildItem injectorFactory,
RestClientRecorder restClientRecorder) {

for (IgnoreClientProviderBuildItem item : ignoreClientProviderBuildItems) {
jaxrsProvidersToRegisterBuildItem.getProviders().remove(item.getProviderClassName());
jaxrsProvidersToRegisterBuildItem.getContributedProviders().remove(item.getProviderClassName());
}

restClientRecorder.initializeResteasyProviderFactory(injectorFactory.getInjectorFactory(),
jaxrsProvidersToRegisterBuildItem.useBuiltIn(),
jaxrsProvidersToRegisterBuildItem.getProviders(), jaxrsProvidersToRegisterBuildItem.getContributedProviders());
Expand Down

0 comments on commit ab84907

Please sign in to comment.