Skip to content

Commit

Permalink
Merge pull request #12840 from patriot1burke/aws-context
Browse files Browse the repository at this point in the history
propagate aws context resteasy standalone #12190
  • Loading branch information
stuartwdouglas authored Oct 22, 2020
2 parents 01fe8bb + 94e7b8b commit a1e04eb
Show file tree
Hide file tree
Showing 5 changed files with 634 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.quarkus.amazon.lambda.http.model.Headers;
import io.quarkus.netty.runtime.virtual.VirtualClientConnection;
import io.quarkus.netty.runtime.virtual.VirtualResponseHandler;
import io.quarkus.vertx.http.runtime.QuarkusHttpHeaders;
import io.quarkus.vertx.http.runtime.VertxHttpRecorder;

@SuppressWarnings("unused")
Expand All @@ -56,7 +57,7 @@ public AwsProxyResponse handleRequest(AwsProxyRequest request, Context context)
}

try {
return nettyDispatch(clientAddress, request);
return nettyDispatch(clientAddress, request, context);
} catch (Exception e) {
log.error("Request Failure", e);
return new AwsProxyResponse(500, errorHeaders, "{ \"message\": \"Internal Server Error\" }");
Expand Down Expand Up @@ -145,7 +146,8 @@ public void close() {
}
}

private AwsProxyResponse nettyDispatch(InetSocketAddress clientAddress, AwsProxyRequest request) throws Exception {
private AwsProxyResponse nettyDispatch(InetSocketAddress clientAddress, AwsProxyRequest request, Context context)
throws Exception {
String path = request.getPath();
//log.info("---- Got lambda request: " + path);
if (request.getMultiValueQueryStringParameters() != null && !request.getMultiValueQueryStringParameters().isEmpty()) {
Expand All @@ -172,8 +174,10 @@ private AwsProxyResponse nettyDispatch(InetSocketAddress clientAddress, AwsProxy
}
path = sb.toString();
}
QuarkusHttpHeaders quarkusHeaders = new QuarkusHttpHeaders();
quarkusHeaders.setContextObject(Context.class, context);
DefaultHttpRequest nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1,
HttpMethod.valueOf(request.getHttpMethod()), path);
HttpMethod.valueOf(request.getHttpMethod()), path, quarkusHeaders);
if (request.getMultiValueHeaders() != null) { //apparently this can be null if no headers are sent
for (Map.Entry<String, List<String>> header : request.getMultiValueHeaders().entrySet()) {
nettyRequest.headers().add(header.getKey(), header.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.concurrent.Executor;

import javax.enterprise.inject.Instance;
Expand All @@ -22,10 +23,12 @@
import io.quarkus.runtime.BlockingOperationControl;
import io.quarkus.security.identity.CurrentIdentityAssociation;
import io.quarkus.vertx.http.runtime.CurrentVertxRequest;
import io.quarkus.vertx.http.runtime.QuarkusHttpHeaders;
import io.quarkus.vertx.http.runtime.VertxInputStream;
import io.quarkus.vertx.http.runtime.security.QuarkusHttpUser;
import io.vertx.core.Context;
import io.vertx.core.Handler;
import io.vertx.core.MultiMap;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
Expand Down Expand Up @@ -128,6 +131,12 @@ private void dispatch(RoutingContext routingContext, InputStream is, VertxOutput
try {
ResteasyContext.pushContext(SecurityContext.class, new QuarkusResteasySecurityContext(request, routingContext));
ResteasyContext.pushContext(RoutingContext.class, routingContext);
MultiMap qheaders = routingContext.request().headers();
if (qheaders instanceof QuarkusHttpHeaders) {
for (Map.Entry<Class<?>, Object> entry : ((QuarkusHttpHeaders) qheaders).getContextObjects().entrySet()) {
ResteasyContext.pushContext((Class) entry.getKey(), entry.getValue());
}
}
dispatcher.service(ctx, request, response, vertxRequest, vertxResponse, true);
} catch (Failure e1) {
vertxResponse.setStatus(e1.getErrorCode());
Expand Down
Loading

0 comments on commit a1e04eb

Please sign in to comment.