use of org.eclipse.jetty.websocket.api.WebSocketPolicy in project jetty.project by eclipse.
the class PingPayloadParserTest method testBasicPingParsing.
@Test
public void testBasicPingParsing() {
ByteBuffer buf = ByteBuffer.allocate(16);
BufferUtil.clearToFill(buf);
buf.put(new byte[] { (byte) 0x89, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f });
BufferUtil.flipToFlush(buf, 0);
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(buf);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.PING, 1);
PingFrame ping = (PingFrame) capture.getFrames().poll();
String actual = BufferUtil.toUTF8String(ping.getPayload());
Assert.assertThat("PingFrame.payload", actual, is("Hello"));
}
use of org.eclipse.jetty.websocket.api.WebSocketPolicy in project jetty.project by eclipse.
the class RFC6455ExamplesParserTest method testSingleUnmasked256ByteBinaryMessage.
@Test
public void testSingleUnmasked256ByteBinaryMessage() {
int dataSize = 256;
ByteBuffer buf = ByteBuffer.allocate(dataSize + 10);
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
// 256 bytes binary message in a single unmasked frame
buf.put(new byte[] { (byte) 0x82, 0x7E });
// 16 bit size
buf.putShort((short) 0x01_00);
for (int i = 0; i < dataSize; i++) {
buf.put((byte) 0x44);
}
buf.flip();
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(buf);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.BINARY, 1);
Frame bin = capture.getFrames().poll();
Assert.assertThat("BinaryFrame.payloadLength", bin.getPayloadLength(), is(dataSize));
ByteBuffer data = bin.getPayload();
Assert.assertThat("BinaryFrame.payload.length", data.remaining(), is(dataSize));
for (int i = 0; i < dataSize; i++) {
Assert.assertThat("BinaryFrame.payload[" + i + "]", data.get(i), is((byte) 0x44));
}
}
use of org.eclipse.jetty.websocket.api.WebSocketPolicy in project jetty.project by eclipse.
the class RFC6455ExamplesParserTest method testSingleUnmaskedTextMessage.
@Test
public void testSingleUnmaskedTextMessage() {
ByteBuffer buf = ByteBuffer.allocate(16);
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
// A single-frame unmasked text message
buf.put(new byte[] { (byte) 0x81, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f });
buf.flip();
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(buf);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.TEXT, 1);
WebSocketFrame txt = capture.getFrames().poll();
String actual = BufferUtil.toUTF8String(txt.getPayload());
Assert.assertThat("TextFrame.payload", actual, is("Hello"));
}
use of org.eclipse.jetty.websocket.api.WebSocketPolicy in project jetty.project by eclipse.
the class RFC6455ExamplesParserTest method testSingleMaskedTextMessage.
@Test
public void testSingleMaskedTextMessage() {
ByteBuffer buf = ByteBuffer.allocate(16);
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
// A single-frame masked text message
buf.put(new byte[] { (byte) 0x81, (byte) 0x85, 0x37, (byte) 0xfa, 0x21, 0x3d, 0x7f, (byte) 0x9f, 0x4d, 0x51, 0x58 });
buf.flip();
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(buf);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.TEXT, 1);
WebSocketFrame txt = capture.getFrames().poll();
String actual = BufferUtil.toUTF8String(txt.getPayload());
Assert.assertThat("TextFrame.payload", actual, is("Hello"));
}
use of org.eclipse.jetty.websocket.api.WebSocketPolicy in project jetty.project by eclipse.
the class RFC6455ExamplesParserTest method testSingleUnmaskedPingRequest.
@Test
public void testSingleUnmaskedPingRequest() {
ByteBuffer buf = ByteBuffer.allocate(16);
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
// Unmasked Ping request
buf.put(new byte[] { (byte) 0x89, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f });
buf.flip();
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(buf);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.PING, 1);
WebSocketFrame ping = capture.getFrames().poll();
String actual = BufferUtil.toUTF8String(ping.getPayload());
Assert.assertThat("PingFrame.payload", actual, is("Hello"));
}
Aggregations