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

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

Introduction

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

Prototype

CloseStatus BAD_DATA

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

Click Source Link

Document

"1007 indicates that an endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 [RFC3629] data within a text message)."

Usage

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  w  ww.jav  a2  s.  c  o m
    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:org.springframework.web.socket.sockjs.client.AbstractClientSockJsSession.java

private void handleMessageFrame(SockJsFrame frame) {
    if (!isOpen()) {
        if (logger.isErrorEnabled()) {
            logger.error("Ignoring received message due to state " + this.state + " in " + this);
        }//from  w w  w  . ja  va2s.c  o  m
        return;
    }

    String[] messages = null;
    String frameData = frame.getFrameData();
    if (frameData != null) {
        try {
            messages = getMessageCodec().decode(frameData);
        } catch (IOException ex) {
            if (logger.isErrorEnabled()) {
                logger.error("Failed to decode data for SockJS \"message\" frame: " + frame + " in " + this,
                        ex);
            }
            silentClose(CloseStatus.BAD_DATA);
            return;
        }
    }
    if (messages == null) {
        return;
    }

    if (logger.isTraceEnabled()) {
        logger.trace("Processing SockJS message frame " + frame.getContent() + " in " + this);
    }
    for (String message : messages) {
        if (isOpen()) {
            try {
                this.webSocketHandler.handleMessage(this, new TextMessage(message));
            } catch (Throwable ex) {
                logger.error("WebSocketHandler.handleMessage threw an exception on " + frame + " in " + this,
                        ex);
            }
        }
    }
}