Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the way Resteasy injection is initialized #17651

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}