Search in sources :

Example 86 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo 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)

Example 87 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class TestABCase7_3 method testCase7_3_1GenerateEmptyClose.

@Test
public void testCase7_3_1GenerateEmptyClose() {
    CloseInfo close = new CloseInfo();
    ByteBuffer actual = UnitGenerator.generate(close.asFrame());
    ByteBuffer expected = ByteBuffer.allocate(5);
    expected.put(new byte[] { (byte) 0x88, (byte) 0x00 });
    expected.flip();
    ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
Also used : CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 88 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class MisbehavingClassTest method testAnnotatedRuntimeOnConnect.

@Test
public void testAnnotatedRuntimeOnConnect() throws Exception {
    try (IBlockheadClient client = new BlockheadClient(server.getServerUri());
        StacklessLogging scope = new StacklessLogging(AnnotatedRuntimeOnConnectSocket.class, WebSocketSession.class)) {
        client.setProtocols("annotated-runtime-connect");
        client.setTimeout(1, TimeUnit.SECONDS);
        AnnotatedRuntimeOnConnectSocket socket = badSocketsServlet.annotatedRuntimeConnect;
        socket.reset();
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
        WebSocketFrame frame = frames.poll();
        assertThat("frames[0].opcode", frame.getOpCode(), is(OpCode.CLOSE));
        CloseInfo close = new CloseInfo(frame);
        assertThat("Close Status Code", close.getStatusCode(), is(StatusCode.SERVER_ERROR));
        // respond with close
        client.write(close.asFrame());
        // ensure server socket got close event
        assertThat("Close Latch", socket.closeLatch.await(1, TimeUnit.SECONDS), is(true));
        assertThat("closeStatusCode", socket.closeStatusCode, is(StatusCode.SERVER_ERROR));
        // Validate errors
        assertThat("socket.onErrors", socket.errors.size(), is(1));
        Throwable cause = socket.errors.pop();
        assertThat("Error type", cause, instanceOf(RuntimeException.class));
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 89 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class WebSocketServletRFCTest method testTextNotUTF8.

@Test
public void testTextNotUTF8() throws Exception {
    try (StacklessLogging stackless = new StacklessLogging(Parser.class);
        BlockheadClient client = new BlockheadClient(server.getServerUri())) {
        client.setProtocols("other");
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        byte[] buf = new byte[] { (byte) 0xC2, (byte) 0xC3 };
        WebSocketFrame txt = new TextFrame().setPayload(ByteBuffer.wrap(buf));
        txt.setMask(Hex.asByteArray("11223344"));
        ByteBuffer bbHeader = generator.generateHeaderBytes(txt);
        client.writeRaw(bbHeader);
        client.writeRaw(txt.getPayload());
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 30, TimeUnit.SECONDS);
        WebSocketFrame frame = frames.poll();
        Assert.assertThat("frames[0].opcode", frame.getOpCode(), is(OpCode.CLOSE));
        CloseInfo close = new CloseInfo(frame);
        Assert.assertThat("Close Status Code", close.getStatusCode(), is(StatusCode.BAD_PAYLOAD));
    }
}
Also used : BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 90 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class TestABCase9 method testCase9_1_5.

/**
     * Echo 8MB text message (1 frame)
     * @throws Exception on test failure
     */
@Test
@Stress("High I/O use")
public void testCase9_1_5() throws Exception {
    byte[] utf = new byte[8 * MBYTE];
    Arrays.fill(utf, (byte) 'y');
    ByteBuffer buf = ByteBuffer.wrap(utf);
    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(Fuzzer.SendMode.BULK);
        fuzzer.send(send);
        fuzzer.expect(expect, 16, TimeUnit.SECONDS);
    }
}
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) Stress(org.eclipse.jetty.toolchain.test.annotation.Stress)

Aggregations

CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)151 Test (org.junit.Test)129 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)118 ArrayList (java.util.ArrayList)104 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)104 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)68 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)55 ByteBuffer (java.nio.ByteBuffer)48 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)30 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)27 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)19 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)17 BlockheadClient (org.eclipse.jetty.websocket.common.test.BlockheadClient)14 IBlockheadClient (org.eclipse.jetty.websocket.common.test.IBlockheadClient)10 CloseableLocalWebSocketSession (org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession)8 LocalWebSocketSession (org.eclipse.jetty.websocket.common.io.LocalWebSocketSession)8 Stress (org.eclipse.jetty.toolchain.test.annotation.Stress)6 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)5 CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4