diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/ClientContainer.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/ClientContainer.java index f9b98e296b1..213bc939c6f 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/ClientContainer.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/ClientContainer.java @@ -68,7 +68,7 @@ public class ClientContainer extends ContainerLifeCycle implements WebSocketCont /** Tracking for all declared Client endpoints */ private final Map, EndpointMetadata> endpointClientMetadataCache; /** The jetty websocket client in use for this container */ - private final WebSocketClient client; + private WebSocketClient client; public ClientContainer() { @@ -179,6 +179,11 @@ public class ClientContainer extends ContainerLifeCycle implements WebSocketCont super.doStop(); } + public WebSocketClient getClient() + { + return client; + } + public EndpointMetadata getClientEndpointMetadata(Class endpoint) { EndpointMetadata metadata = null; diff --git a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/demo/ExampleClient.java b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/demo/ExampleClient.java index 39f7e2ffbbc..1d0aafc1049 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/demo/ExampleClient.java +++ b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/demo/ExampleClient.java @@ -19,13 +19,11 @@ package org.eclipse.jetty.websocket.jsr356.demo; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; import java.util.concurrent.TimeUnit; import javax.websocket.ContainerProvider; import javax.websocket.DeploymentException; -import javax.websocket.Session; import javax.websocket.WebSocketContainer; public class ExampleClient @@ -45,13 +43,14 @@ public class ExampleClient private void run() throws DeploymentException, IOException, URISyntaxException, InterruptedException { WebSocketContainer container = ContainerProvider.getWebSocketContainer(); - ExampleSocket socket = new ExampleSocket(); - URI uri = new URI("ws://echo.websocket.org/"); - Session session = container.connectToServer(socket,uri); - socket.writeMessage("Hello"); - socket.messageLatch.await(1,TimeUnit.SECONDS); // give remote 1 second to respond - session.close(); - socket.closeLatch.await(1,TimeUnit.SECONDS); // give remote 1 second to acknowledge response - System.exit(0); + TimeUnit.HOURS.sleep(1); + // ExampleSocket socket = new ExampleSocket(); + // URI uri = new URI("ws://echo.websocket.org/"); + // Session session = container.connectToServer(socket,uri); + // socket.writeMessage("Hello"); + // socket.messageLatch.await(1,TimeUnit.SECONDS); // give remote 1 second to respond + // session.close(); + // socket.closeLatch.await(1,TimeUnit.SECONDS); // give remote 1 second to acknowledge response + // System.exit(0); } } diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/ServerContainer.java b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/ServerContainer.java index 18b7d952646..f19e5d47931 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/ServerContainer.java +++ b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/ServerContainer.java @@ -52,7 +52,7 @@ public class ServerContainer extends ClientContainer implements javax.websocket. eventDriverFactory.addImplementation(new JsrServerExtendsEndpointImpl()); this.webSocketServerFactory.addSessionFactory(new JsrSessionFactory(this)); } - + public EndpointInstance newClientEndpointInstance(Object endpoint, ServerEndpointConfig config, String path) { EndpointMetadata metadata = getClientEndpointMetadata(endpoint.getClass()); diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java index 83604efa45d..0dfd03f3215 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java @@ -147,6 +147,7 @@ public class WebSocketClient extends ContainerLifeCycle LOG.debug("connect websocket {} to {}",websocket,toUri); // Grab Connection Manager + initConnectionManager(); ConnectionManager manager = getConnectionManager(); // Setup Driver for user provided websocket @@ -184,6 +185,28 @@ public class WebSocketClient extends ContainerLifeCycle return promise; } + private synchronized void initConnectionManager() throws IOException + { + if (connectionManager != null) + { + return; + } + try + { + connectionManager = newConnectionManager(); + addBean(connectionManager); + connectionManager.start(); + } + catch (IOException e) + { + throw e; + } + catch (Exception e) + { + throw new IOException(e); + } + } + @Override protected void doStart() throws Exception { @@ -221,9 +244,6 @@ public class WebSocketClient extends ContainerLifeCycle cookieStore = new HttpCookieStore.Empty(); } - this.connectionManager = newConnectionManager(); - addBean(this.connectionManager); - super.doStart(); LOG.info("Started {}",this);