From 7707e7d3c946d6c71deecc61ecaa4afb8d5ff2a8 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Fri, 27 Sep 2019 09:20:42 +0300 Subject: [PATCH] Ensure that resteasy rest-client uses QuarkusInjectorFactory as well This is done in order to have providers as beans - same as is the case for resteasy server. Fixes #2773 --- .../deployment/RestClientProcessor.java | 14 +++++++++++- .../runtime/RestClientRecorder.java | 17 +++++++++++++- .../runtime/ProxyUnwrapperFunction.java | 22 +++++++++++++++++++ .../runtime/QuarkusConstructorInjector.java | 2 +- .../runtime/QuarkusInjectorFactory.java | 6 ++--- .../ResteasyServerCommonProcessor.java | 2 +- .../runtime/ResteasyServerCommonRecorder.java | 13 +++-------- 7 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 extensions/resteasy-common/runtime/src/main/java/io/quarkus/resteasy/common/runtime/ProxyUnwrapperFunction.java rename extensions/{resteasy-server-common/runtime/src/main/java/io/quarkus/resteasy/server => resteasy-common/runtime/src/main/java/io/quarkus/resteasy}/common/runtime/QuarkusConstructorInjector.java (97%) rename extensions/{resteasy-server-common/runtime/src/main/java/io/quarkus/resteasy/server => resteasy-common/runtime/src/main/java/io/quarkus/resteasy}/common/runtime/QuarkusInjectorFactory.java (94%) diff --git a/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientProcessor.java b/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientProcessor.java index 996c738d634d08..0477e88d4a7390 100644 --- a/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientProcessor.java +++ b/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientProcessor.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.function.Function; import javax.ws.rs.Path; import javax.ws.rs.client.ClientRequestFilter; @@ -44,6 +45,7 @@ import org.jboss.resteasy.spi.ResteasyConfiguration; import io.quarkus.arc.deployment.AdditionalBeanBuildItem; +import io.quarkus.arc.deployment.BeanContainerBuildItem; import io.quarkus.arc.deployment.BeanRegistrarBuildItem; import io.quarkus.arc.processor.BeanConfigurator; import io.quarkus.arc.processor.BeanRegistrar; @@ -56,6 +58,7 @@ import io.quarkus.deployment.builditem.CombinedIndexBuildItem; import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.ProxyUnwrapperBuildItem; import io.quarkus.deployment.builditem.SslNativeConfigBuildItem; import io.quarkus.deployment.builditem.substrate.ReflectiveClassBuildItem; import io.quarkus.deployment.builditem.substrate.ReflectiveHierarchyBuildItem; @@ -284,8 +287,17 @@ private String getBaseUri(ClassInfo classInfo) { void registerProviders(BuildProducer reflectiveClass, JaxrsProvidersToRegisterBuildItem jaxrsProvidersToRegisterBuildItem, CombinedIndexBuildItem combinedIndexBuildItem, + BeanContainerBuildItem beanContainerBuildItem, + List proxyUnwrappers, RestClientRecorder restClientRecorder) { - restClientRecorder.initializeResteasyProviderFactory(jaxrsProvidersToRegisterBuildItem.useBuiltIn(), + + List> unwrappers = new ArrayList<>(); + for (ProxyUnwrapperBuildItem i : proxyUnwrappers) { + unwrappers.add(i.getUnwrapper()); + } + + restClientRecorder.initializeResteasyProviderFactory(beanContainerBuildItem.getValue(), unwrappers, + jaxrsProvidersToRegisterBuildItem.useBuiltIn(), jaxrsProvidersToRegisterBuildItem.getProviders(), jaxrsProvidersToRegisterBuildItem.getContributedProviders()); // register the providers for reflection diff --git a/extensions/rest-client/runtime/src/main/java/io/quarkus/restclient/runtime/RestClientRecorder.java b/extensions/rest-client/runtime/src/main/java/io/quarkus/restclient/runtime/RestClientRecorder.java index 25c119b4b90861..aaed707ef79927 100644 --- a/extensions/rest-client/runtime/src/main/java/io/quarkus/restclient/runtime/RestClientRecorder.java +++ b/extensions/rest-client/runtime/src/main/java/io/quarkus/restclient/runtime/RestClientRecorder.java @@ -1,6 +1,8 @@ package io.quarkus.restclient.runtime; +import java.util.List; import java.util.Set; +import java.util.function.Function; import javax.ws.rs.RuntimeType; @@ -10,8 +12,12 @@ import org.jboss.resteasy.core.providerfactory.ResteasyProviderFactoryImpl; import org.jboss.resteasy.microprofile.client.RestClientBuilderImpl; import org.jboss.resteasy.plugins.providers.RegisterBuiltin; +import org.jboss.resteasy.spi.InjectorFactory; import org.jboss.resteasy.spi.ResteasyProviderFactory; +import io.quarkus.arc.runtime.BeanContainer; +import io.quarkus.resteasy.common.runtime.ProxyUnwrapperFunction; +import io.quarkus.resteasy.common.runtime.QuarkusInjectorFactory; import io.quarkus.runtime.annotations.Recorder; @Recorder @@ -24,8 +30,12 @@ public void setSslEnabled(boolean sslEnabled) { RestClientBuilderImpl.setSslEnabled(sslEnabled); } - public void initializeResteasyProviderFactory(boolean useBuiltIn, Set providersToRegister, + public void initializeResteasyProviderFactory(BeanContainer beanContainer, + List> propertyUnwrappers, boolean useBuiltIn, + Set providersToRegister, Set contributedProviders) { + QuarkusInjectorFactory.CONTAINER = beanContainer; + QuarkusInjectorFactory.PROXY_UNWRAPPER = new ProxyUnwrapperFunction(propertyUnwrappers); ResteasyProviderFactory clientProviderFactory = new ResteasyProviderFactoryImpl(null, true) { @Override public RuntimeType getRuntimeType() { @@ -37,6 +47,11 @@ protected void initializeUtils() { clientHelper = new ClientHelper(this); serverHelper = NOOPServerHelper.INSTANCE; } + + @Override + public InjectorFactory getInjectorFactory() { + return new QuarkusInjectorFactory(); + } }; if (useBuiltIn) { diff --git a/extensions/resteasy-common/runtime/src/main/java/io/quarkus/resteasy/common/runtime/ProxyUnwrapperFunction.java b/extensions/resteasy-common/runtime/src/main/java/io/quarkus/resteasy/common/runtime/ProxyUnwrapperFunction.java new file mode 100644 index 00000000000000..14248122706f95 --- /dev/null +++ b/extensions/resteasy-common/runtime/src/main/java/io/quarkus/resteasy/common/runtime/ProxyUnwrapperFunction.java @@ -0,0 +1,22 @@ +package io.quarkus.resteasy.common.runtime; + +import java.util.List; +import java.util.function.Function; + +public class ProxyUnwrapperFunction implements Function { + + private final List> propertyUnwrappers; + + public ProxyUnwrapperFunction(List> propertyUnwrappers) { + this.propertyUnwrappers = propertyUnwrappers; + } + + @Override + public Object apply(Object o) { + Object res = o; + for (Function i : propertyUnwrappers) { + res = i.apply(res); + } + return res; + } +} diff --git a/extensions/resteasy-server-common/runtime/src/main/java/io/quarkus/resteasy/server/common/runtime/QuarkusConstructorInjector.java b/extensions/resteasy-common/runtime/src/main/java/io/quarkus/resteasy/common/runtime/QuarkusConstructorInjector.java similarity index 97% rename from extensions/resteasy-server-common/runtime/src/main/java/io/quarkus/resteasy/server/common/runtime/QuarkusConstructorInjector.java rename to extensions/resteasy-common/runtime/src/main/java/io/quarkus/resteasy/common/runtime/QuarkusConstructorInjector.java index 9ceea776644c9e..ac822c808f8243 100644 --- a/extensions/resteasy-server-common/runtime/src/main/java/io/quarkus/resteasy/server/common/runtime/QuarkusConstructorInjector.java +++ b/extensions/resteasy-common/runtime/src/main/java/io/quarkus/resteasy/common/runtime/QuarkusConstructorInjector.java @@ -1,4 +1,4 @@ -package io.quarkus.resteasy.server.common.runtime; +package io.quarkus.resteasy.common.runtime; import java.lang.reflect.Constructor; import java.util.concurrent.CompletableFuture; diff --git a/extensions/resteasy-server-common/runtime/src/main/java/io/quarkus/resteasy/server/common/runtime/QuarkusInjectorFactory.java b/extensions/resteasy-common/runtime/src/main/java/io/quarkus/resteasy/common/runtime/QuarkusInjectorFactory.java similarity index 94% rename from extensions/resteasy-server-common/runtime/src/main/java/io/quarkus/resteasy/server/common/runtime/QuarkusInjectorFactory.java rename to extensions/resteasy-common/runtime/src/main/java/io/quarkus/resteasy/common/runtime/QuarkusInjectorFactory.java index 51abfdd627151b..f9af97ddbb2115 100644 --- a/extensions/resteasy-server-common/runtime/src/main/java/io/quarkus/resteasy/server/common/runtime/QuarkusInjectorFactory.java +++ b/extensions/resteasy-common/runtime/src/main/java/io/quarkus/resteasy/common/runtime/QuarkusInjectorFactory.java @@ -1,4 +1,4 @@ -package io.quarkus.resteasy.server.common.runtime; +package io.quarkus.resteasy.common.runtime; import java.lang.reflect.Constructor; import java.util.concurrent.CompletionStage; @@ -23,8 +23,8 @@ public class QuarkusInjectorFactory extends InjectorFactoryImpl { private static final Logger log = Logger.getLogger("io.quarkus.resteasy.runtime"); - static volatile BeanContainer CONTAINER = null; - static volatile Function PROXY_UNWRAPPER; + public static volatile BeanContainer CONTAINER = null; + public static volatile Function PROXY_UNWRAPPER; @SuppressWarnings("rawtypes") @Override diff --git a/extensions/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java b/extensions/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java index 4eedd22e9367a1..2385a4703b3d1d 100755 --- a/extensions/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java +++ b/extensions/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java @@ -69,7 +69,7 @@ import io.quarkus.resteasy.common.deployment.JaxrsProvidersToRegisterBuildItem; import io.quarkus.resteasy.common.deployment.ResteasyCommonProcessor.ResteasyCommonConfig; import io.quarkus.resteasy.common.deployment.ResteasyDotNames; -import io.quarkus.resteasy.server.common.runtime.QuarkusInjectorFactory; +import io.quarkus.resteasy.common.runtime.QuarkusInjectorFactory; import io.quarkus.resteasy.server.common.runtime.ResteasyServerCommonRecorder; import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceDefiningAnnotationBuildItem; import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceMethodAnnotationsBuildItem; diff --git a/extensions/resteasy-server-common/runtime/src/main/java/io/quarkus/resteasy/server/common/runtime/ResteasyServerCommonRecorder.java b/extensions/resteasy-server-common/runtime/src/main/java/io/quarkus/resteasy/server/common/runtime/ResteasyServerCommonRecorder.java index 59d03742e1abd7..29339da5fdd52b 100644 --- a/extensions/resteasy-server-common/runtime/src/main/java/io/quarkus/resteasy/server/common/runtime/ResteasyServerCommonRecorder.java +++ b/extensions/resteasy-server-common/runtime/src/main/java/io/quarkus/resteasy/server/common/runtime/ResteasyServerCommonRecorder.java @@ -4,6 +4,8 @@ import java.util.function.Function; import io.quarkus.arc.runtime.BeanContainer; +import io.quarkus.resteasy.common.runtime.ProxyUnwrapperFunction; +import io.quarkus.resteasy.common.runtime.QuarkusInjectorFactory; import io.quarkus.runtime.annotations.Recorder; @Recorder @@ -11,15 +13,6 @@ public class ResteasyServerCommonRecorder { public void setupIntegration(BeanContainer container, List> propertyUnwrappers) { QuarkusInjectorFactory.CONTAINER = container; - QuarkusInjectorFactory.PROXY_UNWRAPPER = new Function() { - @Override - public Object apply(Object o) { - Object res = o; - for (Function i : propertyUnwrappers) { - res = i.apply(res); - } - return res; - } - }; + QuarkusInjectorFactory.PROXY_UNWRAPPER = new ProxyUnwrapperFunction(propertyUnwrappers); } }