Skip to content

Commit

Permalink
Fix websockets class loading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Apr 12, 2021
1 parent 851ef0a commit b541a8c
Showing 1 changed file with 16 additions and 2 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -107,6 +108,7 @@ public WebSocketDeploymentInfo createDeploymentInfo(Set<String> annotatedEndpoin

public Handler<RoutingContext> createHandler(BeanContainer beanContainer, Supplier<EventLoopGroup> eventLoopGroupSupplier,
WebSocketDeploymentInfo info) throws DeploymentException {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
ManagedContext requestContext = Arc.container().requestContext();
VertxServerWebSocketContainer container = new VertxServerWebSocketContainer(new ObjectIntrospecter() {
@Override
Expand Down Expand Up @@ -137,11 +139,22 @@ public <T, C> Action<T, C> create(Action<T, C> action) {
return new Action<T, C>() {
@Override
public T call(C context) throws Exception {
requestContext.activate();
ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(cl);
boolean required = !requestContext.isActive();
if (required) {
requestContext.activate();
}
try {
return action.call(context);
} finally {
requestContext.terminate();
try {
if (required) {
requestContext.terminate();
}
} finally {
Thread.currentThread().setContextClassLoader(old);
}
}
}
};
Expand All @@ -159,6 +172,7 @@ public Executor get() {
for (ServerEndpointConfig i : info.getProgramaticEndpoints()) {
container.addEndpoint(i);
}
UndertowContainerProvider.setDefaultContainer(container);
return new VertxWebSocketHandler(container, info);
}

Expand Down

0 comments on commit b541a8c

Please sign in to comment.