Search in sources :

Example 21 with ExtensionConfig

use of org.eclipse.jetty.websocket.api.extensions.ExtensionConfig in project jetty.project by eclipse.

the class PerMessageDeflateExtensionTest method getNegotiatedExtensionList.

private String getNegotiatedExtensionList(Session session) {
    StringBuilder actual = new StringBuilder();
    actual.append('[');
    boolean delim = false;
    for (ExtensionConfig ext : session.getUpgradeResponse().getExtensions()) {
        if (delim)
            actual.append(", ");
        actual.append(ext.getName());
        delim = true;
    }
    actual.append(']');
    return actual.toString();
}
Also used : ExtensionConfig(org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)

Example 22 with ExtensionConfig

use of org.eclipse.jetty.websocket.api.extensions.ExtensionConfig in project jetty.project by eclipse.

the class DeflateFrameExtensionTest method init.

private void init(DeflateFrameExtension ext) {
    ext.setConfig(new ExtensionConfig(ext.getName()));
    ext.setBufferPool(bufferPool);
}
Also used : ExtensionConfig(org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)

Example 23 with ExtensionConfig

use of org.eclipse.jetty.websocket.api.extensions.ExtensionConfig in project jetty.project by eclipse.

the class DeflateFrameExtensionTest method assertIncoming.

private void assertIncoming(byte[] raw, String... expectedTextDatas) {
    WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
    DeflateFrameExtension ext = new DeflateFrameExtension();
    ext.setBufferPool(bufferPool);
    ext.setPolicy(policy);
    ExtensionConfig config = ExtensionConfig.parse("deflate-frame");
    ext.setConfig(config);
    // Setup capture of incoming frames
    IncomingFramesCapture capture = new IncomingFramesCapture();
    // Wire up stack
    ext.setNextIncomingFrames(capture);
    Parser parser = new UnitParser(policy);
    parser.configureFromExtensions(Collections.singletonList(ext));
    parser.setIncomingFramesHandler(ext);
    parser.parse(ByteBuffer.wrap(raw));
    int len = expectedTextDatas.length;
    capture.assertFrameCount(len);
    capture.assertHasFrame(OpCode.TEXT, len);
    int i = 0;
    for (WebSocketFrame actual : capture.getFrames()) {
        String prefix = "Frame[" + i + "]";
        Assert.assertThat(prefix + ".opcode", actual.getOpCode(), is(OpCode.TEXT));
        Assert.assertThat(prefix + ".fin", actual.isFin(), is(true));
        // RSV1 should be unset at this point
        Assert.assertThat(prefix + ".rsv1", actual.isRsv1(), is(false));
        Assert.assertThat(prefix + ".rsv2", actual.isRsv2(), is(false));
        Assert.assertThat(prefix + ".rsv3", actual.isRsv3(), is(false));
        ByteBuffer expected = BufferUtil.toBuffer(expectedTextDatas[i], StandardCharsets.UTF_8);
        Assert.assertThat(prefix + ".payloadLength", actual.getPayloadLength(), is(expected.remaining()));
        ByteBufferAssert.assertEquals(prefix + ".payload", expected, actual.getPayload().slice());
        i++;
    }
}
Also used : WebSocketPolicy(org.eclipse.jetty.websocket.api.WebSocketPolicy) ExtensionConfig(org.eclipse.jetty.websocket.api.extensions.ExtensionConfig) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.websocket.common.Parser) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser)

Example 24 with ExtensionConfig

use of org.eclipse.jetty.websocket.api.extensions.ExtensionConfig in project jetty.project by eclipse.

the class DeflateFrameExtensionTest method assertOutgoing.

