use of org.eclipse.jetty.websocket.api.Session in project jetty.project by eclipse.
the class ClientConnectTest method testConnectionNotAccepted.
@Test
public void testConnectionNotAccepted() throws Exception {
JettyTrackingSocket wsocket = new JettyTrackingSocket();
URI wsUri = server.getWsUri();
Future<Session> future = client.connect(wsocket, wsUri);
try {
future.get(3, TimeUnit.SECONDS);
Assert.fail("Should have Timed Out");
} catch (ExecutionException e) {
assertExpectedError(e, wsocket, UpgradeException.class);
// Possible Passing Path (active session wait timeout)
wsocket.assertNotOpened();
} catch (TimeoutException e) {
// Possible Passing Path (concurrency timeout)
wsocket.assertNotOpened();
}
}
use of org.eclipse.jetty.websocket.api.Session in project jetty.project by eclipse.
the class ClientConnectTest method testBadHandshake_GetOK_WithSecWebSocketAccept.
@Test
public void testBadHandshake_GetOK_WithSecWebSocketAccept() throws Exception {
JettyTrackingSocket wsocket = new JettyTrackingSocket();
URI wsUri = server.getWsUri();
Future<Session> future = client.connect(wsocket, wsUri);
IBlockheadServerConnection connection = server.accept();
List<String> requestLines = connection.readRequestLines();
String key = connection.parseWebSocketKey(requestLines);
// Send OK to GET but not upgrade
StringBuilder resp = new StringBuilder();
// intentionally 200 (not 101)
resp.append("HTTP/1.1 200 OK\r\n");
// Include a value accept key
resp.append("Sec-WebSocket-Accept: ").append(AcceptHash.hashKey(key)).append("\r\n");
resp.append("Content-Length: 0\r\n");
resp.append("\r\n");
connection.respond(resp.toString());
// The attempt to get upgrade response future should throw error
try {
future.get(30, TimeUnit.SECONDS);
Assert.fail("Expected ExecutionException -> UpgradeException");
} catch (ExecutionException e) {
// Expected Path
UpgradeException ue = assertExpectedError(e, wsocket, UpgradeException.class);
Assert.assertThat("UpgradeException.requestURI", ue.getRequestURI(), notNullValue());
Assert.assertThat("UpgradeException.requestURI", ue.getRequestURI().toASCIIString(), is(wsUri.toASCIIString()));
Assert.assertThat("UpgradeException.responseStatusCode", ue.getResponseStatusCode(), is(200));
}
}
use of org.eclipse.jetty.websocket.api.Session in project jetty.project by eclipse.
the class ClientConnectTest method testAltConnect.
@Test
public void testAltConnect() throws Exception {
JettyTrackingSocket wsocket = new JettyTrackingSocket();
URI wsUri = server.getWsUri();
HttpClient httpClient = new HttpClient();
httpClient.start();
WebSocketUpgradeRequest req = new WebSocketUpgradeRequest(new WebSocketClient(), httpClient, wsUri, wsocket);
req.header("X-Foo", "Req");
CompletableFuture<Session> sess = req.sendAsync();
sess.thenAccept((s) -> {
System.out.printf("Session: %s%n", s);
s.close();
assertThat("Connect.UpgradeRequest", wsocket.connectUpgradeRequest, notNullValue());
assertThat("Connect.UpgradeResponse", wsocket.connectUpgradeResponse, notNullValue());
});
IBlockheadServerConnection connection = server.accept();
connection.upgrade();
}
use of org.eclipse.jetty.websocket.api.Session in project jetty.project by eclipse.
the class ClientConnectTest method testConnectionTimeout_Concurrent.
@Test(expected = TimeoutException.class)
public void testConnectionTimeout_Concurrent() throws Exception {
JettyTrackingSocket wsocket = new JettyTrackingSocket();
URI wsUri = server.getWsUri();
Future<Session> future = client.connect(wsocket, wsUri);
IBlockheadServerConnection ssocket = server.accept();
Assert.assertNotNull(ssocket);
// The attempt to get upgrade response future should throw error
try {
future.get(3, TimeUnit.SECONDS);
Assert.fail("Expected ExecutionException -> TimeoutException");
} catch (ExecutionException e) {
// Expected path - java.net.ConnectException ?
assertExpectedError(e, wsocket, ConnectException.class);
}
}
use of org.eclipse.jetty.websocket.api.Session in project jetty.project by eclipse.
the class ClientConnectTest method testBadHandshake_SwitchingProtocols_NoConnectionHeader.
@Test
public void testBadHandshake_SwitchingProtocols_NoConnectionHeader() throws Exception {
JettyTrackingSocket wsocket = new JettyTrackingSocket();
URI wsUri = server.getWsUri();
Future<Session> future = client.connect(wsocket, wsUri);
IBlockheadServerConnection connection = server.accept();
List<String> requestLines = connection.readRequestLines();
String key = connection.parseWebSocketKey(requestLines);
// Send Switching Protocols 101, but no 'Connection' header
StringBuilder resp = new StringBuilder();
resp.append("HTTP/1.1 101 Switching Protocols\r\n");
resp.append("Sec-WebSocket-Accept: ").append(AcceptHash.hashKey(key)).append("\r\n");
// Intentionally leave out Connection header
resp.append("\r\n");
connection.respond(resp.toString());
// The attempt to get upgrade response future should throw error
try {
future.get(30, TimeUnit.SECONDS);
Assert.fail("Expected ExecutionException -> UpgradeException");
} catch (ExecutionException e) {
// Expected Path
UpgradeException ue = assertExpectedError(e, wsocket, UpgradeException.class);
Assert.assertThat("UpgradeException.requestURI", ue.getRequestURI(), notNullValue());
Assert.assertThat("UpgradeException.requestURI", ue.getRequestURI().toASCIIString(), is(wsUri.toASCIIString()));
Assert.assertThat("UpgradeException.responseStatusCode", ue.getResponseStatusCode(), is(101));
}
}
Aggregations