Skip to content

Commit

Permalink
Ensure that resteasy rest-client uses QuarkusInjectorFactory as well
Browse files Browse the repository at this point in the history
This is done in order to have providers as beans - same as is the case for
resteasy server.

Fixes #2773
  • Loading branch information
geoand committed Sep 27, 2019
1 parent 9b52fcf commit 7707e7d
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -284,8 +287,17 @@ private String getBaseUri(ClassInfo classInfo) {
void registerProviders(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
JaxrsProvidersToRegisterBuildItem jaxrsProvidersToRegisterBuildItem,
CombinedIndexBuildItem combinedIndexBuildItem,
BeanContainerBuildItem beanContainerBuildItem,
List<ProxyUnwrapperBuildItem> proxyUnwrappers,
RestClientRecorder restClientRecorder) {
restClientRecorder.initializeResteasyProviderFactory(jaxrsProvidersToRegisterBuildItem.useBuiltIn(),

List<Function<Object, Object>> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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
Expand All @@ -24,8 +30,12 @@ public void setSslEnabled(boolean sslEnabled) {
RestClientBuilderImpl.setSslEnabled(sslEnabled);
}

public void initializeResteasyProviderFactory(boolean useBuiltIn, Set<String> providersToRegister,
public void initializeResteasyProviderFactory(BeanContainer beanContainer,
List<Function<Object, Object>> propertyUnwrappers, boolean useBuiltIn,
Set<String> providersToRegister,
Set<String> contributedProviders) {
QuarkusInjectorFactory.CONTAINER = beanContainer;
QuarkusInjectorFactory.PROXY_UNWRAPPER = new ProxyUnwrapperFunction(propertyUnwrappers);
ResteasyProviderFactory clientProviderFactory = new ResteasyProviderFactoryImpl(null, true) {
@Override
public RuntimeType getRuntimeType() {
Expand All @@ -37,6 +47,11 @@ protected void initializeUtils() {
clientHelper = new ClientHelper(this);
serverHelper = NOOPServerHelper.INSTANCE;
}

@Override
public InjectorFactory getInjectorFactory() {
return new QuarkusInjectorFactory();
}
};

if (useBuiltIn) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkus.resteasy.common.runtime;

import java.util.List;
import java.util.function.Function;

public class ProxyUnwrapperFunction implements Function<Object, Object> {

private final List<Function<Object, Object>> propertyUnwrappers;

public ProxyUnwrapperFunction(List<Function<Object, Object>> propertyUnwrappers) {
this.propertyUnwrappers = propertyUnwrappers;
}

@Override
public Object apply(Object o) {
Object res = o;
for (Function<Object, Object> i : propertyUnwrappers) {
res = i.apply(res);
}
return res;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Object, Object> PROXY_UNWRAPPER;
public static volatile BeanContainer CONTAINER = null;
public static volatile Function<Object, Object> PROXY_UNWRAPPER;

@SuppressWarnings("rawtypes")
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@
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
public class ResteasyServerCommonRecorder {

public void setupIntegration(BeanContainer container, List<Function<Object, Object>> propertyUnwrappers) {
QuarkusInjectorFactory.CONTAINER = container;
QuarkusInjectorFactory.PROXY_UNWRAPPER = new Function<Object, Object>() {
@Override
public Object apply(Object o) {
Object res = o;
for (Function<Object, Object> i : propertyUnwrappers) {
res = i.apply(res);
}
return res;
}
};
QuarkusInjectorFactory.PROXY_UNWRAPPER = new ProxyUnwrapperFunction(propertyUnwrappers);
}
}

0 comments on commit 7707e7d

Please sign in to comment.