Search in sources :

Example 31 with PingFrame

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);
}
Also used : PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 32 with PingFrame

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);
}
Also used : PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 33 with PingFrame

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"));
}
Also used : WebSocketPolicy(org.eclipse.jetty.websocket.api.WebSocketPolicy) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) ByteBuffer(java.nio.ByteBuffer) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) Test(org.junit.Test)

Example 34 with PingFrame

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);
}
Also used : PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 35 with PingFrame

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;
}
Also used : PongFrame(org.eclipse.jetty.websocket.common.frames.PongFrame) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) ArrayList(java.util.ArrayList) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Parameters(org.junit.runners.Parameterized.Parameters)

Aggregations

PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)48 Test (org.junit.Test)45 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)33 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)30 ArrayList (java.util.ArrayList)28 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)27 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)24 ByteBuffer (java.nio.ByteBuffer)19 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)19 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)17 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)14 ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)4 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)4 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)4 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)3 CloseableLocalWebSocketSession (org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession)3 LocalWebSocketSession (org.eclipse.jetty.websocket.common.io.LocalWebSocketSession)3 ListenerPingPongSocket (examples.ListenerPingPongSocket)2 AbstractExtensionTest (org.eclipse.jetty.websocket.common.extensions.AbstractExtensionTest)2 FragmentExtension (org.eclipse.jetty.websocket.common.extensions.fragment.FragmentExtension)2