Search in sources :

Example 11 with ExtensionConfig

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

the class DeflateFrameExtensionTest method testGeneratedTwoFrames.

@Test
public void testGeneratedTwoFrames() throws IOException {
    WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
    DeflateFrameExtension ext = new DeflateFrameExtension();
    ext.setBufferPool(bufferPool);
    ext.setPolicy(policy);
    ext.setConfig(new ExtensionConfig(ext.getName()));
    Generator generator = new Generator(policy, bufferPool, true);
    generator.configureFromExtensions(Collections.singletonList(ext));
    OutgoingNetworkBytesCapture capture = new OutgoingNetworkBytesCapture(generator);
    ext.setNextOutgoingFrames(capture);
    ext.outgoingFrame(new TextFrame().setPayload("Hello"), null, BatchMode.OFF);
    ext.outgoingFrame(new TextFrame().setPayload("There"), null, BatchMode.OFF);
    capture.assertBytes(0, "c107f248cdc9c90700");
}
Also used : WebSocketPolicy(org.eclipse.jetty.websocket.api.WebSocketPolicy) 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) AbstractExtensionTest(org.eclipse.jetty.websocket.common.extensions.AbstractExtensionTest) Test(org.junit.Test)

Example 12 with ExtensionConfig

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

the class PerMessageDeflateExtensionTest method testOutgoingPing.

/**
     * Outgoing PING (Control Frame) should pass through extension unmodified
     * @throws IOException on test failure
     */
@Test
public void testOutgoingPing() throws IOException {
    PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
    ext.setBufferPool(bufferPool);
    ext.setPolicy(WebSocketPolicy.newServerPolicy());
    ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
    ext.setConfig(config);
    // Setup capture of outgoing frames
    OutgoingFramesCapture capture = new OutgoingFramesCapture();
    // Wire up stack
    ext.setNextOutgoingFrames(capture);
    String payload = "Are you there?";
    Frame ping = new PingFrame().setPayload(payload);
    ext.outgoingFrame(ping, null, BatchMode.OFF);
    capture.assertFrameCount(1);
    capture.assertHasFrame(OpCode.PING, 1);
    WebSocketFrame actual = capture.getFrames().getFirst();
    Assert.assertThat("Frame.opcode", actual.getOpCode(), is(OpCode.PING));
    Assert.assertThat("Frame.fin", actual.isFin(), is(true));
    Assert.assertThat("Frame.rsv1", actual.isRsv1(), is(false));
    Assert.assertThat("Frame.rsv2", actual.isRsv2(), is(false));
    Assert.assertThat("Frame.rsv3", actual.isRsv3(), is(false));
    ByteBuffer expected = BufferUtil.toBuffer(payload, StandardCharsets.UTF_8);
    Assert.assertThat("Frame.payloadLength", actual.getPayloadLength(), is(expected.remaining()));
    ByteBufferAssert.assertEquals("Frame.payload", expected, actual.getPayload().slice());
}
Also used : WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) Frame(org.eclipse.jetty.websocket.api.extensions.Frame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) ExtensionConfig(org.eclipse.jetty.websocket.api.extensions.ExtensionConfig) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) OutgoingFramesCapture(org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture) AbstractExtensionTest(org.eclipse.jetty.websocket.common.extensions.AbstractExtensionTest) Test(org.junit.Test)

Example 13 with ExtensionConfig

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

the class PerMessageDeflateExtensionTest method testIncomingPing.

/**
     * Incoming PING (Control Frame) should pass through extension unmodified
     */
