Skip to content

Commit

Permalink
Change the way Resteasy injection is initialized
Browse files Browse the repository at this point in the history
Fixes quarkusio#17628

(cherry picked from commit 7abd7de)
  • Loading branch information
stuartwdouglas authored and gsmet committed Jun 3, 2021
1 parent 70c3b13 commit 41856fa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
import io.quarkus.deployment.Capability;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Consume;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.AdditionalStaticInitConfigSourceProviderBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.ProxyUnwrapperBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.util.ServiceUtil;
import io.quarkus.resteasy.common.runtime.ResteasyInjectorFactoryRecorder;
Expand Down Expand Up @@ -148,16 +148,11 @@ void setupGzipProviders(BuildProducer<ResteasyJaxrsProviderBuildItem> providers)
}

@Record(STATIC_INIT)
@Consume(BeanContainerBuildItem.class)
@BuildStep
ResteasyInjectionReadyBuildItem setupResteasyInjection(List<ProxyUnwrapperBuildItem> proxyUnwrappers,
BeanContainerBuildItem beanContainerBuildItem,
Capabilities capabilities,
ResteasyInjectionReadyBuildItem setupResteasyInjection(
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);
RuntimeValue<InjectorFactory> injectorFactory = recorder.setup();
return new ResteasyInjectionReadyBuildItem(injectorFactory);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.resteasy.common.runtime;

import java.lang.reflect.Constructor;
import java.util.function.Supplier;

import javax.ws.rs.WebApplicationException;

Expand All @@ -10,11 +11,12 @@
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse;

import io.quarkus.arc.runtime.BeanContainer;
import io.quarkus.arc.Arc;
import io.quarkus.arc.InstanceHandle;

public class QuarkusConstructorInjector implements ConstructorInjector {

private volatile BeanContainer.Factory<?> factory;
private volatile Supplier<? extends InstanceHandle<?>> factory;

private final ConstructorInjector delegate;

Expand All @@ -27,31 +29,27 @@ public QuarkusConstructorInjector(Constructor<?> ctor, ConstructorInjector deleg

@Override
public Object construct(boolean unwrapAsync) {
if (QuarkusInjectorFactory.CONTAINER == null) {
return this.delegate.construct(unwrapAsync);
}
if (factory == null) {
factory = QuarkusInjectorFactory.CONTAINER.instanceFactory(this.ctor.getDeclaringClass());
if (factory != null) {
return factory.get().get();
}
factory = Arc.container().instanceSupplier(this.ctor.getDeclaringClass());
if (factory == null) {
return delegate.construct(unwrapAsync);
}
return factory.create().get();
return factory.get().get();
}

@Override
public Object construct(HttpRequest request, HttpResponse response, boolean unwrapAsync)
throws Failure, WebApplicationException, ApplicationException {
if (QuarkusInjectorFactory.CONTAINER == null) {
return delegate.construct(request, response, unwrapAsync);
}
if (factory == null) {
factory = QuarkusInjectorFactory.CONTAINER.instanceFactory(this.ctor.getDeclaringClass());
if (factory != null) {
return factory.get().get();
}
factory = Arc.container().instanceSupplier(this.ctor.getDeclaringClass());
if (factory == null) {
return delegate.construct(request, response, unwrapAsync);
}
return factory.create().get();
return factory.get().get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
import org.jboss.resteasy.spi.metadata.ResourceClass;
import org.jboss.resteasy.spi.metadata.ResourceConstructor;

import io.quarkus.arc.runtime.BeanContainer;
import io.quarkus.arc.runtime.ClientProxyUnwrapper;

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;
static final Function<Object, Object> PROXY_UNWRAPPER = new ClientProxyUnwrapper();

@SuppressWarnings("rawtypes")
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
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 ResteasyInjectorFactoryRecorder {

public RuntimeValue<InjectorFactory> setup(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;
}
};
public RuntimeValue<InjectorFactory> setup() {
return new RuntimeValue<>(new QuarkusInjectorFactory());
}
}

0 comments on commit 41856fa

Please sign in to comment.