From 07c4295a895f6f7768786f044f8dae08c3b37ed9 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Mon, 12 Apr 2021 12:07:09 +1000 Subject: [PATCH] Fix websockets class loading issue Fixes #16427 --- .../websockets/runtime/WebsocketRecorder.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/extensions/websockets/runtime/src/main/java/io/quarkus/undertow/websockets/runtime/WebsocketRecorder.java b/extensions/websockets/runtime/src/main/java/io/quarkus/undertow/websockets/runtime/WebsocketRecorder.java index fc5c834d8acd1..b0722fbd7452d 100644 --- a/extensions/websockets/runtime/src/main/java/io/quarkus/undertow/websockets/runtime/WebsocketRecorder.java +++ b/extensions/websockets/runtime/src/main/java/io/quarkus/undertow/websockets/runtime/WebsocketRecorder.java @@ -19,6 +19,7 @@ import io.quarkus.arc.runtime.BeanContainer; import io.quarkus.runtime.ExecutorRecorder; import io.quarkus.runtime.annotations.Recorder; +import io.undertow.websockets.UndertowContainerProvider; import io.undertow.websockets.WebSocketDeploymentInfo; import io.undertow.websockets.util.ContextSetupHandler; import io.undertow.websockets.util.ObjectFactory; @@ -107,6 +108,7 @@ public WebSocketDeploymentInfo createDeploymentInfo(Set annotatedEndpoin public Handler createHandler(BeanContainer beanContainer, Supplier eventLoopGroupSupplier, WebSocketDeploymentInfo info) throws DeploymentException { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); ManagedContext requestContext = Arc.container().requestContext(); VertxServerWebSocketContainer container = new VertxServerWebSocketContainer(new ObjectIntrospecter() { @Override @@ -137,11 +139,17 @@ public Action create(Action action) { return new Action() { @Override public T call(C context) throws Exception { + ClassLoader old = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(cl); requestContext.activate(); try { return action.call(context); } finally { - requestContext.terminate(); + try { + requestContext.terminate(); + } finally { + Thread.currentThread().setContextClassLoader(old); + } } } }; @@ -159,6 +167,7 @@ public Executor get() { for (ServerEndpointConfig i : info.getProgramaticEndpoints()) { container.addEndpoint(i); } + UndertowContainerProvider.setDefaultContainer(container); return new VertxWebSocketHandler(container, info); }