Examples of WebSocketClient


Examples of org.eclipse.jetty.websocket.WebSocketClient

    CNWSPeerImpl(String internalID,CNPeer peer,CNWSHub hub) throws Exception {
        super(peer);
        this.internalID = internalID;
        this.hub = hub;
        WebSocketClient client = hub.factory.newWebSocketClient();
        String account = internalID.substring(0,internalID.indexOf('@'));
        String uriString = internalID.substring(internalID.indexOf('@')+1);
        URI uri = new URI(uriString);
        CNWSWebSocket socket = new CNWSWebSocket(this);
        Future<Connection> f = client.open(uri,socket);
        connection = f.get();
        connection.sendMessage(account);
    }
View Full Code Here

Examples of org.eclipse.jetty.websocket.WebSocketClient

    {

        try
        {
            final WebSocketClientFactory webSocketClientFactory = getWebSocketClientFactory(sslContext);
            WebSocketClient client = webSocketClientFactory.newWebSocketClient();
            // Configure the client
            client.setProtocol(AMQP_WEBSOCKET_SUBPROTOCOL);


            ConnectionHandler.FrameOutput<FrameBody> out = new ConnectionHandler.FrameOutput<FrameBody>(conn);

            final ConnectionHandler.FrameSource src;

            if(conn.requiresSASL())
            {
                ConnectionHandler.FrameOutput<SaslFrameBody> saslOut = new ConnectionHandler.FrameOutput<SaslFrameBody>(conn);

                src =  new ConnectionHandler.SequentialFrameSource(new HeaderFrameSource((byte)'A',
                                                                                               (byte)'M',
                                                                                               (byte)'Q',
                                                                                               (byte)'P',
                                                                                               (byte)3,
                                                                                               (byte)1,
                                                                                               (byte)0,
                                                                                               (byte)0),
                                                                   saslOut.asFrameSource(),
                                                                   new HeaderFrameSource((byte)'A',
                                                                                               (byte)'M',
                                                                                               (byte)'Q',
                                                                                               (byte)'P',
                                                                                               (byte)0,
                                                                                               (byte)1,
                                                                                               (byte)0,
                                                                                               (byte)0),
                                                                   out.asFrameSource());

                conn.setSaslFrameOutput(saslOut);
            }
            else
            {
                src =  new ConnectionHandler.SequentialFrameSource(new HeaderFrameSource((byte)'A',
                                                                                               (byte)'M',
                                                                                               (byte)'Q',
                                                                                               (byte)'P',
                                                                                               (byte)0,
                                                                                               (byte)1,
                                                                                               (byte)0,
                                                                                               (byte)0),
                                                               out.asFrameSource());
            }

            final ConnectionHandler handler = new ConnectionHandler(conn);
            conn.setFrameOutputHandler(out);
            final URI uri = new URI(_transport +"://"+ address+":"+ port +"/");
            _connection = client.open(uri, new WebSocket.OnBinaryMessage()
            {
                public void onOpen(Connection connection)
                {

                    Thread outputThread = new Thread(new FrameOutputThread(connection, src, conn, exceptionHandler, webSocketClientFactory));
View Full Code Here

Examples of org.eclipse.jetty.websocket.client.WebSocketClient

  private final WebSocketClient webSocketClient;

  public JettyMtgoxClient(MessageChannel outputChannel) {
    super(outputChannel);
    this.webSocketClient = new WebSocketClient();
  }
View Full Code Here

Examples of org.eclipse.jetty.websocket.client.WebSocketClient

          null, null);
    } catch (URISyntaxException e) {
      LOG.severe("Unable to create ws:// uri from given address (" + inetAddress + ")", e);
      throw new IllegalStateException(e);
    }
    WebSocketClient client = new WebSocketClient();
    try {
      client.start();
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    }
    ClientUpgradeRequest request = new ClientUpgradeRequest();
    try {
      client.connect(clientChannel, uri, request).get();
    } catch (Exception ex) {
      throw new IOException(ex);
    }
    return client;
  }
View Full Code Here

Examples of org.eclipse.jetty.websocket.client.WebSocketClient

        if (args.length > 0)
        {
            destUri = args[0];
        }

        WebSocketClient client = new WebSocketClient();
        SimpleEchoSocket socket = new SimpleEchoSocket();
        try
        {
            client.start();

            URI echoUri = new URI(destUri);
            ClientUpgradeRequest request = new ClientUpgradeRequest();
            client.connect(socket,echoUri,request);
            System.out.printf("Connecting to : %s%n",echoUri);

            // wait for closed socket connection.
            socket.awaitClose(5,TimeUnit.SECONDS);
        }
        catch (Throwable t)
        {
            t.printStackTrace();
        }
        finally
        {
            try
            {
                client.stop();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
View Full Code Here

Examples of org.eclipse.jetty.websocket.client.WebSocketClient

            URI uri = wsb.getServerBaseURI();

            WebAppContext webapp = wsb.createWebAppContext();
            wsb.deployWebapp(webapp);

            WebSocketClient client = new WebSocketClient(bufferPool);
            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();
View Full Code Here

Examples of org.eclipse.jetty.websocket.client.WebSocketClient

        return engine;
    }

    public UpgradeConnection newUpgradeConnection(SocketChannel channel, EndPoint endPoint, ConnectPromise connectPromise)
    {
        WebSocketClient client = connectPromise.getClient();
        Executor executor = client.getExecutor();
        UpgradeConnection connection = new UpgradeConnection(endPoint,executor,connectPromise);
        return connection;
    }
View Full Code Here

Examples of org.eclipse.jetty.websocket.client.WebSocketClient

        server.stop();
    }

    private void assertConnectionTimeout(URI uri) throws Exception, IOException, InterruptedException, ExecutionException, TimeoutException
    {
        WebSocketClient client = new WebSocketClient(bufferPool);
        try
        {
            client.start();
            JettyEchoSocket clientEcho = new JettyEchoSocket();
            if (LOG.isDebugEnabled())
                LOG.debug("Client Attempting to connnect");
            Future<Session> future = client.connect(clientEcho,uri);
            // wait for connect
            future.get(1,TimeUnit.SECONDS);
            if (LOG.isDebugEnabled())
                LOG.debug("Client Connected");
            // wait 1 second
            if (LOG.isDebugEnabled())
                LOG.debug("Waiting 1 second");
            TimeUnit.SECONDS.sleep(1);
            if (LOG.isDebugEnabled())
                LOG.debug("Waited 1 second");
            if (clientEcho.getClosed() == false)
            {
                // Try to write
                clientEcho.sendMessage("You shouldn't be there");
                try
                {
                    Queue<String> msgs = clientEcho.awaitMessages(1);
                    assertThat("Should not have received messages echoed back",msgs,is(empty()));
                }
                catch (TimeoutException | InterruptedException e)
                {
                    // valid success path
                }
            }
        }
        finally
        {
            client.stop();
        }
    }
View Full Code Here

Examples of org.eclipse.jetty.websocket.client.WebSocketClient

            }
        };

        server.setHandler(handler);

        client = new WebSocketClient();
        server.addBean(client, true);

        server.start();
    }
View Full Code Here

Examples of org.eclipse.jetty.websocket.client.WebSocketClient

        server.stop();
    }

    private void assertResponse(String requestPath, String requestMessage, String expectedResponse) throws Exception
    {
        WebSocketClient client = new WebSocketClient(bufferPool);
        try
        {
            client.start();
            JettyEchoSocket clientEcho = new JettyEchoSocket();
            Future<Session> future = client.connect(clientEcho,serverUri.resolve(requestPath));
            // wait for connect
            future.get(1,TimeUnit.SECONDS);
            clientEcho.sendMessage(requestMessage);
            Queue<String> msgs = clientEcho.awaitMessages(1);
            Assert.assertThat("Expected message",msgs.poll(),is(expectedResponse));
        }
        finally
        {
            client.stop();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.