use of org.eclipse.jetty.websocket.api.extensions.Extension in project jetty.project by eclipse.
the class ExtensionStack method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
// Wire up Extensions
if ((extensions != null) && (extensions.size() > 0)) {
ListIterator<Extension> exts = extensions.listIterator();
// Connect outgoings
while (exts.hasNext()) {
Extension ext = exts.next();
ext.setNextOutgoingFrames(nextOutgoing);
nextOutgoing = ext;
if (ext instanceof LifeCycle) {
addBean(ext, true);
}
}
// Connect incomings
while (exts.hasPrevious()) {
Extension ext = exts.previous();
ext.setNextIncomingFrames(nextIncoming);
nextIncoming = ext;
}
}
}
use of org.eclipse.jetty.websocket.api.extensions.Extension 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());
}
use of org.eclipse.jetty.websocket.api.extensions.Extension 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();
}
}
Aggregations