I use a http filter and ContextLocals
to store contextual information extracted from http request headers. It working nice with blocking http handler but not with non blocking code like ExceptionMapper<NotFoundException>
.
When i entering “response” filter, ContextLocals is empty.
@Provider
@Priority(1)
public final class EntryPointHttpFilter implements ContainerRequestFilter, ContainerResponseFilter {
@Override
public void filter(final ContainerRequestContext containerRequestContext) {
// Extract data from request headers
// Init exec context
ExecutionContext.initialize(...); //internally use ContextLocals.put("KEY", ctx)
}
@Override
public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) {
ExecutionContext.destroy(); //internally use ContextLocals.remove("KEY") with exception if ContextLocals.get() == null
}
}
2024-06-11 08:42:12,715 INFO [com.fra.cor.int.LoggerInterceptor] (executor-thread-1) End processing com.framework.web.controller.GreetingController::convert
2024-06-11 08:42:12,854 INFO [com.fra.cor.int.LoggerInterceptor] (executor-thread-1) End processing com.framework.core.typeconverter.ConverterService::convert
2024-06-11 08:42:12,856 INFO [com.fra.cor.int.LoggerInterceptor] (executor-thread-1) End processing com.framework.web.controller.GreetingController::convert
2024-06-11 08:42:15,071 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (vert.x-eventloop-thread-0) HTTP Request to /greeting/convertsqdf failed, error id: 9f1dd363-d282-44b8-a6f8-f4f38afcba53-2: java.lang.IllegalStateException: Execution context is not initialized
at com.framework.core.execcontext.ExecutionContext.getOrThrow(ExecutionContext.java:168)
at com.framework.core.execcontext.ExecutionContext.destroy(ExecutionContext.java:142)
at com.framework.web.filter.EntryPointHttpFilter.filter(EntryPointHttpFilter.java:38)
at org.jboss.resteasy.reactive.server.handlers.ResourceResponseFilterHandler.handle(ResourceResponseFilterHandler.java:25)
Controller code is executed in thread executor-thread-X
, but error handler in vert.x-eventloop-thread-X
.
How i can propagate my context ?