@Test
public void testIncomingPing() {
    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);
    String payload = "Are you there?";
    Frame ping = new PingFrame().setPayload(payload);
    ext.incomingFrame(ping);
    capture.assertFrameCount(1);
    capture.assertHasFrame(OpCode.PING, 1);
    WebSocketFrame actual = capture.getFrames().poll();
    Assert.assertThat("Frame.opcode", actual.getOpCode(), is(OpCode.PING));
    Assert.assertThat("Frame.fin", actual.isFin(), is(true));
    Assert.assertThat("Frame.rsv1", actual.isRsv1(), is(false));
    Assert.assertThat("Frame.rsv2", actual.isRsv2(), is(false));
    Assert.assertThat("Frame.rsv3", actual.isRsv3(), is(false));
    ByteBuffer expected = BufferUtil.toBuffer(payload, StandardCharsets.UTF_8);
    Assert.assertThat("Frame.payloadLength", actual.getPayloadLength(), is(expected.remaining()));
    ByteBufferAssert.assertEquals("Frame.payload", expected, actual.getPayload().slice());
}
Also used : WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) Frame(org.eclipse.jetty.websocket.api.extensions.Frame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) ExtensionConfig(org.eclipse.jetty.websocket.api.extensions.ExtensionConfig) 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)

Example 14 with ExtensionConfig

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

the class ExtensionStackTest method testStartIdentity.

@Test
public void testStartIdentity() throws Exception {
    ExtensionStack stack = createExtensionStack();
    try {
        // 1 extension
        List<ExtensionConfig> configs = new ArrayList<>();
        configs.add(ExtensionConfig.parse("identity"));
        stack.negotiate(configs);
        // Setup Listeners
        DummyIncomingFrames session = new DummyIncomingFrames("Session");
        DummyOutgoingFrames connection = new DummyOutgoingFrames("Connection");
        stack.setNextOutgoing(connection);
        stack.setNextIncoming(session);
        // Start
        stack.start();
        // Dump
        LOG.debug("{}", stack.dump());
        // Should be no change to handlers
        Extension actualIncomingExtension = assertIsExtension("Incoming", stack.getNextIncoming(), IdentityExtension.class);
        Extension actualOutgoingExtension = assertIsExtension("Outgoing", stack.getNextOutgoing(), IdentityExtension.class);
        Assert.assertEquals(actualIncomingExtension, actualOutgoingExtension);
    } finally {
        stack.stop();
    }
}
Also used : Extension(org.eclipse.jetty.websocket.api.extensions.Extension) IdentityExtension(org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension) ExtensionConfig(org.eclipse.jetty.websocket.api.extensions.ExtensionConfig) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 15 with ExtensionConfig

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

the class ExtensionStackTest method testStartIdentityTwice.

@Test
public void testStartIdentityTwice() throws Exception {
    ExtensionStack stack = createExtensionStack();
    try {
        // 1 extension
        List<ExtensionConfig> configs = new ArrayList<>();
        configs.add(ExtensionConfig.parse("identity; id=A"));
        configs.add(ExtensionConfig.parse("identity; id=B"));
        stack.negotiate(configs);
        // Setup Listeners
        DummyIncomingFrames session = new DummyIncomingFrames("Session");
        DummyOutgoingFrames connection = new DummyOutgoingFrames("Connection");
        stack.setNextOutgoing(connection);
        stack.setNextIncoming(session);
        // Start
        stack.start();
        // Dump
        LOG.debug("{}", stack.dump());
        // Should be no change to handlers
        IdentityExtension actualIncomingExtension = assertIsExtension("Incoming", stack.getNextIncoming(), IdentityExtension.class);
        IdentityExtension actualOutgoingExtension = assertIsExtension("Outgoing", stack.getNextOutgoing(), IdentityExtension.class);
        Assert.assertThat("Incoming[identity].id", actualIncomingExtension.getParam("id"), is("A"));
        Assert.assertThat("Outgoing[identity].id", actualOutgoingExtension.getParam("id"), is("B"));
    } finally {
        stack.stop();
    }
}
Also used : ExtensionConfig(org.eclipse.jetty.websocket.api.extensions.ExtensionConfig) ArrayList(java.util.ArrayList) IdentityExtension(org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension) 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