use of io.quarkus.vertx.http.runtime.CurrentVertxRequest in project quarkus by quarkusio.
the class UndertowDeploymentRecorder method setupRequestScope.
public void setupRequestScope(DeploymentInfo deploymentInfo, BeanContainer beanContainer) {
CurrentVertxRequest currentVertxRequest = CDI.current().select(CurrentVertxRequest.class).get();
Instance<CurrentIdentityAssociation> identityAssociations = CDI.current().select(CurrentIdentityAssociation.class);
CurrentIdentityAssociation association;
if (identityAssociations.isResolvable()) {
association = identityAssociations.get();
} else {
association = null;
}
deploymentInfo.addThreadSetupAction(new ThreadSetupHandler() {
@Override
public <T, C> ThreadSetupHandler.Action<T, C> create(Action<T, C> action) {
return new Action<T, C>() {
@Override
public T call(HttpServerExchange exchange, C context) throws Exception {
// Not sure what to do here
ManagedContext requestContext = beanContainer.requestContext();
if (requestContext.isActive()) {
return action.call(exchange, context);
} else if (exchange == null) {
requestContext.activate();
try {
return action.call(exchange, context);
} finally {
requestContext.terminate();
}
} else {
InjectableContext.ContextState existingRequestContext = exchange.getAttachment(REQUEST_CONTEXT);
try {
requestContext.activate(existingRequestContext);
VertxHttpExchange delegate = (VertxHttpExchange) exchange.getDelegate();
RoutingContext rc = (RoutingContext) delegate.getContext();
currentVertxRequest.setCurrent(rc);
if (association != null) {
QuarkusHttpUser existing = (QuarkusHttpUser) rc.user();
if (existing != null) {
SecurityIdentity identity = existing.getSecurityIdentity();
association.setIdentity(identity);
} else {
association.setIdentity(QuarkusHttpUser.getSecurityIdentity(rc, null));
}
}
return action.call(exchange, context);
} finally {
ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
HttpServletRequestImpl req = src.getOriginalRequest();
if (req.isAsyncStarted()) {
exchange.putAttachment(REQUEST_CONTEXT, requestContext.getState());
requestContext.deactivate();
if (existingRequestContext == null) {
req.getAsyncContextInternal().addListener(new AsyncListener() {
@Override
public void onComplete(AsyncEvent event) throws IOException {
requestContext.activate(exchange.getAttachment(REQUEST_CONTEXT));
requestContext.terminate();
}
@Override
public void onTimeout(AsyncEvent event) throws IOException {
onComplete(event);
}
@Override
public void onError(AsyncEvent event) throws IOException {
onComplete(event);
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException {
}
});
}
} else {
requestContext.terminate();
}
}
}
}
};
}
});
}
use of io.quarkus.vertx.http.runtime.CurrentVertxRequest in project quarkus by quarkusio.
the class ResteasyServlet method service.
@Override
public void service(String httpMethod, HttpServletRequest request, HttpServletResponse response) throws IOException {
CurrentVertxRequest currentVertxRequest = CDI.current().select(CurrentVertxRequest.class).get();
ContextUtil.pushContext(currentVertxRequest.getCurrent());
super.service(httpMethod, request, response);
}
use of io.quarkus.vertx.http.runtime.CurrentVertxRequest in project quarkus by quarkusio.
the class ResteasyFilter method doFilter.
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) servletResponse;
HttpServletRequest request = (HttpServletRequest) servletRequest;
if (request.getMethod().equals("GET") || request.getMethod().equals("HEAD") || isCORSPreflightRequest(request)) {
// we only serve get requests from the default servlet and CORS preflight requests
filterChain.doFilter(servletRequest, new ResteasyResponseWrapper(response, request));
} else {
CurrentVertxRequest currentVertxRequest = CDI.current().select(CurrentVertxRequest.class).get();
ContextUtil.pushContext(currentVertxRequest.getCurrent());
servletContainerDispatcher.service(request.getMethod(), request, response, true);
}
}
use of io.quarkus.vertx.http.runtime.CurrentVertxRequest in project quarkus by quarkusio.
the class AwsHttpContextProducers method getContextObjects.
private Map<Class<?>, Object> getContextObjects() {
if (current == null) {
return Collections.EMPTY_MAP;
}
CurrentVertxRequest currentVertxRequest = current.get();
if (currentVertxRequest == null) {
return Collections.EMPTY_MAP;
}
RoutingContext routingContext = currentVertxRequest.getCurrent();
if (routingContext == null) {
return Collections.EMPTY_MAP;
}
MultiMap qheaders = routingContext.request().headers();
if (qheaders == null) {
return Collections.EMPTY_MAP;
}
if (qheaders instanceof QuarkusHttpHeaders) {
return ((QuarkusHttpHeaders) qheaders).getContextObjects();
} else {
return Collections.EMPTY_MAP;
}
}
Aggregations