Search in sources :

Example 51 with TextFrame

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

the class FragmentExtensionTest method testFragmentExtension.

@Test
public void testFragmentExtension() throws Exception {
    int fragSize = 4;
    BlockheadClient client = new BlockheadClient(server.getServerUri());
    client.clearExtensions();
    client.addExtensions("fragment;maxLength=" + fragSize);
    client.setProtocols("onConnect");
    try {
        // Make sure the read times out if there are problems with the implementation
        client.setTimeout(1, TimeUnit.SECONDS);
        client.connect();
        client.sendStandardRequest();
        HttpResponse resp = client.expectUpgradeResponse();
        Assert.assertThat("Response", resp.getExtensionsHeader(), containsString("fragment"));
        String msg = "Sent as a long message that should be split";
        client.write(new TextFrame().setPayload(msg));
        String[] parts = split(msg, fragSize);
        EventQueue<WebSocketFrame> frames = client.readFrames(parts.length, 1000, TimeUnit.MILLISECONDS);
        for (int i = 0; i < parts.length; i++) {
            WebSocketFrame frame = frames.poll();
            Assert.assertThat("text[" + i + "].payload", frame.getPayloadAsUTF8(), is(parts[i]));
        }
    } finally {
        client.close();
    }
}
Also used : BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) HttpResponse(org.eclipse.jetty.websocket.common.test.HttpResponse) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 52 with TextFrame

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

the class IdentityExtensionTest method testIdentityExtension.

@Test
public void testIdentityExtension() throws Exception {
    BlockheadClient client = new BlockheadClient(server.getServerUri());
    client.clearExtensions();
    client.addExtensions("identity;param=0");
    client.addExtensions("identity;param=1, identity ; param = '2' ; other = ' some = value '");
    client.setProtocols("onConnect");
    try {
        // Make sure the read times out if there are problems with the implementation
        client.setTimeout(1, TimeUnit.SECONDS);
        client.connect();
        client.sendStandardRequest();
        HttpResponse resp = client.expectUpgradeResponse();
        Assert.assertThat("Response", resp.getExtensionsHeader(), containsString("identity"));
        client.write(new TextFrame().setPayload("Hello"));
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 1000, TimeUnit.MILLISECONDS);
        WebSocketFrame frame = frames.poll();
        Assert.assertThat("TEXT.payload", frame.getPayloadAsUTF8(), is("Hello"));
    } finally {
        client.close();
    }
}
Also used : BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) HttpResponse(org.eclipse.jetty.websocket.common.test.HttpResponse) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) Test(org.junit.Test)

Example 53 with TextFrame

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

the class TestABCase1 method testCase1_1_6.

/**
     * Echo 65535 byte TEXT message (uses medium 2 byte payload length)
     * @throws Exception on test failure
     */
@Test
public void testCase1_1_6() throws Exception {
    byte[] payload = new byte[65535];
    Arrays.fill(payload, (byte) '*');
    ByteBuffer buf = ByteBuffer.wrap(payload);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload(buf));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new TextFrame().setPayload(clone(buf)));
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(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) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 54 with TextFrame

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

the class TestABCase1 method testCase1_1_3.

/**
     * Echo 126 byte TEXT message (uses medium 2 byte payload length)
     * @throws Exception on test failure
     */
@Test
public void testCase1_1_3() throws Exception {
    byte[] payload = new byte[126];
    Arrays.fill(payload, (byte) '*');
    ByteBuffer buf = ByteBuffer.wrap(payload);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload(buf));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new TextFrame().setPayload(clone(buf)));
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(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) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 55 with TextFrame

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

the class TestABCase1 method testCase1_1_2.

/**
     * Echo 125 byte TEXT message (uses small 7-bit payload length)
     * @throws Exception on test failure
     */
@Test
public void testCase1_1_2() throws Exception {
    byte[] payload = new byte[125];
    Arrays.fill(payload, (byte) '*');
    ByteBuffer buf = ByteBuffer.wrap(payload);
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload(buf));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new TextFrame().setPayload(clone(buf)));
    expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this)) {
        fuzzer.connect();
        fuzzer.setSendMode(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) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Aggregations

TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)142 Test (org.junit.Test)130 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)109 ArrayList (java.util.ArrayList)69 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)68 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)59 ByteBuffer (java.nio.ByteBuffer)54 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)38 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)35 BlockheadClient (org.eclipse.jetty.websocket.common.test.BlockheadClient)33 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)23 IBlockheadClient (org.eclipse.jetty.websocket.common.test.IBlockheadClient)14 URI (java.net.URI)13 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)12 Matchers.containsString (org.hamcrest.Matchers.containsString)10 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)9 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)8 ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)6 UnitParser (org.eclipse.jetty.websocket.common.test.UnitParser)6 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)5