<div dir="ltr">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.<div>The custom handler I add this way runs in IO thread:</div><div>/subsystem=undertow/configuration=filter/custom-filter=correlation:add(module="com.ingrammicro.idp.undertow-correlation",class-name=com.ingrammicro.idp.CorrelationHandler)<br>/subsystem=undertow/server=default-server/host=default-host/filter-ref=correlation:add()<br></div><div><br></div><div>But from stacktrace I see multiple handlers run in worker thread:</div><div>handleRequest:43, PredicateHandler (io.undertow.server.handlers)<br>handleRequest:68, RedirectDirHandler (io.undertow.servlet.handlers)<br>handleRequest:132, SSLInformationAssociationHandler (io.undertow.servlet.handlers.security)<br>handleRequest:57, ServletAuthenticationCallHandler (io.undertow.servlet.handlers.security)<br></div><div><br></div><div>Also, I can add an expression handler that runs in worker thread: </div><div>/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'})")<br>/subsystem=undertow/server=default-server/host=default-host/filter-ref=IM_private:add()<br></div><div><br></div><div>Is it possible to add a custom handler to run in a worker thread?</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">ср, 3 июн. 2020 г. в 10:23, Andrea Di Cesare <<a href="mailto:andrea@softinstigate.com">andrea@softinstigate.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">If a thread switch occurs the MDC context is lost.<div><br></div><div>You can attach it to the exchange:</div><div><br></div><div><div><font face="monospace">public static final AttachmentKey<Map<String, String>> MDC_CONTEXT_KEY = AttachmentKey.create(Map.class);</font></div></div><div><font face="monospace">....</font></div><div><font face="monospace">exchange.putAttachment(MDC_CONTEXT_KEY, MDC.getCopyOfContextMap());</font><br></div><div>...</div><div><br></div><div>and then restore it in your worker thread:</div><div><br></div><div><font face="monospace">MDC.setContextMap(exchange.getAttachment(MDC_CONTEXT_KEY));</font><br></div><div><br></div><div>Hope this helps,</div><div><br clear="all"><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"> <font size="4">Andrea Di Cesare</font></div><div dir="ltr"><div dir="ltr"> Partner at <a href="https://softinstigate.com/" target="_blank">Soft<b>Instigate</b></a><font size="4"><br></font></div><div dir="ltr"> MongoDB Technology Partner </div><div dir="ltr"> <a href="https://sched.co/b2Hz" target="_blank"><img src="https://docs.google.com/uc?export=download&id=1To-wOR_h9VjVcsfochmjd4JxjQ7UluzH&revid=0BxzmRFiL7K0IQW5WSWo5d0hiS0Nib0crTWRFdzNvbWxLb1hZPQ" width="158" height="200"></a></div><div dir="ltr"> Via Copernico 38, 20125 Milano (Italy)<br></div><div dir="ltr"><div dir="ltr"> Mobile: +39 329 737 6417</div><div dir="ltr"> Skype: ujibang</div></div><div dir="ltr"><img src="https://drive.google.com/a/softinstigate.com/uc?id=1wu6-sfqQWI8-8MGKuYu3BQTR4StPt33a&export=download"><br></div><div dir="ltr"> The company behind <a href="https://restheart.org" target="_blank"><b>REST</b>Heart</a>, the NoCoding and NoSQL Platform for MongoDB </div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><br></div></div></div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno mar 2 giu 2020 alle ore 14:57 Мартынов Илья <<a href="mailto:imartynovsp@gmail.com" target="_blank">imartynovsp@gmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>I've created a handler to fill MDC from incoming request header.</div><div>public class CorrelationHandler implements HttpHandler<br>{<br> private HttpHandler next;<br> public CorrelationHandler(HttpHandler next) {<br> this.next = next;<br> }<br> @Override<br> public void handleRequest(HttpServerExchange e) throws Exception {<br> String corr = e.getRequestHeaders().getFirst("IDP-CORR-ID");<br> MDC.put("corr", corr);<br> next.handleRequest(e);<br> }<br>}<br></div><div><br></div><div>But most of my processing is done in worker thread and mdc is not passed threre. How to pass it?</div><div><br></div></div>
_______________________________________________<br>
undertow-dev mailing list<br>
<a href="mailto:undertow-dev@lists.jboss.org" target="_blank">undertow-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/undertow-dev</a></blockquote></div>
</blockquote></div>