Example usage for org.springframework.web.socket CloseStatus SERVER_ERROR

List of usage examples for org.springframework.web.socket CloseStatus SERVER_ERROR

Introduction

In this page you can find the example usage for org.springframework.web.socket CloseStatus SERVER_ERROR.

Prototype

CloseStatus SERVER_ERROR

To view the source code for org.springframework.web.socket CloseStatus SERVER_ERROR.

Click Source Link

Document

"1011 indicates that a server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request."

Usage

From source file:com.csavory.websocket.client.StringWebSocketHandler.java

@Override
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
    logger.error("Transport Error", exception);
    session.close(CloseStatus.SERVER_ERROR);
}

From source file:com.omni.fansoffury.TestEchoWebSocketHandler.java

@Override
public void handleTransportError(WebSocketSession session, Throwable e) throws Exception {
    logger.error("Socket threw error", e);
    session.close(CloseStatus.SERVER_ERROR);
}

From source file:com.company.project.config.StompDisconnectEvent.java

@Override
public void onApplicationEvent(SessionDisconnectEvent event) {
    StompHeaderAccessor sha = StompHeaderAccessor.wrap(event.getMessage());
    CloseStatus status = event.getCloseStatus();

    if (status.equals(CloseStatus.BAD_DATA)) {
        System.out.println("CloseStatus.BAD_DATA");
    }/*from  ww w  . j  av  a2 s  . c  om*/
    if (status.equals(CloseStatus.GOING_AWAY)) {
        System.out.println("CloseStatus.GOING_AWAY");
    }
    if (status.equals(CloseStatus.NORMAL)) {
        System.out.println("CloseStatus.NORMAL");
    }
    if (status.equals(CloseStatus.NOT_ACCEPTABLE)) {
        System.out.println("CloseStatus.NOT_ACCEPTABLE");
    }
    if (status.equals(CloseStatus.NO_CLOSE_FRAME)) {
        System.out.println("CloseStatus.NO_CLOSE_FRAME");
    }
    if (status.equals(CloseStatus.NO_STATUS_CODE)) {
        System.out.println("CloseStatus.NO_STATUS_CODE");
    }
    if (status.equals(CloseStatus.POLICY_VIOLATION)) {
        System.out.println("CloseStatus.POLICY_VIOLATION");
    }
    if (status.equals(CloseStatus.PROTOCOL_ERROR)) {
        System.out.println("CloseStatus.PROTOCOL_ERROR");
    }
    if (status.equals(CloseStatus.REQUIRED_EXTENSION)) {
        System.out.println("CloseStatus.REQUIRED_EXTENSION");
    }
    if (status.equals(CloseStatus.SERVER_ERROR)) {
        System.out.println("CloseStatus.SERVER_ERROR");
    }
    if (status.equals(CloseStatus.SERVICE_RESTARTED)) {
        System.out.println("CloseStatus.SERVICE_RESTARTED");
    }
    if (status.equals(CloseStatus.SESSION_NOT_RELIABLE)) {
        System.out.println("CloseStatus.SESSION_NOT_RELIABLE");
    }
    if (status.equals(CloseStatus.TLS_HANDSHAKE_FAILURE)) {
        System.out.println("CloseStatus.TLS_HANDSHAKE_FAILURE");
    }
    if (status.equals(CloseStatus.TOO_BIG_TO_PROCESS)) {
        System.out.println("CloseStatus.TOO_BIG_TO_PROCESS");
    }

    System.out.println("CloseStatus: " + status);

    logger.debug("Disconnect event [sessionId: " + sha.getSessionId() + " ]");
    System.out.println("Disconnect event [sessionId: " + event.getSessionId() + " ]");
}

From source file:ymanv.forex.websocket.RatesWebSocketHandler.java

@Override
public void handleTransportError(WebSocketSession session, Throwable exception) throws IOException {
    session.close(CloseStatus.SERVER_ERROR);
}

From source file:com.kjipo.echo.EchoWebSocketHandler.java

@Override
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
    logger.debug("Closing session: {}", session);
    session.close(CloseStatus.SERVER_ERROR);
    simpleWebSocketMessageSender.removeMessageConsumer(sessionIdMessageConsumerMap.get(session.getId()));
}

From source file:com.jxt.web.websocket.OrderedWebSocketFlushRunnable.java

private void closeSession(WebSocketSession session) {
    try {/* w  w w  . j  a  va 2 s . c  o m*/
        session.close(CloseStatus.SERVER_ERROR);
    } catch (Exception e) {
        LOGGER.warn(e.getMessage(), e);
    }
}

From source file:com.pubkit.platform.messaging.PKMPConnectionHandler.java

@Override
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
    session.close(CloseStatus.SERVER_ERROR);
}

From source file:org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.java

public static void tryCloseWithError(WebSocketSession session, Throwable exception, Log logger) {
    if (logger.isErrorEnabled()) {
        logger.error("Closing session due to exception for " + session, exception);
    }//from w  ww . j  a  v a2 s  .  c  o  m
    if (session.isOpen()) {
        try {
            session.close(CloseStatus.SERVER_ERROR);
        } catch (Throwable ex) {
            // ignore
        }
    }
}

From source file:org.springframework.web.socket.sockjs.AbstractSockJsSession.java

/**
 * For internal use within a TransportHandler and the (TransportHandler-specific)
 * session sub-class./*from   ww w  .ja  v a 2s.c  o  m*/
 */
protected void writeFrame(SockJsFrame frame) throws IOException {
    if (logger.isTraceEnabled()) {
        logger.trace("Preparing to write " + frame);
    }
    try {
        writeFrameInternal(frame);
    } catch (IOException ex) {
        if (ex instanceof EOFException || ex instanceof SocketException) {
            logger.warn("Client went away. Terminating connection");
        } else {
            logger.warn("Terminating connection due to failure to send message: " + ex.getMessage());
        }
        disconnect(CloseStatus.SERVER_ERROR);
        close(CloseStatus.SERVER_ERROR);
        throw ex;
    } catch (Throwable ex) {
        logger.warn("Terminating connection due to failure to send message: " + ex.getMessage());
        disconnect(CloseStatus.SERVER_ERROR);
        close(CloseStatus.SERVER_ERROR);
        throw new TransportErrorException("Failed to write " + frame, ex, this.getId());
    }
}

From source file:org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.java

/**
 * For internal use within a TransportHandler and the (TransportHandler-specific)
 * session class.// w  w w  .ja  v a2  s .c o  m
 */
protected void writeFrame(SockJsFrame frame) throws SockJsTransportFailureException {
    if (logger.isTraceEnabled()) {
        logger.trace("Preparing to write " + frame);
    }
    try {
        writeFrameInternal(frame);
    } catch (Throwable ex) {
        logWriteFrameFailure(ex);
        try {
            // Force disconnect (so we won't try to send close frame)
            disconnect(CloseStatus.SERVER_ERROR);
        } catch (Throwable disconnectFailure) {
            // Ignore
        }
        try {
            close(CloseStatus.SERVER_ERROR);
        } catch (Throwable closeFailure) {
            // Nothing of consequence, already forced disconnect
        }
        throw new SockJsTransportFailureException("Failed to write " + frame, getId(), ex);
    }
}