use of org.eclipse.jetty.websocket.api.extensions.OutgoingFrames in project jetty.project by eclipse.
the class ExtensionStack method getLastOutgoing.
private OutgoingFrames getLastOutgoing() {
OutgoingFrames last = nextOutgoing;
boolean done = false;
while (!done) {
if (last instanceof AbstractExtension) {
last = ((AbstractExtension) last).getNextOutgoing();
} else {
done = true;
}
}
return last;
}
use of org.eclipse.jetty.websocket.api.extensions.OutgoingFrames in project jetty.project by eclipse.
the class MessageWriterTest method setupSession.
@Before
public void setupSession() throws Exception {
policy = WebSocketPolicy.newServerPolicy();
policy.setInputBufferSize(1024);
policy.setMaxTextMessageBufferSize(1024);
// Container
WebSocketContainerScope containerScope = new SimpleContainerScope(policy, bufferPool);
// Event Driver factory
EventDriverFactory factory = new EventDriverFactory(containerScope);
// local socket
EventDriver driver = factory.wrap(new TrackingSocket("local"));
// remote socket
socket = new TrackingSocket("remote");
OutgoingFrames socketPipe = FramePipes.to(factory.wrap(socket));
session = new LocalWebSocketSession(containerScope, testname, driver);
session.setPolicy(policy);
// talk to our remote socket
session.setOutgoingHandler(socketPipe);
// start session
session.start();
// open connection
session.open();
}
use of org.eclipse.jetty.websocket.api.extensions.OutgoingFrames in project jetty.project by eclipse.
the class DeflateFrameExtensionTest method testCompressAndDecompressBigPayload.
@Test
public void testCompressAndDecompressBigPayload() throws Exception {
byte[] input = new byte[1024 * 1024];
// Make them not compressible.
new Random().nextBytes(input);
int maxMessageSize = (1024 * 1024) + 8192;
DeflateFrameExtension clientExtension = new DeflateFrameExtension();
clientExtension.setBufferPool(bufferPool);
clientExtension.setPolicy(WebSocketPolicy.newClientPolicy());
clientExtension.getPolicy().setMaxBinaryMessageSize(maxMessageSize);
clientExtension.getPolicy().setMaxBinaryMessageBufferSize(maxMessageSize);
clientExtension.setConfig(ExtensionConfig.parse("deflate-frame"));
final DeflateFrameExtension serverExtension = new DeflateFrameExtension();
serverExtension.setBufferPool(bufferPool);
serverExtension.setPolicy(WebSocketPolicy.newServerPolicy());
serverExtension.getPolicy().setMaxBinaryMessageSize(maxMessageSize);
serverExtension.getPolicy().setMaxBinaryMessageBufferSize(maxMessageSize);
serverExtension.setConfig(ExtensionConfig.parse("deflate-frame"));
// Chain the next element to decompress.
clientExtension.setNextOutgoingFrames(new OutgoingFrames() {
@Override
public void outgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode) {
LOG.debug("outgoingFrame({})", frame);
serverExtension.incomingFrame(frame);
callback.writeSuccess();
}
});
final ByteArrayOutputStream result = new ByteArrayOutputStream(input.length);
serverExtension.setNextIncomingFrames(new IncomingFrames() {
@Override
public void incomingFrame(Frame frame) {
LOG.debug("incomingFrame({})", frame);
try {
result.write(BufferUtil.toArray(frame.getPayload()));
} catch (IOException x) {
throw new RuntimeIOException(x);
}
}
@Override
public void incomingError(Throwable t) {
}
});
BinaryFrame frame = new BinaryFrame();
frame.setPayload(input);
frame.setFin(true);
clientExtension.outgoingFrame(frame, null, BatchMode.OFF);
Assert.assertArrayEquals(input, result.toByteArray());
}
use of org.eclipse.jetty.websocket.api.extensions.OutgoingFrames in project jetty.project by eclipse.
the class ExtensionStackProcessingTest method testDeflateFrameExtension.
@Test
public void testDeflateFrameExtension() throws Exception {
assumeDeflateFrameAvailable();
ClientEndpointConfig config = ClientEndpointConfig.Builder.create().extensions(Arrays.<Extension>asList(new JsrExtension("deflate-frame"))).build();
final String content = "deflate_me";
final CountDownLatch messageLatch = new CountDownLatch(1);
URI uri = URI.create("ws://localhost:" + connector.getLocalPort());
Session session = client.connectToServer(new EndpointAdapter() {
@Override
public void onMessage(String message) {
Assert.assertEquals(content, message);
messageLatch.countDown();
}
}, config, uri);
// Make sure everything is wired properly.
OutgoingFrames firstOut = ((JsrSession) session).getOutgoingHandler();
Assert.assertTrue(firstOut instanceof ExtensionStack);
ExtensionStack extensionStack = (ExtensionStack) firstOut;
Assert.assertTrue(extensionStack.isRunning());
OutgoingFrames secondOut = extensionStack.getNextOutgoing();
Assert.assertTrue(secondOut instanceof DeflateFrameExtension);
DeflateFrameExtension deflateExtension = (DeflateFrameExtension) secondOut;
Assert.assertTrue(deflateExtension.isRunning());
OutgoingFrames thirdOut = deflateExtension.getNextOutgoing();
Assert.assertTrue(thirdOut instanceof WebSocketClientConnection);
final CountDownLatch latch = new CountDownLatch(1);
session.getAsyncRemote().sendText(content, new SendHandler() {
@Override
public void onResult(SendResult result) {
latch.countDown();
}
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
Assert.assertTrue(messageLatch.await(5, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.websocket.api.extensions.OutgoingFrames in project jetty.project by eclipse.
the class ExtensionStack method dump.
@Override
public void dump(Appendable out, String indent) throws IOException {
super.dump(out, indent);
IncomingFrames websocket = getLastIncoming();
OutgoingFrames network = getLastOutgoing();
out.append(indent).append(" +- Stack").append(System.lineSeparator());
out.append(indent).append(" +- Network : ").append(network.toString()).append(System.lineSeparator());
for (Extension ext : extensions) {
out.append(indent).append(" +- Extension: ").append(ext.toString()).append(System.lineSeparator());
}
out.append(indent).append(" +- Websocket: ").append(websocket.toString()).append(System.lineSeparator());
}
Aggregations