use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class TestABCase5 method testCase5_9.
/**
* Send continuation+fin, then text+fin
* @throws Exception on test failure
*/
@Test
public void testCase5_9() 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.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class TestABCase6 method testCase6_2_2.
/**
* valid utf8 text message, 2 fragments (on UTF8 code point boundary)
* @throws Exception on test failure
*/
@Test
public void testCase6_2_2() throws Exception {
String utf1 = "Hello-습@쎟쎤";
String utf2 = "쎼쎠쎡-UTF-8!!";
ByteBuffer b1 = ByteBuffer.wrap(StringUtil.getUtf8Bytes(utf1));
ByteBuffer b2 = ByteBuffer.wrap(StringUtil.getUtf8Bytes(utf2));
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(b1).setFin(false));
send.add(new ContinuationFrame().setPayload(b2).setFin(true));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
ByteBuffer e1 = ByteBuffer.allocate(100);
e1.put(StringUtil.getUtf8Bytes(utf1));
e1.put(StringUtil.getUtf8Bytes(utf2));
e1.flip();
expect.add(new TextFrame().setPayload(e1));
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 WebSocketFrame method copy.
public static WebSocketFrame copy(Frame original) {
WebSocketFrame copy;
switch(original.getOpCode()) {
case OpCode.BINARY:
copy = new BinaryFrame();
break;
case OpCode.TEXT:
copy = new TextFrame();
break;
case OpCode.CLOSE:
copy = new CloseFrame();
break;
case OpCode.CONTINUATION:
copy = new ContinuationFrame();
break;
case OpCode.PING:
copy = new PingFrame();
break;
case OpCode.PONG:
copy = new PongFrame();
break;
default:
throw new IllegalArgumentException("Cannot copy frame with opcode " + original.getOpCode() + " - " + original);
}
copy.copyHeaders(original);
ByteBuffer payload = original.getPayload();
if (payload != null) {
ByteBuffer payloadCopy = ByteBuffer.allocate(payload.remaining());
payloadCopy.put(payload.slice()).flip();
copy.setPayload(payloadCopy);
}
return copy;
}
use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class WebSocketRemoteEndpoint method sendPartialBytes.
@Override
public void sendPartialBytes(ByteBuffer fragment, boolean isLast) throws IOException {
boolean first = lockMsg(MsgType.PARTIAL_BINARY);
try {
if (LOG.isDebugEnabled()) {
LOG.debug("sendPartialBytes({}, {})", BufferUtil.toDetailString(fragment), isLast);
}
DataFrame frame = first ? new BinaryFrame() : new ContinuationFrame();
frame.setPayload(fragment);
frame.setFin(isLast);
blockingWrite(frame);
} finally {
if (isLast)
unlockMsg(MsgType.PARTIAL_BINARY);
}
}
Aggregations