Esempio n. 1
0
 public void setUpConnection(String playerDest, String publDest) {
   try {
     publClient.start();
     playerClient.start();
     URI publURI = new URI(publDest);
     URI playerURI = new URI(playerDest);
     ClientUpgradeRequest publRequest = new ClientUpgradeRequest();
     ClientUpgradeRequest playerRequest = new ClientUpgradeRequest();
     publClient.connect(publSocket, publURI, publRequest);
     playerClient.connect(playerSocket, playerURI, playerRequest);
   } catch (Throwable t) {
     t.printStackTrace();
   }
 }
  private ServiceSocket getConnectionSocket() throws URISyntaxException, Exception {
    URI uri = getUri();

    String connectionId = getThreadName() + getConnectionId();
    ServiceSocket socket;
    WebSocketClient webSocketClient;
    if (isStreamingConnection()) {
      if (connectionList.containsKey(connectionId)) {
        socket = connectionList.get(connectionId);
        socket.initialize();
        return socket;
      } else {
        socket = new ServiceSocket(this);
        connectionList.put(connectionId, socket);
      }
    } else {
      socket = new ServiceSocket(this);
    }

    SslContextFactory sslContexFactory = new SslContextFactory();
    sslContexFactory.setTrustAll(isIgnoreSslErrors());
    webSocketClient = new WebSocketClient(sslContexFactory);

    webSocketClient.start();
    ClientUpgradeRequest request = new ClientUpgradeRequest();
    webSocketClient.connect(socket, uri, request);

    int connectionTimeout = Integer.parseInt(getConnectionTimeout());
    socket.awaitOpen(connectionTimeout, TimeUnit.MILLISECONDS);

    return socket;
  }
Esempio n. 3
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();
    }
  }
Esempio n. 4
0
  protected void connect(URI uri, long timeout, JettyConnection connection) throws Exception {

    if (!getWebsocketClient().isStarted()) websocketClient.start();

    ClientUpgradeRequest request = new ClientUpgradeRequest();
    request.setSubProtocols(WampFactory.getProtocolName());

    Future<Session> future = websocketClient.connect(connection, uri, request);

    if (timeout > 0) future.get(timeout, TimeUnit.MILLISECONDS);
    else future.get();
  }
  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();
  }