Thank you for your answers. I understand I need to explicitly set MDC in worker thread. Problem is I cannot modify the codebase of application that runs on Wildfly. Actually it is a war deployed into Wildfly, and I cannot re-build it. I want to customize only undertow/wildfly.The custom handler I add this way runs in IO thread:/subsystem=undertow/configuration=filter/custom-filter=correlation:add(module="com.ingrammicro.idp.undertow-correlation",class-name=com.ingrammicro.idp.CorrelationHandler)
/subsystem=undertow/server=default-server/host=default-host/filter-ref=correlation:add()But from stacktrace I see multiple handlers run in worker thread:handleRequest:43, PredicateHandler (io.undertow.server.handlers)
handleRequest:68, RedirectDirHandler (io.undertow.servlet.handlers)
handleRequest:132, SSLInformationAssociationHandler (io.undertow.servlet.handlers.security)
handleRequest:57, ServletAuthenticationCallHandler (io.undertow.servlet.handlers.security)Also, I can add an expression handler that runs in worker thread:/subsystem=undertow/configuration=filter/expression-filter=IM_private:add(,expression="path-template('/auth/realms/{realm}/restart-session') -> ip-access-control(acl={'127.0.0.1 allow', '0:0:0:0:0:0:0:1 allow'})")
/subsystem=undertow/server=default-server/host=default-host/filter-ref=IM_private:add()Is it possible to add a custom handler to run in a worker thread?_______________________________________________ср, 3 июн. 2020 г. в 10:23, Andrea Di Cesare <andrea@softinstigate.com>:If a thread switch occurs the MDC context is lost.You can attach it to the exchange:public static final AttachmentKey<Map<String, String>> MDC_CONTEXT_KEY = AttachmentKey.create(Map.class);....exchange.putAttachment(MDC_CONTEXT_KEY, MDC.getCopyOfContextMap());...and then restore it in your worker thread:MDC.setContextMap(exchange.getAttachment(MDC_CONTEXT_KEY));Hope this helps,Andrea Di CesarePartner at SoftInstigateMongoDB Technology PartnerVia Copernico 38, 20125 Milano (Italy)Mobile: +39 329 737 6417Skype: ujibangThe company behind RESTHeart, the NoCoding and NoSQL Platform for MongoDBIl giorno mar 2 giu 2020 alle ore 14:57 Мартынов Илья <imartynovsp@gmail.com> ha scritto:Hello,_______________________________________________I've created a handler to fill MDC from incoming request header.public class CorrelationHandler implements HttpHandler
{
private HttpHandler next;
public CorrelationHandler(HttpHandler next) {
this.next = next;
}
@Override
public void handleRequest(HttpServerExchange e) throws Exception {
String corr = e.getRequestHeaders().getFirst("IDP-CORR-ID");
MDC.put("corr", corr);
next.handleRequest(e);
}
}But most of my processing is done in worker thread and mdc is not passed threre. How to pass it?
undertow-dev mailing list
undertow-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/undertow-dev
undertow-dev mailing list
undertow-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/undertow-dev