Search in sources :

Example 1 with WebSocketClient

use of org.eclipse.jetty.websocket.client.WebSocketClient in project zeppelin by apache.

the class ZeppelinClient method createNewWebsocketClient.

private WebSocketClient createNewWebsocketClient() {
    SslContextFactory sslContextFactory = new SslContextFactory();
    WebSocketClient client = new WebSocketClient(sslContextFactory);
    client.setMaxIdleTimeout(5 * MIN * 1000);
    client.setMaxTextMessageBufferSize(Client.getMaxNoteSize());
    client.getPolicy().setMaxTextMessageSize(Client.getMaxNoteSize());
    //TODO(khalid): other client settings
    return client;
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient)

Example 2 with WebSocketClient

use of org.eclipse.jetty.websocket.client.WebSocketClient in project jetty.project by eclipse.

the class LargeContainerTest method testEcho.

@Test
public void testEcho() throws Exception {
    WSServer wsb = new WSServer(testdir, "app");
    wsb.copyWebInf("large-echo-config-web.xml");
    wsb.copyEndpoint(LargeEchoDefaultSocket.class);
    try {
        wsb.start();
        URI uri = wsb.getServerBaseURI();
        WebAppContext webapp = wsb.createWebAppContext();
        wsb.deployWebapp(webapp);
        // wsb.dump();
        WebSocketClient client = new WebSocketClient(bufferPool);
        try {
            client.getPolicy().setMaxTextMessageSize(128 * 1024);
            client.start();
            JettyEchoSocket clientEcho = new JettyEchoSocket();
            Future<Session> foo = client.connect(clientEcho, uri.resolve("echo/large"));
            // wait for connect
            foo.get(1, TimeUnit.SECONDS);
            // The message size should be bigger than default, but smaller than the limit that LargeEchoSocket specifies
            byte[] txt = new byte[100 * 1024];
            Arrays.fill(txt, (byte) 'o');
            String msg = new String(txt, StandardCharsets.UTF_8);
            clientEcho.sendMessage(msg);
            Queue<String> msgs = clientEcho.awaitMessages(1);
            Assert.assertEquals("Expected message", msg, msgs.poll());
        } finally {
            client.stop();
        }
    } finally {
        wsb.stop();
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) URI(java.net.URI) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test)

Example 3 with WebSocketClient

use of org.eclipse.jetty.websocket.client.WebSocketClient in project jetty.project by eclipse.

the class SimpleEchoClient method main.

public static void main(String[] args) {
    String destUri = "ws://echo.websocket.org";
    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();
        }
    }
}
Also used : ClientUpgradeRequest(org.eclipse.jetty.websocket.client.ClientUpgradeRequest) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) URI(java.net.URI)

Example 4 with WebSocketClient

use of org.eclipse.jetty.websocket.client.WebSocketClient in project jetty.project by eclipse.

the class BasicEndpointTest method testEcho.

@Test
public void testEcho() throws Exception {
    WSServer wsb = new WSServer(testdir, "app");
    wsb.copyWebInf("basic-echo-endpoint-config-web.xml");
    // the endpoint (extends javax.websocket.Endpoint)
    wsb.copyClass(BasicEchoEndpoint.class);
    // the configuration (adds the endpoint)
    wsb.copyClass(BasicEchoEndpointConfigContextListener.class);
    try {
        wsb.start();
        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("echo"));
            // 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();
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) URI(java.net.URI) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test)

Example 5 with WebSocketClient

use of org.eclipse.jetty.websocket.client.WebSocketClient in project jetty.project by eclipse.

the class AltFilterTest method testEcho.

@Test
public void testEcho() throws Exception {
    WSServer wsb = new WSServer(testdir, "app");
    wsb.copyWebInf("alt-filter-web.xml");
    // the endpoint (extends javax.websocket.Endpoint)
    wsb.copyClass(BasicEchoSocket.class);
    try {
        wsb.start();
        URI uri = wsb.getServerBaseURI();
        WebAppContext webapp = wsb.createWebAppContext();
        wsb.deployWebapp(webapp);
        FilterHolder filterWebXml = webapp.getServletHandler().getFilter("wsuf-test");
        assertThat("Filter[wsuf-test]", filterWebXml, notNullValue());
        FilterHolder filterSCI = webapp.getServletHandler().getFilter("Jetty_WebSocketUpgradeFilter");
        assertThat("Filter[Jetty_WebSocketUpgradeFilter]", filterSCI, nullValue());
        WebSocketClient client = new WebSocketClient(bufferPool);
        try {
            client.start();
            JettyEchoSocket clientEcho = new JettyEchoSocket();
            Future<Session> future = client.connect(clientEcho, uri.resolve("echo"));
            // wait for connect
            future.get(1, TimeUnit.SECONDS);
            clientEcho.sendMessage("Hello Echo");
            Queue<String> msgs = clientEcho.awaitMessages(1);
            Assert.assertEquals("Expected message", "Hello Echo", msgs.poll());
        } finally {
            client.stop();
        }
    } finally {
        wsb.stop();
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) URI(java.net.URI) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test)

Aggregations

WebSocketClient (org.eclipse.jetty.websocket.client.WebSocketClient)40 Test (org.junit.Test)26 URI (java.net.URI)25 Session (org.eclipse.jetty.websocket.api.Session)23 HashMap (java.util.HashMap)10 ClientUpgradeRequest (org.eclipse.jetty.websocket.client.ClientUpgradeRequest)10 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)9 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)9 QueuingWebSocketListener (com.kixeye.chassis.transport.websocket.QueuingWebSocketListener)9 WebSocketMessageRegistry (com.kixeye.chassis.transport.websocket.WebSocketMessageRegistry)9 MapPropertySource (org.springframework.core.env.MapPropertySource)9 StandardEnvironment (org.springframework.core.env.StandardEnvironment)9 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)9 ServiceError (com.kixeye.chassis.transport.dto.ServiceError)8 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)8 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)8 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)8 WebSocketSession (org.eclipse.jetty.websocket.common.WebSocketSession)8 Envelope (com.kixeye.chassis.transport.dto.Envelope)7 Header (com.kixeye.chassis.transport.dto.Header)6