use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class WebSocketServletRFCTest method testUppercaseUpgrade.
/**
* Test http://tools.ietf.org/html/rfc6455#section-4.1 where server side upgrade handling is supposed to be case insensitive.
* <p>
* This test will simulate a client requesting upgrade with all uppercase headers.
* @throws Exception on test failure
*/
@Test
public void testUppercaseUpgrade() throws Exception {
BlockheadClient client = new BlockheadClient(server.getServerUri());
try {
client.connect();
StringBuilder req = new StringBuilder();
req.append("GET ").append(client.getRequestPath()).append(" HTTP/1.1\r\n");
req.append("HOST: ").append(client.getRequestHost()).append("\r\n");
req.append("UPGRADE: WEBSOCKET\r\n");
req.append("CONNECTION: UPGRADE\r\n");
req.append("SEC-WEBSOCKET-KEY: ").append(client.getRequestWebSocketKey()).append("\r\n");
req.append("SEC-WEBSOCKET-ORIGIN: ").append(client.getRequestWebSocketOrigin()).append("\r\n");
req.append("SEC-WEBSOCKET-PROTOCOL: ECHO\r\n");
req.append("SEC-WEBSOCKET-VERSION: 13\r\n");
req.append("\r\n");
client.writeRaw(req.toString());
client.expectUpgradeResponse();
// Generate text frame
String msg = "this is an echo ... cho ... ho ... o";
client.write(new TextFrame().setPayload(msg));
// Read frame (hopefully text frame)
EventQueue<WebSocketFrame> frames = client.readFrames(1, 30, TimeUnit.SECONDS);
WebSocketFrame tf = frames.poll();
Assert.assertThat("Text Frame.status code", tf.getPayloadAsUTF8(), is(msg));
} finally {
client.close();
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class WebSocketUpgradeFilterTest method testNormalConfiguration.
@Test
public void testNormalConfiguration() throws Exception {
URI destUri = serverUri.resolve("/info/");
try (BlockheadClient client = new BlockheadClient(destUri)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.write(new TextFrame().setPayload("hello"));
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1000, TimeUnit.MILLISECONDS);
String payload = frames.poll().getPayloadAsUTF8();
// If we can connect and send a text message, we know that the endpoint was
// added properly, and the response will help us verify the policy configuration too
assertThat("payload", payload, containsString("session.maxTextMessageSize=" + (10 * 1024 * 1024)));
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class WebSocketUpgradeFilterTest method testStopStartOfHandler.
@Test
public void testStopStartOfHandler() throws Exception {
URI destUri = serverUri.resolve("/info/");
try (BlockheadClient client = new BlockheadClient(destUri)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.write(new TextFrame().setPayload("hello 1"));
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1000, TimeUnit.MILLISECONDS);
String payload = frames.poll().getPayloadAsUTF8();
// If we can connect and send a text message, we know that the endpoint was
// added properly, and the response will help us verify the policy configuration too
assertThat("payload", payload, containsString("session.maxTextMessageSize=" + (10 * 1024 * 1024)));
}
server.getHandler().stop();
server.getHandler().start();
try (BlockheadClient client = new BlockheadClient(destUri)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.write(new TextFrame().setPayload("hello 2"));
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1000, TimeUnit.MILLISECONDS);
String payload = frames.poll().getPayloadAsUTF8();
// If we can connect and send a text message, we know that the endpoint was
// added properly, and the response will help us verify the policy configuration too
assertThat("payload", payload, containsString("session.maxTextMessageSize=" + (10 * 1024 * 1024)));
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class WebSocketCloseTest method testFastFail.
/**
* Test fast fail (bug #410537)
*
* @throws Exception
* on test failure
*/
@Test
public void testFastFail() throws Exception {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) {
client.setProtocols("fastfail");
client.setTimeout(5, TimeUnit.SECONDS);
try (StacklessLogging scope = new StacklessLogging(FastFailSocket.class, WebSocketSession.class)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
EventQueue<WebSocketFrame> frames = client.readFrames(1, 5, TimeUnit.SECONDS);
WebSocketFrame frame = frames.poll();
assertThat("frames[0].opcode", frame.getOpCode(), is(OpCode.CLOSE));
CloseInfo close = new CloseInfo(frame);
assertThat("Close Status Code", close.getStatusCode(), is(StatusCode.SERVER_ERROR));
// respond with close
client.write(close.asFrame());
// ensure server socket got close event
assertThat("Fast Fail Latch", closeSocket.closeLatch.await(5, TimeUnit.SECONDS), is(true));
assertThat("Fast Fail.statusCode", closeSocket.closeStatusCode, is(StatusCode.SERVER_ERROR));
assertThat("Fast Fail.errors", closeSocket.errors.size(), is(1));
}
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class WebSocketCloseTest method testOpenSessionCleanup.
/**
* Test session open session cleanup (bug #474936)
*
* @throws Exception
* on test failure
*/
@Test
public void testOpenSessionCleanup() throws Exception {
fastFail();
fastClose();
dropConnection();
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) {
client.setProtocols("container");
client.setTimeout(1, TimeUnit.SECONDS);
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
TextFrame text = new TextFrame();
text.setPayload("openSessions");
client.write(text);
EventQueue<WebSocketFrame> frames = client.readFrames(2, 1, TimeUnit.SECONDS);
WebSocketFrame frame = frames.poll();
assertThat("frames[0].opcode", frame.getOpCode(), is(OpCode.TEXT));
String resp = frame.getPayloadAsUTF8();
assertThat("Should only have 1 open session", resp, containsString("openSessions.size=1\n"));
frame = frames.poll();
assertThat("frames[1].opcode", frame.getOpCode(), is(OpCode.CLOSE));
CloseInfo close = new CloseInfo(frame);
assertThat("Close Status Code", close.getStatusCode(), is(StatusCode.NORMAL));
// respond with close
client.write(close.asFrame());
// ensure server socket got close event
assertThat("Open Sessions Latch", closeSocket.closeLatch.await(1, TimeUnit.SECONDS), is(true));
assertThat("Open Sessions.statusCode", closeSocket.closeStatusCode, is(StatusCode.NORMAL));
assertThat("Open Sessions.errors", closeSocket.errors.size(), is(0));
}
}
Aggregations