Search in sources :

Example 36 with ContinuationFrame

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

the class TestABCase5 method testCase5_9.

/**
     * Send continuation+fin, then text+fin
     * @throws Exception on test failure
     */
@Test
public void testCase5_9() 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.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)

Example 37 with ContinuationFrame

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

the class TestABCase6 method testCase6_2_2.

/**
     * valid utf8 text message, 2 fragments (on UTF8 code point boundary)
     * @throws Exception on test failure
     */
@Test
public void testCase6_2_2() throws Exception {
    String utf1 = "Hello-습@쎟쎤";
    String utf2 = "쎼쎠쎡-UTF-8!!";
    ByteBuffer b1 = ByteBuffer.wrap(StringUtil.getUtf8Bytes(utf1));
    ByteBuffer b2 = ByteBuffer.wrap(StringUtil.getUtf8Bytes(utf2));
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload(b1).setFin(false));
    send.add(new ContinuationFrame().setPayload(b2).setFin(true));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    ByteBuffer e1 = ByteBuffer.allocate(100);
    e1.put(StringUtil.getUtf8Bytes(utf1));
    e1.put(StringUtil.getUtf8Bytes(utf2));
    e1.flip();
    expect.add(new TextFrame().setPayload(e1));
    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) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 38 with ContinuationFrame

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

the class WebSocketFrame method copy.

public static WebSocketFrame copy(Frame original) {
    WebSocketFrame copy;
    switch(original.getOpCode()) {
        case OpCode.BINARY:
            copy = new BinaryFrame();
            break;
        case OpCode.TEXT:
            copy = new TextFrame();
            break;
        case OpCode.CLOSE:
            copy = new CloseFrame();
            break;
        case OpCode.CONTINUATION:
            copy = new ContinuationFrame();
            break;
        case OpCode.PING:
            copy = new PingFrame();
            break;
        case OpCode.PONG:
            copy = new PongFrame();
            break;
        default:
            throw new IllegalArgumentException("Cannot copy frame with opcode " + original.getOpCode() + " - " + original);
    }
    copy.copyHeaders(original);
    ByteBuffer payload = original.getPayload();
    if (payload != null) {
        ByteBuffer payloadCopy = ByteBuffer.allocate(payload.remaining());
        payloadCopy.put(payload.slice()).flip();
        copy.setPayload(payloadCopy);
    }
    return copy;
}
Also used : PongFrame(org.eclipse.jetty.websocket.common.frames.PongFrame) BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) ByteBuffer(java.nio.ByteBuffer)

Example 39 with ContinuationFrame

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

the class WebSocketRemoteEndpoint method sendPartialBytes.

@Override
public void sendPartialBytes(ByteBuffer fragment, boolean isLast) throws IOException {
    boolean first = lockMsg(MsgType.PARTIAL_BINARY);
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("sendPartialBytes({}, {})", BufferUtil.toDetailString(fragment), isLast);
        }
        DataFrame frame = first ? new BinaryFrame() : new ContinuationFrame();
        frame.setPayload(fragment);
        frame.setFin(isLast);
        blockingWrite(frame);
    } finally {
        if (isLast)
            unlockMsg(MsgType.PARTIAL_BINARY);
    }
}
Also used : BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) DataFrame(org.eclipse.jetty.websocket.common.frames.DataFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame)

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