예제 #1
0
  @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();
    }
  }
예제 #2
0
  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();
  }
예제 #3
0
 public void stopWebsocketClient() throws Exception {
   if (websocketClient != null) websocketClient.stop();
 }