Search in sources :

Example 11 with TextFrame

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

the class ConfiguratorTest method testCaptureRequestHeadersConfigurator.

@Test
public void testCaptureRequestHeadersConfigurator() throws Exception {
    URI uri = baseServerUri.resolve("/capture-request-headers");
    try (IBlockheadClient client = new BlockheadClient(uri)) {
        client.addHeader("X-Dummy: Bogus\r\n");
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        client.write(new TextFrame().setPayload("X-Dummy"));
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
        WebSocketFrame frame = frames.poll();
        Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is("Request Header [X-Dummy]: \"Bogus\""));
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) URI(java.net.URI) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) Test(org.junit.Test)

Example 12 with TextFrame

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

the class ConfiguratorTest method testProtocol_Triple.

/**
     * Test of Sec-WebSocket-Protocol, as seen in RFC-6455, 3 protocols
     * @throws Exception on test failure
     */
@Test
public void testProtocol_Triple() throws Exception {
    URI uri = baseServerUri.resolve("/protocols");
    ProtocolsConfigurator.seenProtocols.set(null);
    try (IBlockheadClient client = new BlockheadClient(uri)) {
        client.addHeader("Sec-WebSocket-Protocol: echo, chat, status\r\n");
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        client.write(new TextFrame().setPayload("getProtocols"));
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
        WebSocketFrame frame = frames.poll();
        Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is("Requested Protocols: [\"echo\",\"chat\",\"status\"]"));
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) URI(java.net.URI) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) Test(org.junit.Test)

Example 13 with TextFrame

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

the class ConfiguratorTest method testProtocol_LowercaseHeader.

/**
     * Test of Sec-WebSocket-Protocol, using all lowercase header
     * @throws Exception on test failure
     */
@Test
public void testProtocol_LowercaseHeader() throws Exception {
    URI uri = baseServerUri.resolve("/protocols");
    ProtocolsConfigurator.seenProtocols.set(null);
    try (IBlockheadClient client = new BlockheadClient(uri)) {
        client.addHeader("sec-websocket-protocol: echo, chat, status\r\n");
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        client.write(new TextFrame().setPayload("getProtocols"));
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
        WebSocketFrame frame = frames.poll();
        Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is("Requested Protocols: [\"echo\",\"chat\",\"status\"]"));
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) URI(java.net.URI) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) Test(org.junit.Test)

Example 14 with TextFrame

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

the class ServerWriteThread method run.

@Override
public void run() {
    final AtomicInteger m = new AtomicInteger();
    try {
        while (m.get() < messageCount) {
            conn.write(new TextFrame().setPayload(message));
            m.incrementAndGet();
            if (slowness > 0) {
                TimeUnit.MILLISECONDS.sleep(slowness);
            }
        }
    } catch (InterruptedException | IOException e) {
        LOG.warn(e);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) IOException(java.io.IOException)

Example 15 with TextFrame

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

the class TestABCase5 method testCase5_13.

/**
     * Send continuation+!fin, then text+fin (framewise)
     * @throws Exception on test failure
     */
@Test
public void testCase5_13() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new ContinuationFrame().setPayload("sorry").setFin(false));
    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)

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