Search in sources :

Example 26 with ContinuationFrame

use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame 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 27 with ContinuationFrame

use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.

the class RFC6455ExamplesGeneratorTest method testFragmentedUnmaskedTextMessage.

@Test
public void testFragmentedUnmaskedTextMessage() {
    WebSocketFrame text1 = new TextFrame().setPayload("Hel").setFin(false);
    WebSocketFrame text2 = new ContinuationFrame().setPayload("lo");
    ByteBuffer actual1 = UnitGenerator.generate(text1);
    ByteBuffer actual2 = UnitGenerator.generate(text2);
    ByteBuffer expected1 = ByteBuffer.allocate(5);
    expected1.put(new byte[] { (byte) 0x01, (byte) 0x03, (byte) 0x48, (byte) 0x65, (byte) 0x6c });
    ByteBuffer expected2 = ByteBuffer.allocate(4);
    expected2.put(new byte[] { (byte) 0x80, (byte) 0x02, (byte) 0x6c, (byte) 0x6f });
    expected1.flip();
    expected2.flip();
    ByteBufferAssert.assertEquals("t1 buffers are not equal", expected1, actual1);
    ByteBufferAssert.assertEquals("t2 buffers are not equal", expected2, actual2);
}
Also used : TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 28 with ContinuationFrame

use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.

the class WebSocketServletRFCTest method testBinaryAggregate.

/**
     * Test that aggregation of binary frames into a single message occurs
     * @throws Exception on test failure
     */
@Test
public void testBinaryAggregate() throws Exception {
    BlockheadClient client = new BlockheadClient(server.getServerUri());
    try {
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        // Generate binary frames
        byte[] buf1 = new byte[128];
        byte[] buf2 = new byte[128];
        byte[] buf3 = new byte[128];
        Arrays.fill(buf1, (byte) 0xAA);
        Arrays.fill(buf2, (byte) 0xBB);
        Arrays.fill(buf3, (byte) 0xCC);
        WebSocketFrame bin;
        bin = new BinaryFrame().setPayload(buf1).setFin(false);
        // write buf1 (fin=false)
        client.write(bin);
        bin = new ContinuationFrame().setPayload(buf2).setFin(false);
        // write buf2 (fin=false)
        client.write(bin);
        bin = new ContinuationFrame().setPayload(buf3).setFin(true);
        // write buf3 (fin=true)
        client.write(bin);
        // Read frame echo'd back (hopefully a single binary frame)
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 30, TimeUnit.SECONDS);
        Frame binmsg = frames.poll();
        int expectedSize = buf1.length + buf2.length + buf3.length;
        Assert.assertThat("BinaryFrame.payloadLength", binmsg.getPayloadLength(), is(expectedSize));
        int aaCount = 0;
        int bbCount = 0;
        int ccCount = 0;
        ByteBuffer echod = binmsg.getPayload();
        while (echod.remaining() >= 1) {
            byte b = echod.get();
            switch(b) {
                case (byte) 0xAA:
                    aaCount++;
                    break;
                case (byte) 0xBB:
                    bbCount++;
                    break;
                case (byte) 0xCC:
                    ccCount++;
                    break;
                default:
                    Assert.fail(String.format("Encountered invalid byte 0x%02X", (byte) (0xFF & b)));
            }
        }
        Assert.assertThat("Echoed data count for 0xAA", aaCount, is(buf1.length));
        Assert.assertThat("Echoed data count for 0xBB", bbCount, is(buf2.length));
        Assert.assertThat("Echoed data count for 0xCC", ccCount, is(buf3.length));
    } finally {
        client.close();
    }
}
Also used : BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) Frame(org.eclipse.jetty.websocket.api.extensions.Frame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 29 with ContinuationFrame

use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.

the class TestABCase5 method testCase5_10.

/**
     * Send continuation+fin, then text+fin (framewise)
     * @throws Exception on test failure
     */
@Test
public void testCase5_10() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new ContinuationFrame().setPayload("sorry").setFin(true));
    send.add(new TextFrame().setPayload("hello, world"));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this);
        StacklessLogging supress = new StacklessLogging(Parser.class)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME);
        fuzzer.sendAndIgnoreBrokenPipe(send);
        fuzzer.expect(expect);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 30 with ContinuationFrame

use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.

the class TestABCase5 method testCase5_15.

/**
     * Send text fragmented properly in 2 frames, then continuation!fin, then text unfragmented.
     * @throws Exception on test failure
     */
@Test
public void testCase5_15() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload("fragment1").setFin(false));
    send.add(new ContinuationFrame().setPayload("fragment2").setFin(true));
    // bad frame
    send.add(new ContinuationFrame().setPayload("fragment3").setFin(false));
    send.add(new TextFrame().setPayload("fragment4").setFin(true));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new TextFrame().setPayload("fragment1fragment2"));
    expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this);
        StacklessLogging supress = new StacklessLogging(Parser.class)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.BULK);
        fuzzer.send(send);
        fuzzer.expect(expect);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Aggregations

ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)39 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)36 Test (org.junit.Test)34 ArrayList (java.util.ArrayList)31 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)29 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)26 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)26 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)20 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)11 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)9 ByteBuffer (java.nio.ByteBuffer)8 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)4 DataFrame (org.eclipse.jetty.websocket.common.frames.DataFrame)4 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)3 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)3 UnitParser (org.eclipse.jetty.websocket.common.test.UnitParser)3 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)2 CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)2 ProtocolException (org.eclipse.jetty.websocket.api.ProtocolException)1 ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)1