Search in sources :

Example 16 with CloseFrame

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();
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 17 with CloseFrame

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();
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) Test(org.junit.Test)

Example 18 with CloseFrame

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();
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 19 with CloseFrame

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;
}
Also used : PongFrame(org.eclipse.jetty.websocket.common.frames.PongFrame) BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) ByteBuffer(java.nio.ByteBuffer)

Example 20 with CloseFrame

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();
}
Also used : CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame)

Aggregations

CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)20 Test (org.junit.Test)15 ByteBuffer (java.nio.ByteBuffer)10 ArrayList (java.util.ArrayList)6 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)6 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)6 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)4 ProtocolException (org.eclipse.jetty.websocket.api.ProtocolException)3 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)2 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)2 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)2 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)2 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)2 NotUtf8Exception (org.eclipse.jetty.util.Utf8Appendable.NotUtf8Exception)1 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)1 CloseException (org.eclipse.jetty.websocket.api.CloseException)1