use of org.eclipse.jetty.websocket.api.UpgradeException in project jetty.project by eclipse.
the class ClientConnectTest method testBadHandshake.
@Test
public void testBadHandshake() throws Exception {
JettyTrackingSocket wsocket = new JettyTrackingSocket();
URI wsUri = server.getWsUri();
Future<Session> future = client.connect(wsocket, wsUri);
IBlockheadServerConnection connection = server.accept();
connection.readRequest();
// no upgrade, just fail with a 404 error
connection.respond("HTTP/1.1 404 NOT FOUND\r\n" + "Content-Length: 0\r\n" + "\r\n");
// 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(404));
}
}
use of org.eclipse.jetty.websocket.api.UpgradeException in project jetty.project by eclipse.
the class ClientConnectTest method testBadUpgrade.
@Test
public void testBadUpgrade() throws Exception {
JettyTrackingSocket wsocket = new JettyTrackingSocket();
URI wsUri = server.getWsUri();
Future<Session> future = client.connect(wsocket, wsUri);
IBlockheadServerConnection connection = server.accept();
connection.readRequest();
// Upgrade badly
connection.respond("HTTP/1.1 101 Upgrade\r\n" + "Sec-WebSocket-Accept: rubbish\r\n" + "\r\n");
// 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));
}
}
use of org.eclipse.jetty.websocket.api.UpgradeException in project jetty.project by eclipse.
the class ClientConnectTest method testBadHandshake_GetOK.
@Test
public void testBadHandshake_GetOK() throws Exception {
JettyTrackingSocket wsocket = new JettyTrackingSocket();
URI wsUri = server.getWsUri();
Future<Session> future = client.connect(wsocket, wsUri);
IBlockheadServerConnection connection = server.accept();
connection.readRequest();
// Send OK to GET but not upgrade
connection.respond("HTTP/1.1 200 OK\r\n" + "Content-Length: 0\r\n" + "\r\n");
// 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.UpgradeException in project jetty.project by eclipse.
the class ClientConnectTest method testBadHandshake_SwitchingProtocols_InvalidConnectionHeader.
@Test
public void testBadHandshake_SwitchingProtocols_InvalidConnectionHeader() 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 invalid '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");
resp.append("Connection: close\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(101));
}
}
use of org.eclipse.jetty.websocket.api.UpgradeException in project incubator-pulsar by apache.
the class ProxyPublishConsumeTest method emptySubcriptionConsumerTest.
@Test(timeOut = 10000)
public void emptySubcriptionConsumerTest() throws Exception {
// Empty subcription name
final String consumerUri = "ws://localhost:" + port + "/ws/consumer/persistent/my-property/use/my-ns/my-topic2/?subscriptionType=Exclusive";
URI consumeUri = URI.create(consumerUri);
WebSocketClient consumeClient1 = new WebSocketClient();
SimpleConsumerSocket consumeSocket1 = new SimpleConsumerSocket();
try {
consumeClient1.start();
ClientUpgradeRequest consumeRequest1 = new ClientUpgradeRequest();
Future<Session> consumerFuture1 = consumeClient1.connect(consumeSocket1, consumeUri, consumeRequest1);
consumerFuture1.get();
Assert.fail("should fail: empty subscription");
} catch (Exception e) {
// Expected
Assert.assertTrue(e.getCause() instanceof UpgradeException);
Assert.assertEquals(((UpgradeException) e.getCause()).getResponseStatusCode(), HttpServletResponse.SC_BAD_REQUEST);
} finally {
stopWebSocketClient(consumeClient1);
}
}
Aggregations