use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class ParserTest method testParseCase5_19.
/**
* Similar to the server side 5.19 testcase. text message, send in 5 frames/fragments, with 2 pings in the mix.
*/
@Test
public void testParseCase5_19() {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload("f1").setFin(false));
send.add(new ContinuationFrame().setPayload(",f2").setFin(false));
send.add(new PingFrame().setPayload("pong-1"));
send.add(new ContinuationFrame().setPayload(",f3").setFin(false));
send.add(new ContinuationFrame().setPayload(",f4").setFin(false));
send.add(new PingFrame().setPayload("pong-2"));
send.add(new ContinuationFrame().setPayload(",f5").setFin(true));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
ByteBuffer completeBuf = UnitGenerator.generate(send);
UnitParser parser = new UnitParser();
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parseQuietly(completeBuf);
capture.assertErrorCount(0);
capture.assertHasFrame(OpCode.TEXT, 1);
capture.assertHasFrame(OpCode.CONTINUATION, 4);
capture.assertHasFrame(OpCode.CLOSE, 1);
capture.assertHasFrame(OpCode.PING, 2);
}
use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class RFC6455ExamplesGeneratorTest method testFragmentedUnmaskedTextMessage.
@Test
public void testFragmentedUnmaskedTextMessage() {
WebSocketFrame text1 = new TextFrame().setPayload("Hel").setFin(false);
WebSocketFrame text2 = new ContinuationFrame().setPayload("lo");
ByteBuffer actual1 = UnitGenerator.generate(text1);
ByteBuffer actual2 = UnitGenerator.generate(text2);
ByteBuffer expected1 = ByteBuffer.allocate(5);
expected1.put(new byte[] { (byte) 0x01, (byte) 0x03, (byte) 0x48, (byte) 0x65, (byte) 0x6c });
ByteBuffer expected2 = ByteBuffer.allocate(4);
expected2.put(new byte[] { (byte) 0x80, (byte) 0x02, (byte) 0x6c, (byte) 0x6f });
expected1.flip();
expected2.flip();
ByteBufferAssert.assertEquals("t1 buffers are not equal", expected1, actual1);
ByteBufferAssert.assertEquals("t2 buffers are not equal", expected2, actual2);
}
use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class WebSocketServletRFCTest method testBinaryAggregate.
/**
* Test that aggregation of binary frames into a single message occurs
* @throws Exception on test failure
*/
@Test
public void testBinaryAggregate() throws Exception {
BlockheadClient client = new BlockheadClient(server.getServerUri());
try {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
// Generate binary frames
byte[] buf1 = new byte[128];
byte[] buf2 = new byte[128];
byte[] buf3 = new byte[128];
Arrays.fill(buf1, (byte) 0xAA);
Arrays.fill(buf2, (byte) 0xBB);
Arrays.fill(buf3, (byte) 0xCC);
WebSocketFrame bin;
bin = new BinaryFrame().setPayload(buf1).setFin(false);
// write buf1 (fin=false)
client.write(bin);
bin = new ContinuationFrame().setPayload(buf2).setFin(false);
// write buf2 (fin=false)
client.write(bin);
bin = new ContinuationFrame().setPayload(buf3).setFin(true);
// write buf3 (fin=true)
client.write(bin);
// Read frame echo'd back (hopefully a single binary frame)
EventQueue<WebSocketFrame> frames = client.readFrames(1, 30, TimeUnit.SECONDS);
Frame binmsg = frames.poll();
int expectedSize = buf1.length + buf2.length + buf3.length;
Assert.assertThat("BinaryFrame.payloadLength", binmsg.getPayloadLength(), is(expectedSize));
int aaCount = 0;
int bbCount = 0;
int ccCount = 0;
ByteBuffer echod = binmsg.getPayload();
while (echod.remaining() >= 1) {
byte b = echod.get();
switch(b) {
case (byte) 0xAA:
aaCount++;
break;
case (byte) 0xBB:
bbCount++;
break;
case (byte) 0xCC:
ccCount++;
break;
default:
Assert.fail(String.format("Encountered invalid byte 0x%02X", (byte) (0xFF & b)));
}
}
Assert.assertThat("Echoed data count for 0xAA", aaCount, is(buf1.length));
Assert.assertThat("Echoed data count for 0xBB", bbCount, is(buf2.length));
Assert.assertThat("Echoed data count for 0xCC", ccCount, is(buf3.length));
} finally {
client.close();
}
}
use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class TestABCase5 method testCase5_10.
/**
* Send continuation+fin, then text+fin (framewise)
* @throws Exception on test failure
*/
@Test
public void testCase5_10() throws Exception {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new ContinuationFrame().setPayload("sorry").setFin(true));
send.add(new TextFrame().setPayload("hello, world"));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this);
StacklessLogging supress = new StacklessLogging(Parser.class)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME);
fuzzer.sendAndIgnoreBrokenPipe(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class TestABCase5 method testCase5_15.
/**
* Send text fragmented properly in 2 frames, then continuation!fin, then text unfragmented.
* @throws Exception on test failure
*/
@Test
public void testCase5_15() throws Exception {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload("fragment1").setFin(false));
send.add(new ContinuationFrame().setPayload("fragment2").setFin(true));
// bad frame
send.add(new ContinuationFrame().setPayload("fragment3").setFin(false));
send.add(new TextFrame().setPayload("fragment4").setFin(true));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new TextFrame().setPayload("fragment1fragment2"));
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this);
StacklessLogging supress = new StacklessLogging(Parser.class)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
Aggregations