Search in sources :

Example 91 with TextFrame

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

the class ConfiguratorTest method testProtocol_AltHeaderCase.

/**
     * Test of Sec-WebSocket-Protocol, using non-spec case header
     * @throws Exception on test failure
     */
@Test
public void testProtocol_AltHeaderCase() 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 92 with TextFrame

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

the class ConfiguratorTest method testDecoderWithProtocol.

/**
     * Test of Sec-WebSocket-Protocol, using non-spec case header
     */
@Test
public void testDecoderWithProtocol() throws Exception {
    URI uri = baseServerUri.resolve("/timedecoder");
    try (BlockheadClient client = new BlockheadClient(uri)) {
        client.addHeader("Sec-Websocket-Protocol: gmt\r\n");
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        client.write(new TextFrame().setPayload("2016-06-20T14:27:44"));
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
        WebSocketFrame frame = frames.poll();
        Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is("cal=2016.06.20 AD at 14:27:44 +0000"));
    }
}
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) Test(org.junit.Test)

Example 93 with TextFrame

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

the class WebSocketServerSessionTest method testDisconnect.

@Test
public void testDisconnect() throws Exception {
    URI uri = server.getServerUri().resolve("/test/disconnect");
    try (IBlockheadClient client = new BlockheadClient(uri)) {
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        client.write(new TextFrame().setPayload("harsh-disconnect"));
        client.awaitDisconnect(1, TimeUnit.SECONDS);
    }
}
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) URI(java.net.URI) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) Test(org.junit.Test)

Example 94 with TextFrame

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

the class WebSocketServletRFCTest method testEcho.

/**
     * Test the requirement of issuing socket and receiving echo response
     * @throws Exception on test failure
     */
@Test
public void testEcho() throws Exception {
    BlockheadClient client = new BlockheadClient(server.getServerUri());
    try {
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        // Generate text frame
        String msg = "this is an echo ... cho ... ho ... o";
        client.write(new TextFrame().setPayload(msg));
        // Read frame (hopefully text frame)
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 30, TimeUnit.SECONDS);
        WebSocketFrame tf = frames.poll();
        Assert.assertThat("Text Frame.status code", tf.getPayloadAsUTF8(), is(msg));
    } finally {
        client.close();
    }
}
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) Test(org.junit.Test)

Example 95 with TextFrame

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

the class WebSocketServletRFCTest method testLowercaseUpgrade.

/**
     * Test http://tools.ietf.org/html/rfc6455#section-4.1 where server side upgrade handling is supposed to be case insensitive.
     * <p>
     * This test will simulate a client requesting upgrade with all lowercase headers.
     * @throws Exception on test failure
     */
@Test
public void testLowercaseUpgrade() throws Exception {
    BlockheadClient client = new BlockheadClient(server.getServerUri());
    try {
        client.connect();
        StringBuilder req = new StringBuilder();
        req.append("GET ").append(client.getRequestPath()).append(" HTTP/1.1\r\n");
        req.append("Host: ").append(client.getRequestHost()).append("\r\n");
        req.append("Upgrade: websocket\r\n");
        req.append("connection: upgrade\r\n");
        req.append("sec-websocket-key: ").append(client.getRequestWebSocketKey()).append("\r\n");
        req.append("sec-websocket-origin: ").append(client.getRequestWebSocketOrigin()).append("\r\n");
        req.append("sec-websocket-protocol: echo\r\n");
        req.append("sec-websocket-version: 13\r\n");
        req.append("\r\n");
        client.writeRaw(req.toString());
        client.expectUpgradeResponse();
        // Generate text frame
        String msg = "this is an echo ... cho ... ho ... o";
        client.write(new TextFrame().setPayload(msg));
        // Read frame (hopefully text frame)
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 30, TimeUnit.SECONDS);
        WebSocketFrame tf = frames.poll();
        Assert.assertThat("Text Frame.status code", tf.getPayloadAsUTF8(), is(msg));
    } finally {
        client.close();
    }
}
Also used : BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) Utf8StringBuilder(org.eclipse.jetty.util.Utf8StringBuilder) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) 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