Search in sources :

Example 11 with ContinuationFrame

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

the class TestABCase6 method fragmentText.

/**
     * Split a message byte array into a series of fragments (frames + continuations) of 1 byte message contents each.
     * @param frames the frames
     * @param msg the message
     */
protected void fragmentText(List<WebSocketFrame> frames, byte[] msg) {
    int len = msg.length;
    boolean continuation = false;
    byte[] mini;
    for (int i = 0; i < len; i++) {
        DataFrame frame = null;
        if (continuation) {
            frame = new ContinuationFrame();
        } else {
            frame = new TextFrame();
        }
        mini = new byte[1];
        mini[0] = msg[i];
        frame.setPayload(ByteBuffer.wrap(mini));
        boolean isLast = (i >= (len - 1));
        frame.setFin(isLast);
        frames.add(frame);
        continuation = true;
    }
}
Also used : TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) DataFrame(org.eclipse.jetty.websocket.common.frames.DataFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame)

Example 12 with ContinuationFrame

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

the class TestABCase6 method testCase6_4_1.

/**
     * invalid text message, 3 fragments.
     * <p>
     * fragment #1 and fragment #3 are both valid in themselves.
     * <p>
     * fragment #2 contains the invalid utf8 code point.
     * @throws Exception on test failure
     */
@Test
@Slow
public void testCase6_4_1() throws Exception {
    byte[] part1 = StringUtil.getUtf8Bytes("κόσμε");
    // invalid
    byte[] part2 = Hex.asByteArray("F4908080");
    byte[] part3 = StringUtil.getUtf8Bytes("edited");
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.BULK);
        fuzzer.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false));
        TimeUnit.SECONDS.sleep(1);
        fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part2)).setFin(false));
        TimeUnit.SECONDS.sleep(1);
        fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part3)).setFin(true));
        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) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 13 with ContinuationFrame

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

the class TestABCase6 method testCase6_1_2.

/**
     * text message, 0 length, 3 fragments
     * @throws Exception on test failure
     */
@Test
public void testCase6_1_2() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setFin(false));
    send.add(new ContinuationFrame().setFin(false));
    send.add(new ContinuationFrame().setFin(true));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new TextFrame());
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        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) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 14 with ContinuationFrame

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

the class TestABCase7 method testCase7_1_5.

/**
     * Text fin=false, close, then continuation fin=true
     * @throws Exception on test failure
     */
@Test
public void testCase7_1_5() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload("an").setFin(false));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    send.add(new ContinuationFrame().setPayload("ticipation").setFin(true));
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.BULK);
        fuzzer.send(send);
        fuzzer.expect(expect);
        fuzzer.expectNoMoreFrames();
    }
}
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) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 15 with ContinuationFrame

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

the class TestABCase5 method testCase5_5.

/**
     * Send text fragmented in 2 packets (slowly)
     * @throws Exception on test failure
     */
@Test
public void testCase5_5() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload("hello, ").setFin(false));
    send.add(new ContinuationFrame().setPayload("world").setFin(true));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new TextFrame().setPayload("hello, world"));
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this);
        StacklessLogging supress = new StacklessLogging(Parser.class)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.SLOW);
        fuzzer.setSlowSendSegmentSize(1);
        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