Example usage for org.springframework.web.socket.handler SessionLimitExceededException getStatus

List of usage examples for org.springframework.web.socket.handler SessionLimitExceededException getStatus

Introduction

In this page you can find the example usage for org.springframework.web.socket.handler SessionLimitExceededException getStatus.

Prototype

public CloseStatus getStatus() 

Source Link

Usage

From source file:org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.java

/**
 * Handle an outbound Spring Message to a WebSocket client.
 *///from w ww.  j  a  va 2  s .  c om
@Override
public void handleMessage(Message<?> message) throws MessagingException {
    String sessionId = resolveSessionId(message);
    if (sessionId == null) {
        if (logger.isErrorEnabled()) {
            logger.error("Could not find session id in " + message);
        }
        return;
    }

    WebSocketSessionHolder holder = this.sessions.get(sessionId);
    if (holder == null) {
        if (logger.isDebugEnabled()) {
            // The broker may not have removed the session yet
            logger.debug("No session for " + message);
        }
        return;
    }

    WebSocketSession session = holder.getSession();
    try {
        findProtocolHandler(session).handleMessageToClient(session, message);
    } catch (SessionLimitExceededException ex) {
        try {
            if (logger.isDebugEnabled()) {
                logger.debug("Terminating '" + session + "'", ex);
            }
            this.stats.incrementLimitExceededCount();
            clearSession(session, ex.getStatus()); // clear first, session may be unresponsive
            session.close(ex.getStatus());
        } catch (Exception secondException) {
            logger.debug("Failure while closing session " + sessionId + ".", secondException);
        }
    } catch (Exception ex) {
        // Could be part of normal workflow (e.g. browser tab closed)
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to send message to client in " + session + ": " + message, ex);
        }
    }
}