Search in sources :

Example 1 with CloseCode

use of javax.websocket.CloseReason.CloseCode in project jetty.project by eclipse.

the class AbstractJsrEventDriver method onClose.

@Override
public final void onClose(CloseInfo close) {
    if (hasCloseBeenCalled) {
        // avoid duplicate close events (possible when using harsh Session.disconnect())
        return;
    }
    hasCloseBeenCalled = true;
    CloseCode closecode = CloseCodes.getCloseCode(close.getStatusCode());
    CloseReason closereason = new CloseReason(closecode, close.getReason());
    onClose(closereason);
}
Also used : CloseReason(javax.websocket.CloseReason) CloseCode(javax.websocket.CloseReason.CloseCode)

Example 2 with CloseCode

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

the class TestClose method awaitOnClose.

public static void awaitOnClose(CloseCode... codes) {
    Set<CloseCode> set = new HashSet<>();
    for (CloseCode code : codes) {
        set.add(code);
    }
    awaitOnClose(set);
}
Also used : CloseCode(javax.websocket.CloseReason.CloseCode) HashSet(java.util.HashSet)

Example 3 with CloseCode

use of javax.websocket.CloseReason.CloseCode in project tomcat70 by apache.

the class TestClose method awaitOnClose.

public static void awaitOnClose(CloseCode... codes) {
    Set<CloseCode> set = new HashSet<CloseCode>();
    for (CloseCode code : codes) {
        set.add(code);
    }
    awaitOnClose(set);
}
Also used : CloseCode(javax.websocket.CloseReason.CloseCode) HashSet(java.util.HashSet)

Example 4 with CloseCode

use of javax.websocket.CloseReason.CloseCode in project tomcat70 by apache.

the class WsSession method sendCloseMessage.

private void sendCloseMessage(CloseReason closeReason) {
    // 125 is maximum size for the payload of a control message
    ByteBuffer msg = ByteBuffer.allocate(125);
    CloseCode closeCode = closeReason.getCloseCode();
    // CLOSED_ABNORMALLY should not be put on the wire
    if (closeCode == CloseCodes.CLOSED_ABNORMALLY) {
        // PROTOCOL_ERROR is probably better than GOING_AWAY here
        msg.putShort((short) CloseCodes.PROTOCOL_ERROR.getCode());
    } else {
        msg.putShort((short) closeCode.getCode());
    }
    String reason = closeReason.getReasonPhrase();
    if (reason != null && reason.length() > 0) {
        appendCloseReasonWithTruncation(msg, reason);
    }
    msg.flip();
    try {
        wsRemoteEndpoint.startMessageBlock(Constants.OPCODE_CLOSE, msg, true);
    } catch (IOException ioe) {
        handleCloseException(ioe, closeCode);
    } catch (WritePendingException wpe) {
        handleCloseException(wpe, closeCode);
    } finally {
        webSocketContainer.unregisterSession(localEndpoint, this);
    }
}
Also used : WritePendingException(java.nio.channels.WritePendingException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) CloseCode(javax.websocket.CloseReason.CloseCode)

Example 5 with CloseCode

use of javax.websocket.CloseReason.CloseCode in project tomcat70 by apache.

the class TestClose method awaitOnClose.

public static void awaitOnClose(Set<CloseCode> codes) {
    awaitLatch(events.onCloseCalled, "onClose not called");
    CloseCode received = events.closeReason.getCloseCode();
    Assert.assertTrue("Rx: " + received, codes.contains(received));
}
Also used : CloseCode(javax.websocket.CloseReason.CloseCode)

Aggregations

CloseCode (javax.websocket.CloseReason.CloseCode)5 HashSet (java.util.HashSet)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 WritePendingException (java.nio.channels.WritePendingException)1 CloseReason (javax.websocket.CloseReason)1