Search in sources :

Example 1 with IdentityExtension

use of org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension in project jetty.project by eclipse.

the class IdentityExtensionTest method testOutgoingFrames.

/**
     * Verify that outgoing frames are unmodified
     * @throws IOException on test failure
     */
@Test
public void testOutgoingFrames() throws IOException {
    OutgoingFramesCapture capture = new OutgoingFramesCapture();
    Extension ext = new IdentityExtension();
    ext.setNextOutgoingFrames(capture);
    Frame frame = new TextFrame().setPayload("hello");
    ext.outgoingFrame(frame, null, BatchMode.OFF);
    capture.assertFrameCount(1);
    capture.assertHasFrame(OpCode.TEXT, 1);
    WebSocketFrame actual = capture.getFrames().getFirst();
    Assert.assertThat("Frame.opcode", actual.getOpCode(), is(OpCode.TEXT));
    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("hello", StandardCharsets.UTF_8);
    Assert.assertThat("Frame.payloadLength", actual.getPayloadLength(), is(expected.remaining()));
    ByteBufferAssert.assertEquals("Frame.payload", expected, actual.getPayload().slice());
}
Also used : Extension(org.eclipse.jetty.websocket.api.extensions.Extension) IdentityExtension(org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension) Frame(org.eclipse.jetty.websocket.api.extensions.Frame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) IdentityExtension(org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) OutgoingFramesCapture(org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture) Test(org.junit.Test)

Example 2 with IdentityExtension

use of org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension in project jetty.project by eclipse.

the class IdentityExtensionTest method testIncomingFrames.

/**
     * Verify that incoming frames are unmodified
     */
@Test
public void testIncomingFrames() {
    IncomingFramesCapture capture = new IncomingFramesCapture();
    Extension ext = new IdentityExtension();
    ext.setNextIncomingFrames(capture);
    Frame frame = new TextFrame().setPayload("hello");
    ext.incomingFrame(frame);
    capture.assertFrameCount(1);
    capture.assertHasFrame(OpCode.TEXT, 1);
    WebSocketFrame actual = capture.getFrames().poll();
    Assert.assertThat("Frame.opcode", actual.getOpCode(), is(OpCode.TEXT));
    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("hello", StandardCharsets.UTF_8);
    Assert.assertThat("Frame.payloadLength", actual.getPayloadLength(), is(expected.remaining()));
    ByteBufferAssert.assertEquals("Frame.payload", expected, actual.getPayload().slice());
}
Also used : Extension(org.eclipse.jetty.websocket.api.extensions.Extension) IdentityExtension(org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension) Frame(org.eclipse.jetty.websocket.api.extensions.Frame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) IdentityExtension(org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with IdentityExtension

use of org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension 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

IdentityExtension (org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension)3 Test (org.junit.Test)3 ByteBuffer (java.nio.ByteBuffer)2 Extension (org.eclipse.jetty.websocket.api.extensions.Extension)2 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)2 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)2 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)2 ArrayList (java.util.ArrayList)1 ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)1 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)1 OutgoingFramesCapture (org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture)1