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

Allow injection of Lambda types into JAX-RS methods via @Context in RESTEasy Reactive #24195

Merged
merged 1 commit into from
Mar 13, 2022
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
6 changes: 5 additions & 1 deletion extensions/amazon-lambda-http/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-amazon-lambda-http-event-server</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-server-spi-deployment</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand All @@ -56,4 +60,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import static io.vertx.core.file.impl.FileResolverImpl.CACHE_DIR_BASE_PROP_NAME;

import org.jboss.jandex.DotName;
import org.jboss.logging.Logger;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPResponse;

Expand All @@ -16,16 +18,22 @@
import io.quarkus.amazon.lambda.http.model.Headers;
import io.quarkus.amazon.lambda.http.model.MultiValuedTreeMap;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.SystemPropertyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
import io.quarkus.resteasy.reactive.server.spi.ContextTypeBuildItem;
import io.quarkus.vertx.http.deployment.RequireVirtualHttpBuildItem;

public class AmazonLambdaHttpProcessor {
private static final Logger log = Logger.getLogger(AmazonLambdaHttpProcessor.class);
public static final DotName CONTEXT = DotName.createSimple(Context.class.getName());
public static final DotName API_GATEWAY_HTTP_EVENT = DotName.createSimple(APIGatewayV2HTTPEvent.class.getName());
public static final DotName REQUEST_CONTEXT = DotName.createSimple(
APIGatewayV2HTTPEvent.RequestContext.class.getName());

@BuildStep
public void setupCDI(BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
Expand Down Expand Up @@ -96,4 +104,14 @@ public void generateScripts(OutputTargetBuildItem target,
LambdaUtil.writeFile(target, "sam.native.yaml", output);
}

@BuildStep
public void resteasyReactiveIntegration(BuildProducer<ContextTypeBuildItem> contextTypeProducer,
BuildProducer<UnremovableBeanBuildItem> unremovableBeanProducer) {
contextTypeProducer.produce(new ContextTypeBuildItem(CONTEXT));
contextTypeProducer.produce(new ContextTypeBuildItem(API_GATEWAY_HTTP_EVENT));
contextTypeProducer.produce(new ContextTypeBuildItem(REQUEST_CONTEXT));

unremovableBeanProducer.produce(UnremovableBeanBuildItem.beanTypes(CONTEXT, API_GATEWAY_HTTP_EVENT, REQUEST_CONTEXT));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -142,6 +143,7 @@
import io.quarkus.resteasy.reactive.server.runtime.security.EagerSecurityHandler;
import io.quarkus.resteasy.reactive.server.runtime.security.SecurityContextOverrideHandler;
import io.quarkus.resteasy.reactive.server.spi.AnnotationsTransformerBuildItem;
import io.quarkus.resteasy.reactive.server.spi.ContextTypeBuildItem;
import io.quarkus.resteasy.reactive.server.spi.MethodScannerBuildItem;
import io.quarkus.resteasy.reactive.server.spi.NonBlockingReturnTypeBuildItem;
import io.quarkus.resteasy.reactive.spi.CustomExceptionMapperBuildItem;
Expand Down Expand Up @@ -355,6 +357,7 @@ public void setupEndpoints(ApplicationIndexBuildItem applicationIndexBuildItem,
List<ApplicationClassPredicateBuildItem> applicationClassPredicateBuildItems,
List<MethodScannerBuildItem> methodScanners,
List<AnnotationsTransformerBuildItem> annotationTransformerBuildItems,
List<ContextTypeBuildItem> contextTypeBuildItems,
Capabilities capabilities)
throws NoSuchMethodException {

Expand Down Expand Up @@ -412,7 +415,7 @@ public void setupEndpoints(ApplicationIndexBuildItem applicationIndexBuildItem,
methodScanners.stream().map(MethodScannerBuildItem::getMethodScanner).collect(toList()))
.setIndex(index)
.setApplicationIndex(applicationIndexBuildItem.getIndex())
.addContextTypes(CONTEXT_TYPES)
.addContextTypes(additionalContextTypes(contextTypeBuildItems))
.setFactoryCreator(new QuarkusFactoryCreator(recorder, beanContainerBuildItem.getValue()))
.setEndpointInvokerFactory(
new QuarkusInvokerFactory(generatedClassBuildItemBuildProducer, recorder))
Expand Down Expand Up @@ -601,6 +604,18 @@ private boolean hasAnnotation(MethodInfo method, short paramPosition, DotName an
handleDateFormatReflection(reflectiveClass, index);
}

private Collection<DotName> additionalContextTypes(List<ContextTypeBuildItem> contextTypeBuildItems) {
if (contextTypeBuildItems.isEmpty()) {
return CONTEXT_TYPES;
}
Set<DotName> contextTypes = new HashSet<>(CONTEXT_TYPES.size() + contextTypeBuildItems.size());
contextTypes.addAll(CONTEXT_TYPES);
for (ContextTypeBuildItem bi : contextTypeBuildItems) {
contextTypes.add(bi.getType());
}
return contextTypes;
}

private void handleDateFormatReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, IndexView index) {
Collection<AnnotationInstance> dateFormatInstances = index.getAnnotations(DATE_FORMAT);
if (dateFormatInstances.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.resteasy.reactive.server.spi;

import javax.ws.rs.core.Context;

import org.jboss.jandex.DotName;

import io.quarkus.builder.item.MultiBuildItem;

/**
* Register types that should be available for injection into JAX-RS methods via {@link Context}
*/
public final class ContextTypeBuildItem extends MultiBuildItem {

private final DotName type;

public ContextTypeBuildItem(DotName className) {
this.type = className;
}

public DotName getType() {
return type;
}
}