Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix websockets class loading issue #16428

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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