Skip to content

Commit

Permalink
Fixes #981 - WebSocketTransport.Factory does not add WebSocketContain…
Browse files Browse the repository at this point in the history
…er as a bean.

Adding WebSocketContainer as a bean has no effect because WebSocketContainer comes
from the Servlet Container implementation and implements the server version of
LifeCycle, so the webapp version of LifeCycle won't recognize it as a LifeCycle
and won't manage its life.

However, it is useful to add it for dump() purposes.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Dec 22, 2020
1 parent 4e9dbc9 commit 0430389
Showing 1 changed file with 7 additions and 2 deletions.
Expand Up @@ -31,7 +31,6 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import javax.websocket.ClientEndpointConfig;
import javax.websocket.CloseReason;
import javax.websocket.ContainerProvider;
Expand All @@ -42,7 +41,6 @@
import javax.websocket.MessageHandler;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;

import org.cometd.bayeux.Message.Mutable;
import org.cometd.client.transport.ClientTransport;
import org.cometd.client.transport.TransportListener;
Expand Down Expand Up @@ -258,6 +256,13 @@ public void afterResponse(HandshakeResponse hr) {
public static class Factory extends ContainerLifeCycle implements ClientTransport.Factory {
private final WebSocketContainer container = ContainerProvider.getWebSocketContainer();

public Factory() {
// The WebSocketContainer comes from the Servlet Container,
// so its lifecycle cannot be managed by this class due to
// classloader differences; we just add it for dump() purposes.
addBean(container, false);
}

@Override
public ClientTransport newClientTransport(String url, Map<String, Object> options) {
ScheduledExecutorService scheduler = (ScheduledExecutorService)options.get(ClientTransport.SCHEDULER_OPTION);
Expand Down

0 comments on commit 0430389

Please sign in to comment.