private void assertOutgoing(String text, String expectedHex) throws IOException {
    WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
    DeflateFrameExtension ext = new DeflateFrameExtension();
    ext.setBufferPool(bufferPool);
    ext.setPolicy(policy);
    ExtensionConfig config = ExtensionConfig.parse("deflate-frame");
    ext.setConfig(config);
    Generator generator = new Generator(policy, bufferPool, true);
    generator.configureFromExtensions(Collections.singletonList(ext));
    OutgoingNetworkBytesCapture capture = new OutgoingNetworkBytesCapture(generator);
    ext.setNextOutgoingFrames(capture);
    Frame frame = new TextFrame().setPayload(text);
    ext.outgoingFrame(frame, null, BatchMode.OFF);
    capture.assertBytes(0, expectedHex);
}
Also used : WebSocketPolicy(org.eclipse.jetty.websocket.api.WebSocketPolicy) BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) Frame(org.eclipse.jetty.websocket.api.extensions.Frame) ExtensionConfig(org.eclipse.jetty.websocket.api.extensions.ExtensionConfig) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) OutgoingNetworkBytesCapture(org.eclipse.jetty.websocket.common.test.OutgoingNetworkBytesCapture) Generator(org.eclipse.jetty.websocket.common.Generator)

Example 25 with ExtensionConfig

use of org.eclipse.jetty.websocket.api.extensions.ExtensionConfig in project jetty.project by eclipse.

the class PerMessageDeflateExtensionTest method testIncomingUncompressedFrames.

/**
     * Verify that incoming uncompressed frames are properly passed through
     */
@Test
public void testIncomingUncompressedFrames() {
    PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
    ext.setBufferPool(bufferPool);
    ext.setPolicy(WebSocketPolicy.newServerPolicy());
    ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
    ext.setConfig(config);
    // Setup capture of incoming frames
    IncomingFramesCapture capture = new IncomingFramesCapture();
    // Wire up stack
    ext.setNextIncomingFrames(capture);
    // Quote
    List<String> quote = new ArrayList<>();
    quote.add("No amount of experimentation can ever prove me right;");
    quote.add("a single experiment can prove me wrong.");
    quote.add("-- Albert Einstein");
    // leave frames as-is, no compression, and pass into extension
    for (String q : quote) {
        TextFrame frame = new TextFrame().setPayload(q);
        // indication to extension that frame is not compressed (ie: a normal frame)
        frame.setRsv1(false);
        ext.incomingFrame(frame);
    }
    int len = quote.size();
    capture.assertFrameCount(len);
    capture.assertHasFrame(OpCode.TEXT, len);
    String prefix;
    int i = 0;
    for (WebSocketFrame actual : capture.getFrames()) {
        prefix = "Frame[" + i + "]";
        Assert.assertThat(prefix + ".opcode", actual.getOpCode(), is(OpCode.TEXT));
        Assert.assertThat(prefix + ".fin", actual.isFin(), is(true));
        Assert.assertThat(prefix + ".rsv1", actual.isRsv1(), is(false));
        Assert.assertThat(prefix + ".rsv2", actual.isRsv2(), is(false));
        Assert.assertThat(prefix + ".rsv3", actual.isRsv3(), is(false));
        ByteBuffer expected = BufferUtil.toBuffer(quote.get(i), StandardCharsets.UTF_8);
        Assert.assertThat(prefix + ".payloadLength", actual.getPayloadLength(), is(expected.remaining()));
        ByteBufferAssert.assertEquals(prefix + ".payload", expected, actual.getPayload().slice());
        i++;
    }
}
Also used : ExtensionConfig(org.eclipse.jetty.websocket.api.extensions.ExtensionConfig) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) AbstractExtensionTest(org.eclipse.jetty.websocket.common.extensions.AbstractExtensionTest) Test(org.junit.Test)

Aggregations

ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)26 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)10 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)10 ByteBuffer (java.nio.ByteBuffer)9 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)8 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)7 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)7 FragmentExtension (org.eclipse.jetty.websocket.common.extensions.fragment.FragmentExtension)5 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)5 AbstractExtensionTest (org.eclipse.jetty.websocket.common.extensions.AbstractExtensionTest)4 OutgoingFramesCapture (org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture)4 IOException (java.io.IOException)3 WebSocketPolicy (org.eclipse.jetty.websocket.api.WebSocketPolicy)3 ExtensionStack (org.eclipse.jetty.websocket.common.extensions.ExtensionStack)3 Extension (org.eclipse.jetty.websocket.api.extensions.Extension)2 Generator (org.eclipse.jetty.websocket.common.Generator)2 IdentityExtension (org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension)2 OutgoingNetworkBytesCapture (org.eclipse.jetty.websocket.common.test.OutgoingNetworkBytesCapture)2