use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class ConfiguratorTest method testProtocol_AltHeaderCase.
/**
* Test of Sec-WebSocket-Protocol, using non-spec case header
* @throws Exception on test failure
*/
@Test
public void testProtocol_AltHeaderCase() throws Exception {
URI uri = baseServerUri.resolve("/protocols");
ProtocolsConfigurator.seenProtocols.set(null);
try (IBlockheadClient client = new BlockheadClient(uri)) {
client.addHeader("Sec-Websocket-Protocol: echo, chat, status\r\n");
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.write(new TextFrame().setPayload("getProtocols"));
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
WebSocketFrame frame = frames.poll();
Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is("Requested Protocols: [\"echo\",\"chat\",\"status\"]"));
}
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class ConfiguratorTest method testDecoderWithProtocol.
/**
* Test of Sec-WebSocket-Protocol, using non-spec case header
*/
@Test
public void testDecoderWithProtocol() throws Exception {
URI uri = baseServerUri.resolve("/timedecoder");
try (BlockheadClient client = new BlockheadClient(uri)) {
client.addHeader("Sec-Websocket-Protocol: gmt\r\n");
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.write(new TextFrame().setPayload("2016-06-20T14:27:44"));
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
WebSocketFrame frame = frames.poll();
Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is("cal=2016.06.20 AD at 14:27:44 +0000"));
}
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class WebSocketServerSessionTest method testDisconnect.
@Test
public void testDisconnect() throws Exception {
URI uri = server.getServerUri().resolve("/test/disconnect");
try (IBlockheadClient client = new BlockheadClient(uri)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.write(new TextFrame().setPayload("harsh-disconnect"));
client.awaitDisconnect(1, TimeUnit.SECONDS);
}
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class WebSocketServletRFCTest method testEcho.
/**
* Test the requirement of issuing socket and receiving echo response
* @throws Exception on test failure
*/
@Test
public void testEcho() throws Exception {
BlockheadClient client = new BlockheadClient(server.getServerUri());
try {
client.connect();
client.sendStandardRequest();
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.frames.TextFrame in project jetty.project by eclipse.
the class WebSocketServletRFCTest method testLowercaseUpgrade.
/**
* 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 lowercase headers.
* @throws Exception on test failure
*/
@Test
public void testLowercaseUpgrade() 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();
}
}
Aggregations