Search in sources :

Example 16 with CloseReason

use of javax.websocket.CloseReason in project AngularBeans by bessemHmidi.

the class WebsocketReceiver method didClose.

@Override
protected void didClose() {
    super.didClose();
    try {
        ws.close(new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, "Normal closure"));
    } catch (IOException x) {
        log.log(Level.FINE, "Error closing receiver", x);
    }
    ws = null;
}
Also used : CloseReason(javax.websocket.CloseReason) IOException(java.io.IOException)

Example 17 with CloseReason

use of javax.websocket.CloseReason in project AngularBeans by bessemHmidi.

the class RawWebsocketSessionReceiver method didClose.

public void didClose() {
    if (ws == null) {
        return;
    }
    try {
        ws.close(new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, "Normal closure"));
    } catch (IOException x) {
        log.log(Level.FINE, "Error closing receiver", x);
    }
    ws = null;
    readyState = CLOSED;
    connection.emitClose();
    connection = null;
}
Also used : CloseReason(javax.websocket.CloseReason) IOException(java.io.IOException)

Example 18 with CloseReason

use of javax.websocket.CloseReason in project tomcat by apache.

the class WsSession method checkExpiration.

protected void checkExpiration() {
    long timeout = maxIdleTimeout;
    if (timeout < 1) {
        return;
    }
    if (System.currentTimeMillis() - lastActive > timeout) {
        String msg = sm.getString("wsSession.timeout", getId());
        if (log.isDebugEnabled()) {
            log.debug(msg);
        }
        doClose(new CloseReason(CloseCodes.GOING_AWAY, msg), new CloseReason(CloseCodes.CLOSED_ABNORMALLY, msg));
    }
}
Also used : CloseReason(javax.websocket.CloseReason)

Example 19 with CloseReason

use of javax.websocket.CloseReason in project tomcat by apache.

the class WsWebSocketContainer method destroy.

/**
     * Cleans up the resources still in use by WebSocket sessions created from
     * this container. This includes closing sessions and cancelling
     * {@link Future}s associated with blocking read/writes.
     */
public void destroy() {
    CloseReason cr = new CloseReason(CloseCodes.GOING_AWAY, sm.getString("wsWebSocketContainer.shutdown"));
    for (WsSession session : sessions.keySet()) {
        try {
            session.close(cr);
        } catch (IOException ioe) {
            log.debug(sm.getString("wsWebSocketContainer.sessionCloseFail", session.getId()), ioe);
        }
    }
    // registered with it
    if (asynchronousChannelGroup != null) {
        synchronized (asynchronousChannelGroupLock) {
            if (asynchronousChannelGroup != null) {
                AsyncChannelGroupUtil.unregister();
                asynchronousChannelGroup = null;
            }
        }
    }
}
Also used : CloseReason(javax.websocket.CloseReason) IOException(java.io.IOException)

Example 20 with CloseReason

use of javax.websocket.CloseReason in project tomcat by apache.

the class WsFrameBase method processRemainingHeader.

/**
     * @return <code>true</code> if sufficient data was present to complete the
     *         processing of the header
     */
private boolean processRemainingHeader() throws IOException {
    // Ignore the 2 bytes already read. 4 for the mask
    int headerLength;
    if (isMasked()) {
        headerLength = 4;
    } else {
        headerLength = 0;
    }
    // Add additional bytes depending on length
    if (payloadLength == 126) {
        headerLength += 2;
    } else if (payloadLength == 127) {
        headerLength += 8;
    }
    if (inputBuffer.remaining() < headerLength) {
        return false;
    }
    // Calculate new payload length if necessary
    if (payloadLength == 126) {
        payloadLength = byteArrayToLong(inputBuffer.array(), inputBuffer.arrayOffset() + inputBuffer.position(), 2);
        inputBuffer.position(inputBuffer.position() + 2);
    } else if (payloadLength == 127) {
        payloadLength = byteArrayToLong(inputBuffer.array(), inputBuffer.arrayOffset() + inputBuffer.position(), 8);
        inputBuffer.position(inputBuffer.position() + 8);
    }
    if (Util.isControl(opCode)) {
        if (payloadLength > 125) {
            throw new WsIOException(new CloseReason(CloseCodes.PROTOCOL_ERROR, sm.getString("wsFrame.controlPayloadTooBig", Long.valueOf(payloadLength))));
        }
        if (!fin) {
            throw new WsIOException(new CloseReason(CloseCodes.PROTOCOL_ERROR, sm.getString("wsFrame.controlNoFin")));
        }
    }
    if (isMasked()) {
        inputBuffer.get(mask, 0, 4);
    }
    state = State.DATA;
    return true;
}
Also used : CloseReason(javax.websocket.CloseReason)

Aggregations

CloseReason (javax.websocket.CloseReason)29 IOException (java.io.IOException)16 Session (javax.websocket.Session)8 URI (java.net.URI)7 Test (org.junit.Test)6 ByteBuffer (java.nio.ByteBuffer)5 Endpoint (javax.websocket.Endpoint)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 EndpointConfig (javax.websocket.EndpointConfig)4 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)3 UndertowSession (io.undertow.websockets.jsr.UndertowSession)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 CloseWebSocketFrame (io.netty.handler.codec.http.websocketx.CloseWebSocketFrame)2 AnnotatedClientEndpoint (io.undertow.websockets.jsr.test.annotated.AnnotatedClientEndpoint)2 FrameChecker (io.undertow.websockets.utils.FrameChecker)2 WebSocketTestClient (io.undertow.websockets.utils.WebSocketTestClient)2 CoderResult (java.nio.charset.CoderResult)2 ArrayList (java.util.ArrayList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2