Search in sources :

Example 96 with WebSocketFrame

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

the class ConfiguratorTest method testNoExtensionsConfigurator.

@Test
public void testNoExtensionsConfigurator() throws Exception {
    URI uri = baseServerUri.resolve("/no-extensions");
    try (IBlockheadClient client = new BlockheadClient(uri)) {
        client.addExtensions("identity");
        client.connect();
        client.sendStandardRequest();
        HttpResponse response = client.expectUpgradeResponse();
        assertThat("response.extensions", response.getExtensionsHeader(), nullValue());
        client.write(new TextFrame().setPayload("NegoExts"));
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
        WebSocketFrame frame = frames.poll();
        assertThat("Frame Response", frame.getPayloadAsUTF8(), is("negotiatedExtensions=[]"));
    }
}
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) HttpResponse(org.eclipse.jetty.websocket.common.test.HttpResponse) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) URI(java.net.URI) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) Test(org.junit.Test)

Example 97 with WebSocketFrame

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

the class ConfiguratorTest method testUserPropsAddress.

@Test
public void testUserPropsAddress() throws Exception {
    URI uri = baseServerUri.resolve("/addr");
    // First request
    try (IBlockheadClient client = new BlockheadClient(uri)) {
        client.connect();
        client.sendStandardRequest();
        client.expectUpgradeResponse();
        InetSocketAddress expectedLocal = client.getLocalSocketAddress();
        InetSocketAddress expectedRemote = client.getRemoteSocketAddress();
        client.write(new TextFrame().setPayload("addr"));
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
        WebSocketFrame frame = frames.poll();
        StringWriter expected = new StringWriter();
        PrintWriter out = new PrintWriter(expected);
        // local <-> remote are opposite on server (duh)
        out.printf("[javax.websocket.endpoint.localAddress] = %s%n", toSafeAddr(expectedRemote));
        out.printf("[javax.websocket.endpoint.remoteAddress] = %s%n", toSafeAddr(expectedLocal));
        out.printf("[found.local] = %s%n", toSafeAddr(expectedRemote));
        out.printf("[found.remote] = %s%n", toSafeAddr(expectedLocal));
        Assert.assertThat("Frame Response", frame.getPayloadAsUTF8(), is(expected.toString()));
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) StringWriter(java.io.StringWriter) InetSocketAddress(java.net.InetSocketAddress) 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) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 98 with WebSocketFrame

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

the class ConfiguratorTest method testProtocol_Single.

/**
     * Test of Sec-WebSocket-Protocol, as seen in RFC-6455, 1 protocol
     * @throws Exception on test failure
     */
@Test
public void testProtocol_Single() throws Exception {
    URI uri = baseServerUri.resolve("/protocols");
    ProtocolsConfigurator.seenProtocols.set(null);
    try (IBlockheadClient client = new BlockheadClient(uri)) {
        client.addHeader("Sec-WebSocket-Protocol: echo\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\"]"));
    }
}
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 99 with WebSocketFrame

use of org.eclipse.jetty.websocket.common.WebSocketFrame 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 100 with WebSocketFrame

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

Aggregations

WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)185 Test (org.junit.Test)169 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)118 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)112 ArrayList (java.util.ArrayList)111 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)108 ByteBuffer (java.nio.ByteBuffer)79 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)51 BlockheadClient (org.eclipse.jetty.websocket.common.test.BlockheadClient)37 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)36 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)36 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)25 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)17 IBlockheadClient (org.eclipse.jetty.websocket.common.test.IBlockheadClient)17 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)14 URI (java.net.URI)12 ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)8 Stress (org.eclipse.jetty.toolchain.test.annotation.Stress)6