use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class TestABCase6 method fragmentText.
/**
* Split a message byte array into a series of fragments (frames + continuations) of 1 byte message contents each.
* @param frames the frames
* @param msg the message
*/
protected void fragmentText(List<WebSocketFrame> frames, byte[] msg) {
int len = msg.length;
boolean continuation = false;
byte[] mini;
for (int i = 0; i < len; i++) {
DataFrame frame = null;
if (continuation) {
frame = new ContinuationFrame();
} else {
frame = new TextFrame();
}
mini = new byte[1];
mini[0] = msg[i];
frame.setPayload(ByteBuffer.wrap(mini));
boolean isLast = (i >= (len - 1));
frame.setFin(isLast);
frames.add(frame);
continuation = true;
}
}
use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class TestABCase6 method testCase6_4_1.
/**
* invalid text message, 3 fragments.
* <p>
* fragment #1 and fragment #3 are both valid in themselves.
* <p>
* fragment #2 contains the invalid utf8 code point.
* @throws Exception on test failure
*/
@Test
@Slow
public void testCase6_4_1() throws Exception {
byte[] part1 = StringUtil.getUtf8Bytes("κόσμε");
// invalid
byte[] part2 = Hex.asByteArray("F4908080");
byte[] part3 = StringUtil.getUtf8Bytes("edited");
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false));
TimeUnit.SECONDS.sleep(1);
fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part2)).setFin(false));
TimeUnit.SECONDS.sleep(1);
fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part3)).setFin(true));
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class TestABCase6 method testCase6_1_2.
/**
* text message, 0 length, 3 fragments
* @throws Exception on test failure
*/
@Test
public void testCase6_1_2() throws Exception {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setFin(false));
send.add(new ContinuationFrame().setFin(false));
send.add(new ContinuationFrame().setFin(true));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new TextFrame());
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class TestABCase7 method testCase7_1_5.
/**
* Text fin=false, close, then continuation fin=true
* @throws Exception on test failure
*/
@Test
public void testCase7_1_5() throws Exception {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload("an").setFin(false));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
send.add(new ContinuationFrame().setPayload("ticipation").setFin(true));
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
}
}
use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class TestABCase5 method testCase5_5.
/**
* Send text fragmented in 2 packets (slowly)
* @throws Exception on test failure
*/
@Test
public void testCase5_5() throws Exception {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload("hello, ").setFin(false));
send.add(new ContinuationFrame().setPayload("world").setFin(true));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new TextFrame().setPayload("hello, world"));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this);
StacklessLogging supress = new StacklessLogging(Parser.class)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.SLOW);
fuzzer.setSlowSendSegmentSize(1);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
Aggregations