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;
}
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();
}
}
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();
}
}
}
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();
}
}
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();
}
}
Aggregations