Search in sources :

Example 1 with HttpResponse

use of org.eclipse.jetty.websocket.common.test.HttpResponse in project jetty.project by eclipse.

the class ConfiguratorTest method testEmptyConfigurator.

@Test
public void testEmptyConfigurator() throws Exception {
    URI uri = baseServerUri.resolve("/empty");
    try (IBlockheadClient client = new BlockheadClient(uri)) {
        client.addExtensions("identity");
        client.connect();
        client.sendStandardRequest();
        HttpResponse response = client.readResponseHeader();
        Assert.assertThat("response.extensions", response.getExtensionsHeader(), is("identity"));
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) HttpResponse(org.eclipse.jetty.websocket.common.test.HttpResponse) URI(java.net.URI) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) Test(org.junit.Test)

Example 2 with HttpResponse

use of org.eclipse.jetty.websocket.common.test.HttpResponse in project jetty.project by eclipse.

the class WebSocketInvalidVersionTest method testRequestVersion29.

/**
     * Test the requirement of responding with an http 400 when using a Sec-WebSocket-Version that is unsupported.
     * @throws Exception on test failure
     */
@Test
public void testRequestVersion29() throws Exception {
    @SuppressWarnings("resource") BlockheadClient client = new BlockheadClient(server.getServerUri());
    // intentionally bad version
    client.setVersion(29);
    try {
        client.connect();
        client.sendStandardRequest();
        HttpResponse response = client.readResponseHeader();
        Assert.assertThat("Response Status Code", response.getStatusCode(), is(400));
        Assert.assertThat("Response Status Reason", response.getStatusReason(), containsString("Unsupported websocket version specification"));
        Assert.assertThat("Response Versions", response.getHeader("Sec-WebSocket-Version"), is("13"));
    } finally {
        client.disconnect();
    }
}
Also used : BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) HttpResponse(org.eclipse.jetty.websocket.common.test.HttpResponse) Test(org.junit.Test)

Example 3 with HttpResponse

use of org.eclipse.jetty.websocket.common.test.HttpResponse in project jetty.project by eclipse.

the class ChromeTest method testUpgradeWithWebkitDeflateExtension.

@Test
public void testUpgradeWithWebkitDeflateExtension() throws Exception {
    Assume.assumeTrue("Server has x-webkit-deflate-frame registered", server.getWebSocketServletFactory().getExtensionFactory().isAvailable("x-webkit-deflate-frame"));
    BlockheadClient client = new BlockheadClient(server.getServerUri());
    try {
        client.addExtensions("x-webkit-deflate-frame");
        client.setProtocols("chat");
        client.connect();
        client.sendStandardRequest();
        HttpResponse response = client.expectUpgradeResponse();
        Assert.assertThat("Response", response.getExtensionsHeader(), containsString("x-webkit-deflate-frame"));
        // 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) 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 4 with HttpResponse

use of org.eclipse.jetty.websocket.common.test.HttpResponse 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 5 with HttpResponse

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

Aggregations

BlockheadClient (org.eclipse.jetty.websocket.common.test.BlockheadClient)6 HttpResponse (org.eclipse.jetty.websocket.common.test.HttpResponse)6 Test (org.junit.Test)6 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)4 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)4 URI (java.net.URI)2 IBlockheadClient (org.eclipse.jetty.websocket.common.test.IBlockheadClient)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2