use of org.eclipse.jetty.websocket.common.frames.CloseFrame in project jetty.project by eclipse.
the class TestABCase7_GoodStatusCodes method testStatusCodeWithReason.
/**
* the good close code, with reason
* @throws Exception on test failure
*/
@Test
public void testStatusCodeWithReason() throws Exception {
ByteBuffer payload = ByteBuffer.allocate(256);
payload.putChar((char) statusCode);
payload.put(StringUtil.getBytes("Reason"));
payload.flip();
List<WebSocketFrame> send = new ArrayList<>();
send.add(new CloseFrame().setPayload(payload.slice()));
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseFrame().setPayload(clone(payload)));
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.CloseFrame in project jetty.project by eclipse.
the class TestABCase7 method testCase7_3_1.
/**
* close with no payload (payload length 0)
* @throws Exception on test failure
*/
@Test
public void testCase7_3_1() throws Exception {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new CloseFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseFrame());
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.CloseFrame in project jetty.project by eclipse.
the class TestABCase7_BadStatusCodes method testBadStatusCodeWithReason.
/**
* the bad close code, with reason
* @throws Exception on test failure
*/
@Test
public void testBadStatusCodeWithReason() throws Exception {
ByteBuffer payload = ByteBuffer.allocate(256);
BufferUtil.clearToFill(payload);
payload.putChar((char) statusCode);
payload.put(StringUtil.getBytes("Reason"));
BufferUtil.flipToFlush(payload, 0);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new CloseFrame().setPayload(payload.slice()));
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).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.CloseFrame 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.CloseFrame in project jetty.project by eclipse.
the class BlockheadServerConnection method close.
/* (non-Javadoc)
* @see org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection#close()
*/
@Override
public void close() throws IOException {
write(new CloseFrame());
flush();
}
Aggregations