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 quarkusio#2773
  • Loading branch information
geoand committed Sep 27, 2019
1 parent 9b52fcf commit 729114b
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.resteasy.server.common.deployment.ResteasyInjectionReadyBuildItem;
import io.quarkus.resteasy.common.deployment.ResteasyInjectionReadyBuildItem;
import io.quarkus.resteasy.server.common.deployment.ResteasyServerConfigBuildItem;

public class AmazonLambdaResteasyProcessor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import io.quarkus.restclient.runtime.RestClientRecorder;
import io.quarkus.resteasy.common.deployment.JaxrsProvidersToRegisterBuildItem;
import io.quarkus.resteasy.common.deployment.ResteasyDotNames;
import io.quarkus.resteasy.common.deployment.ResteasyInjectionReadyBuildItem;

class RestClientProcessor {
private static final Logger log = Logger.getLogger(RestClientProcessor.class);
Expand Down Expand Up @@ -284,8 +285,11 @@ private String getBaseUri(ClassInfo classInfo) {
void registerProviders(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
JaxrsProvidersToRegisterBuildItem jaxrsProvidersToRegisterBuildItem,
CombinedIndexBuildItem combinedIndexBuildItem,
ResteasyInjectionReadyBuildItem injectorFactory,
RestClientRecorder restClientRecorder) {
restClientRecorder.initializeResteasyProviderFactory(jaxrsProvidersToRegisterBuildItem.useBuiltIn(),

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

// register the providers for reflection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
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.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;

@Recorder
Expand All @@ -24,7 +26,8 @@ public void setSslEnabled(boolean sslEnabled) {
RestClientBuilderImpl.setSslEnabled(sslEnabled);
}

public void initializeResteasyProviderFactory(boolean useBuiltIn, Set<String> providersToRegister,
public void initializeResteasyProviderFactory(RuntimeValue<InjectorFactory> injectorFactory, boolean useBuiltIn,
Set<String> providersToRegister,
Set<String> contributedProviders) {
ResteasyProviderFactory clientProviderFactory = new ResteasyProviderFactoryImpl(null, true) {
@Override
Expand All @@ -37,6 +40,11 @@ protected void initializeUtils() {
clientHelper = new ClientHelper(this);
serverHelper = NOOPServerHelper.INSTANCE;
}

@Override
public InjectorFactory getInjectorFactory() {
return injectorFactory.getValue();
}
};

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

import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;

import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
Expand All @@ -26,15 +30,21 @@
import org.jboss.resteasy.plugins.interceptors.GZIPDecodingInterceptor;
import org.jboss.resteasy.plugins.interceptors.GZIPEncodingInterceptor;
import org.jboss.resteasy.plugins.providers.StringTextStar;
import org.jboss.resteasy.spi.InjectorFactory;

import io.quarkus.arc.deployment.BeanArchiveIndexBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.ProxyUnwrapperBuildItem;
import io.quarkus.deployment.builditem.substrate.ReflectiveClassBuildItem;
import io.quarkus.deployment.util.ServiceUtil;
import io.quarkus.resteasy.common.runtime.ResteasyInjectorFactoryRecorder;
import io.quarkus.resteasy.common.spi.ResteasyJaxrsProviderBuildItem;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;
Expand Down Expand Up @@ -90,6 +100,19 @@ void setupGzipProviders(BuildProducer<ResteasyJaxrsProviderBuildItem> providers)
}
}

@Record(STATIC_INIT)
@BuildStep
ResteasyInjectionReadyBuildItem setupResteasyInjection(List<ProxyUnwrapperBuildItem> proxyUnwrappers,
BeanContainerBuildItem beanContainerBuildItem,
ResteasyInjectorFactoryRecorder recorder) {
List<Function<Object, Object>> unwrappers = new ArrayList<>();
for (ProxyUnwrapperBuildItem i : proxyUnwrappers) {
unwrappers.add(i.getUnwrapper());
}
RuntimeValue<InjectorFactory> injectorFactory = recorder.setup(beanContainerBuildItem.getValue(), unwrappers);
return new ResteasyInjectionReadyBuildItem(injectorFactory);
}

@BuildStep
JaxrsProvidersToRegisterBuildItem setupProviders(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
CombinedIndexBuildItem indexBuildItem,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.resteasy.common.deployment;

import org.jboss.resteasy.spi.InjectorFactory;

import io.quarkus.builder.item.SimpleBuildItem;
import io.quarkus.runtime.RuntimeValue;

/**
* Gives access to the configured {@link InjectorFactory}
* Can also be used as a marker indicating the RESTEasy injection has been properly set up
*/
public final class ResteasyInjectionReadyBuildItem extends SimpleBuildItem {

private final RuntimeValue<InjectorFactory> injectorFactory;

public ResteasyInjectionReadyBuildItem(RuntimeValue<InjectorFactory> injectorFactory) {
this.injectorFactory = injectorFactory;
}

public RuntimeValue<InjectorFactory> getInjectorFactory() {
return injectorFactory;
}
}
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 Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package io.quarkus.resteasy.server.common.runtime;
package io.quarkus.resteasy.common.runtime;

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

import org.jboss.resteasy.spi.InjectorFactory;

import io.quarkus.arc.runtime.BeanContainer;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;

@Recorder
public class ResteasyServerCommonRecorder {
public class ResteasyInjectorFactoryRecorder {

public void setupIntegration(BeanContainer container, List<Function<Object, Object>> propertyUnwrappers) {
public RuntimeValue<InjectorFactory> setup(BeanContainer container, List<Function<Object, Object>> propertyUnwrappers) {
QuarkusInjectorFactory.CONTAINER = container;
QuarkusInjectorFactory.PROXY_UNWRAPPER = new Function<Object, Object>() {
@Override
Expand All @@ -21,5 +24,6 @@ public Object apply(Object o) {
return res;
}
};
return new RuntimeValue<>(new QuarkusInjectorFactory());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.quarkus.resteasy.server.common.deployment;

import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT;
import static io.quarkus.runtime.annotations.ConfigPhase.BUILD_TIME;

import java.lang.reflect.Modifier;
Expand All @@ -14,7 +13,6 @@
import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.jboss.jandex.AnnotationInstance;
Expand Down Expand Up @@ -45,7 +43,6 @@
import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem;
import io.quarkus.arc.deployment.AutoInjectAnnotationBuildItem;
import io.quarkus.arc.deployment.BeanArchiveIndexBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.arc.deployment.BeanDefiningAnnotationBuildItem;
import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
import io.quarkus.arc.deployment.UnremovableBeanBuildItem.BeanClassNameExclusion;
Expand All @@ -55,10 +52,8 @@
import io.quarkus.arc.processor.Transformation;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.BytecodeTransformerBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.ProxyUnwrapperBuildItem;
import io.quarkus.deployment.builditem.substrate.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.substrate.ReflectiveHierarchyBuildItem;
import io.quarkus.deployment.builditem.substrate.RuntimeInitializedClassBuildItem;
Expand All @@ -69,8 +64,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.server.common.runtime.ResteasyServerCommonRecorder;
import io.quarkus.resteasy.common.runtime.QuarkusInjectorFactory;
import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceDefiningAnnotationBuildItem;
import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceMethodAnnotationsBuildItem;
import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceMethodParamAnnotations;
Expand Down Expand Up @@ -390,20 +384,6 @@ void processPathInterfaceImplementors(CombinedIndexBuildItem combinedIndexBuildI
}
}

@Record(STATIC_INIT)
@BuildStep
ResteasyInjectionReadyBuildItem setupInjection(ResteasyServerCommonRecorder recorder,
BeanContainerBuildItem beanContainerBuildItem,
List<ProxyUnwrapperBuildItem> proxyUnwrappers) {
List<Function<Object, Object>> unwrappers = new ArrayList<>();
for (ProxyUnwrapperBuildItem i : proxyUnwrappers) {
unwrappers.add(i.getUnwrapper());
}
recorder.setupIntegration(beanContainerBuildItem.getValue(), unwrappers);

return new ResteasyInjectionReadyBuildItem();
}

@BuildStep
void beanDefiningAnnotations(BuildProducer<BeanDefiningAnnotationBuildItem> beanDefiningAnnotations) {
beanDefiningAnnotations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.substrate.ReflectiveClassBuildItem;
import io.quarkus.resteasy.common.deployment.ResteasyInjectionReadyBuildItem;
import io.quarkus.resteasy.runtime.ExceptionMapperRecorder;
import io.quarkus.resteasy.runtime.ResteasyFilter;
import io.quarkus.resteasy.server.common.deployment.ResteasyInjectionReadyBuildItem;
import io.quarkus.resteasy.server.common.deployment.ResteasyServerConfigBuildItem;
import io.quarkus.undertow.deployment.FilterBuildItem;
import io.quarkus.undertow.deployment.ServletBuildItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.resteasy.common.deployment.ResteasyInjectionReadyBuildItem;
import io.quarkus.resteasy.runtime.standalone.ResteasyStandaloneRecorder;
import io.quarkus.resteasy.server.common.deployment.ResteasyDeploymentBuildItem;
import io.quarkus.resteasy.server.common.deployment.ResteasyInjectionReadyBuildItem;
import io.quarkus.undertow.deployment.KnownPathsBuildItem;
import io.quarkus.undertow.deployment.StaticResourceFilesBuildItem;
import io.quarkus.vertx.core.deployment.InternalWebVertxBuildItem;
Expand Down

0 comments on commit 729114b

Please sign in to comment.