use of org.eclipse.jetty.websocket.api.Session in project jetty.project by eclipse.
the class CookieTest method testViaServletUpgradeRequest.
@Test
public void testViaServletUpgradeRequest() throws Exception {
// Setup client
HttpCookie cookie = new HttpCookie("hello", "world");
cookie.setPath("/");
cookie.setMaxAge(100000);
ClientUpgradeRequest request = new ClientUpgradeRequest();
request.setCookies(Collections.singletonList(cookie));
// Client connects
CookieTrackingSocket clientSocket = new CookieTrackingSocket();
Future<Session> clientConnectFuture = client.connect(clientSocket, server.getWsUri(), request);
// Server accepts connect
IBlockheadServerConnection serverConn = server.accept();
// client confirms upgrade and receipt of frame
String serverCookies = confirmClientUpgradeAndCookies(clientSocket, clientConnectFuture, serverConn);
Assert.assertThat("Cookies seen at server side", serverCookies, containsString("hello=world"));
}
use of org.eclipse.jetty.websocket.api.Session in project jetty.project by eclipse.
the class BadNetworkTest method testAbruptServerClose.
@Test
public void testAbruptServerClose() throws Exception {
JettyTrackingSocket wsocket = new JettyTrackingSocket();
URI wsUri = server.getWsUri();
Future<Session> future = client.connect(wsocket, wsUri);
IBlockheadServerConnection ssocket = server.accept();
ssocket.upgrade();
// Validate that we are connected
future.get(30, TimeUnit.SECONDS);
wsocket.waitForConnected(30, TimeUnit.SECONDS);
// Have server disconnect abruptly
ssocket.disconnect();
// Wait for close (as response to idle timeout)
wsocket.waitForClose(10, TimeUnit.SECONDS);
// Client Socket should see a close event, with status NO_CLOSE
// This event is automatically supplied by the underlying WebSocketClientConnection
// in the situation of a bad network connection.
wsocket.assertCloseCode(StatusCode.NO_CLOSE);
}
use of org.eclipse.jetty.websocket.api.Session in project jetty.project by eclipse.
the class BadNetworkTest method testAbruptClientClose.
@Test
public void testAbruptClientClose() throws Exception {
JettyTrackingSocket wsocket = new JettyTrackingSocket();
URI wsUri = server.getWsUri();
Future<Session> future = client.connect(wsocket, wsUri);
IBlockheadServerConnection ssocket = server.accept();
ssocket.upgrade();
// Validate that we are connected
future.get(30, TimeUnit.SECONDS);
wsocket.waitForConnected(30, TimeUnit.SECONDS);
// Have client disconnect abruptly
Session session = wsocket.getSession();
session.disconnect();
// Client Socket should see close
wsocket.waitForClose(10, TimeUnit.SECONDS);
// Client Socket should see a close event, with status NO_CLOSE
// This event is automatically supplied by the underlying WebSocketClientConnection
// in the situation of a bad network connection.
wsocket.assertCloseCode(StatusCode.NO_CLOSE);
}
use of org.eclipse.jetty.websocket.api.Session in project jetty.project by eclipse.
the class ClientCloseTest method testHalfClose.
@Test
public void testHalfClose() throws Exception {
// Set client timeout
final int timeout = 1000;
client.setMaxIdleTimeout(timeout);
// Client connects
CloseTrackingSocket clientSocket = new CloseTrackingSocket();
Future<Session> clientConnectFuture = client.connect(clientSocket, server.getWsUri());
// Server accepts connect
IBlockheadServerConnection serverConn = server.accept();
serverConn.upgrade();
// client confirms connection via echo
confirmConnection(clientSocket, clientConnectFuture, serverConn);
// client sends close frame (code 1000, normal)
final String origCloseReason = "Normal Close";
clientSocket.getSession().close(StatusCode.NORMAL, origCloseReason);
// server receives close frame
confirmServerReceivedCloseFrame(serverConn, StatusCode.NORMAL, is(origCloseReason));
// server sends 2 messages
serverConn.write(new TextFrame().setPayload("Hello"));
serverConn.write(new TextFrame().setPayload("World"));
// server sends close frame (code 1000, no reason)
CloseInfo sclose = new CloseInfo(StatusCode.NORMAL, "From Server");
serverConn.write(sclose.asFrame());
// client receives 2 messages
clientSocket.messageQueue.awaitEventCount(2, 1, TimeUnit.SECONDS);
// Verify received messages
String recvMsg = clientSocket.messageQueue.poll();
assertThat("Received message 1", recvMsg, is("Hello"));
recvMsg = clientSocket.messageQueue.poll();
assertThat("Received message 2", recvMsg, is("World"));
// Verify that there are no errors
assertThat("Error events", clientSocket.error.get(), nullValue());
// client close event on ws-endpoint
clientSocket.assertReceivedCloseEvent(timeout, is(StatusCode.NORMAL), containsString("From Server"));
}
use of org.eclipse.jetty.websocket.api.Session in project jetty.project by eclipse.
the class ClientCloseTest method testStopLifecycle.
@Test(timeout = 5000L)
public void testStopLifecycle() throws Exception {
// Set client timeout
final int timeout = 1000;
client.setMaxIdleTimeout(timeout);
int clientCount = 3;
CloseTrackingSocket[] clientSockets = new CloseTrackingSocket[clientCount];
IBlockheadServerConnection[] serverConns = new IBlockheadServerConnection[clientCount];
// Connect Multiple Clients
for (int i = 0; i < clientCount; i++) {
// Client Request Upgrade
clientSockets[i] = new CloseTrackingSocket();
Future<Session> clientConnectFuture = client.connect(clientSockets[i], server.getWsUri());
// Server accepts connection
serverConns[i] = server.accept();
serverConns[i].upgrade();
// client confirms connection via echo
confirmConnection(clientSockets[i], clientConnectFuture, serverConns[i]);
}
// client lifecycle stop
client.stop();
// clients send close frames (code 1001, shutdown)
for (int i = 0; i < clientCount; i++) {
// server receives close frame
confirmServerReceivedCloseFrame(serverConns[i], StatusCode.SHUTDOWN, containsString("Shutdown"));
}
// clients disconnect
for (int i = 0; i < clientCount; i++) {
clientSockets[i].assertReceivedCloseEvent(timeout, is(StatusCode.SHUTDOWN), containsString("Shutdown"));
}
}
Aggregations