use of org.eclipse.jetty.websocket.common.frames.PingFrame in project jetty.project by eclipse.
the class WebSocketFrameTest method testLaxInvalidPing.
@Test
public void testLaxInvalidPing() {
WebSocketFrame frame = new PingFrame().setFin(false);
ByteBuffer actual = generateWholeFrame(laxGenerator, frame);
String expected = "0900";
assertFrameHex("Lax Invalid Ping Frame", expected, actual);
}
use of org.eclipse.jetty.websocket.common.frames.PingFrame in project jetty.project by eclipse.
the class ParserTest method testParseCase5_19.
/**
* Similar to the server side 5.19 testcase. text message, send in 5 frames/fragments, with 2 pings in the mix.
*/
@Test
public void testParseCase5_19() {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload("f1").setFin(false));
send.add(new ContinuationFrame().setPayload(",f2").setFin(false));
send.add(new PingFrame().setPayload("pong-1"));
send.add(new ContinuationFrame().setPayload(",f3").setFin(false));
send.add(new ContinuationFrame().setPayload(",f4").setFin(false));
send.add(new PingFrame().setPayload("pong-2"));
send.add(new ContinuationFrame().setPayload(",f5").setFin(true));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
ByteBuffer completeBuf = UnitGenerator.generate(send);
UnitParser parser = new UnitParser();
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parseQuietly(completeBuf);
capture.assertErrorCount(0);
capture.assertHasFrame(OpCode.TEXT, 1);
capture.assertHasFrame(OpCode.CONTINUATION, 4);
capture.assertHasFrame(OpCode.CLOSE, 1);
capture.assertHasFrame(OpCode.PING, 2);
}
use of org.eclipse.jetty.websocket.common.frames.PingFrame 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.common.frames.PingFrame in project jetty.project by eclipse.
the class RFC6455ExamplesGeneratorTest method testSingleUnmaskedPingRequest.
@Test
public void testSingleUnmaskedPingRequest() throws Exception {
PingFrame ping = new PingFrame().setPayload("Hello");
ByteBuffer actual = UnitGenerator.generate(ping);
ByteBuffer expected = ByteBuffer.allocate(10);
expected.put(new byte[] { (byte) 0x89, (byte) 0x05, (byte) 0x48, (byte) 0x65, (byte) 0x6c, (byte) 0x6c, (byte) 0x6f });
// make readable
expected.flip();
ByteBufferAssert.assertEquals("Ping buffers", expected, actual);
}
use of org.eclipse.jetty.websocket.common.frames.PingFrame in project jetty.project by eclipse.
the class TestABCase3 method data.
@Parameters
public static Collection<WebSocketFrame[]> data() {
List<WebSocketFrame[]> data = new ArrayList<>();
// @formatter:off
data.add(new WebSocketFrame[] { new PingFrame().setFin(false) });
data.add(new WebSocketFrame[] { new PingFrame().setRsv1(true) });
data.add(new WebSocketFrame[] { new PingFrame().setRsv2(true) });
data.add(new WebSocketFrame[] { new PingFrame().setRsv3(true) });
data.add(new WebSocketFrame[] { new PongFrame().setFin(false) });
data.add(new WebSocketFrame[] { new PingFrame().setRsv1(true) });
data.add(new WebSocketFrame[] { new PongFrame().setRsv2(true) });
data.add(new WebSocketFrame[] { new PongFrame().setRsv3(true) });
data.add(new WebSocketFrame[] { new CloseInfo().asFrame().setFin(false) });
data.add(new WebSocketFrame[] { new CloseInfo().asFrame().setRsv1(true) });
data.add(new WebSocketFrame[] { new CloseInfo().asFrame().setRsv2(true) });
data.add(new WebSocketFrame[] { new CloseInfo().asFrame().setRsv3(true) });
// @formatter:on
return data;
}
Aggregations