Search in sources :

Example 71 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class BlockheadClient method close.

/* (non-Javadoc)
     * @see org.eclipse.jetty.websocket.common.test.IBlockheadClient#close(int, java.lang.String)
     */
@Override
public void close(int statusCode, String message) {
    LOG.debug("close({},{})", statusCode, message);
    CloseInfo close = new CloseInfo(statusCode, message);
    if (!ioState.isClosed()) {
        ioState.onCloseLocal(close);
    } else {
        LOG.debug("Not issuing close. ioState = {}", ioState);
    }
}
Also used : CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo)

Example 72 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class LocalWebSocketConnection method close.

@Override
public void close(int statusCode, String reason) {
    if (LOG.isDebugEnabled())
        LOG.debug("close({}, {})", statusCode, reason);
    CloseInfo close = new CloseInfo(statusCode, reason);
    ioState.onCloseLocal(close);
}
Also used : CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo)

Example 73 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class LocalWebSocketConnection method onConnectionStateChange.

@Override
public void onConnectionStateChange(ConnectionState state) {
    if (LOG.isDebugEnabled())
        LOG.debug("Connection State Change: {}", state);
    switch(state) {
        case CLOSED:
            this.disconnect();
            break;
        case CLOSING:
            if (ioState.wasRemoteCloseInitiated()) {
                // send response close frame
                CloseInfo close = ioState.getCloseInfo();
                LOG.debug("write close frame: {}", close);
                ioState.onCloseLocal(close);
            }
        default:
            break;
    }
}
Also used : CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo)

Example 74 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class IOStateTest method testConnectAbnormalClose.

@Test
public void testConnectAbnormalClose() {
    IOState state = new IOState();
    StateTracker tracker = new StateTracker();
    state.addListener(tracker);
    assertState(state, ConnectionState.CONNECTING);
    // connect
    state.onConnected();
    assertInputAvailable(state, false);
    assertOutputAvailable(state, true);
    // open
    state.onOpened();
    assertInputAvailable(state, true);
    assertOutputAvailable(state, true);
    // disconnect
    state.onAbnormalClose(new CloseInfo(StatusCode.NO_CLOSE, "Oops"));
    assertInputAvailable(state, false);
    assertOutputAvailable(state, false);
    tracker.assertTransitions(ConnectionState.CONNECTED, ConnectionState.OPEN, ConnectionState.CLOSED);
    assertState(state, ConnectionState.CLOSED);
    // not clean
    assertCleanClose(state, false);
    assertLocalInitiated(state, false);
    assertRemoteInitiated(state, false);
}
Also used : CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 75 with CloseInfo

use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.

the class EventDriverTest method testAnnotated_ByteArray.

@Test
public void testAnnotated_ByteArray() throws Exception {
    AnnotatedBinaryArraySocket socket = new AnnotatedBinaryArraySocket();
    EventDriver driver = wrap(socket);
    try (LocalWebSocketSession conn = new CloseableLocalWebSocketSession(container, testname, driver)) {
        conn.open();
        driver.incomingFrame(makeBinaryFrame("Hello World", true));
        driver.incomingFrame(new CloseInfo(StatusCode.NORMAL).asFrame());
        socket.capture.assertEventCount(3);
        socket.capture.pop().assertEventStartsWith("onConnect");
        socket.capture.pop().assertEvent("onBinary([11],0,11)");
        socket.capture.pop().assertEventStartsWith("onClose(1000,");
    }
}
Also used : LocalWebSocketSession(org.eclipse.jetty.websocket.common.io.LocalWebSocketSession) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) AnnotatedBinaryArraySocket(examples.AnnotatedBinaryArraySocket) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Aggregations

CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)151 Test (org.junit.Test)129 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)118 ArrayList (java.util.ArrayList)104 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)104 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)68 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)55 ByteBuffer (java.nio.ByteBuffer)48 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)30 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)27 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)19 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)17 BlockheadClient (org.eclipse.jetty.websocket.common.test.BlockheadClient)14 IBlockheadClient (org.eclipse.jetty.websocket.common.test.IBlockheadClient)10 CloseableLocalWebSocketSession (org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession)8 LocalWebSocketSession (org.eclipse.jetty.websocket.common.io.LocalWebSocketSession)8 Stress (org.eclipse.jetty.toolchain.test.annotation.Stress)6 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)5 CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4