Example usage for org.springframework.web.socket.sockjs.frame SockJsFrame getFrameData

List of usage examples for org.springframework.web.socket.sockjs.frame SockJsFrame getFrameData

Introduction

In this page you can find the example usage for org.springframework.web.socket.sockjs.frame SockJsFrame getFrameData.

Prototype

@Nullable
public String getFrameData() 

Source Link

Document

Return data contained in a SockJS "message" and "close" frames.

Usage

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);
        }//  w  ww .  j a  v a2 s .co  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);
            }
        }
    }
}

From source file:org.springframework.web.socket.sockjs.client.AbstractClientSockJsSession.java

private void handleCloseFrame(SockJsFrame frame) {
    CloseStatus closeStatus = CloseStatus.NO_STATUS_CODE;
    try {/* ww w .  java  2s .c om*/
        String frameData = frame.getFrameData();
        if (frameData != null) {
            String[] data = getMessageCodec().decode(frameData);
            if (data != null && data.length == 2) {
                closeStatus = new CloseStatus(Integer.valueOf(data[0]), data[1]);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Processing SockJS close frame with " + closeStatus + " in " + this);
            }
        }
    } catch (IOException ex) {
        if (logger.isErrorEnabled()) {
            logger.error("Failed to decode data for " + frame + " in " + this, ex);
        }
    }
    silentClose(closeStatus);
}