@Test public void testEchoReturn() throws Exception { WSServer wsb = new WSServer(testdir, "app"); wsb.copyWebInf("empty-web.xml"); wsb.copyClass(EchoReturnEndpoint.class); try { wsb.start(); URI uri = wsb.getServerBaseURI(); WebAppContext webapp = wsb.createWebAppContext(); wsb.deployWebapp(webapp); wsb.dump(); WebSocketClient client = new WebSocketClient(); try { client.start(); JettyEchoSocket clientEcho = new JettyEchoSocket(); Future<Session> future = client.connect(clientEcho, uri.resolve("echoreturn")); // wait for connect future.get(1, TimeUnit.SECONDS); clientEcho.sendMessage("Hello World"); Queue<String> msgs = clientEcho.awaitMessages(1); Assert.assertEquals("Expected message", "Hello World", msgs.poll()); } finally { client.stop(); } } finally { wsb.stop(); } }
public Session connect(AgentWebSocketClientController controller) throws Exception { if (webSocketClient == null || !webSocketClient.isRunning()) { if (webSocketClient != null) { webSocketClient.stop(); } webSocketClient = builder.build(); webSocketClient.start(); } LOG.info("Connecting to websocket endpoint: " + urlService.getAgentRemoteWebSocketUrl()); ClientUpgradeRequest request = new ClientUpgradeRequest(); request.addExtensions("fragment;maxLength=" + getMessageBufferSize()); return webSocketClient .connect(controller, new URI(urlService.getAgentRemoteWebSocketUrl()), request) .get(); }
public void stopWebsocketClient() throws Exception { if (websocketClient != null) websocketClient.stop(); }