use of org.eclipse.jetty.websocket.api.extensions.IncomingFrames 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.IncomingFrames in project jetty.project by eclipse.
the class ExtensionStack method getLastIncoming.
private IncomingFrames getLastIncoming() {
IncomingFrames last = nextIncoming;
boolean done = false;
while (!done) {
if (last instanceof AbstractExtension) {
last = ((AbstractExtension) last).getNextIncoming();
} else {
done = true;
}
}
return last;
}
use of org.eclipse.jetty.websocket.api.extensions.IncomingFrames 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