protected void handleTextMessage()

in java/ws-server/src/main/java/com/epam/deltix/tbwg/webapp/websockets/WSHandler.java [413:454]


    protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
        if (message != null && message.getPayloadLength() != 0) {
            try {
                WSMessage wsMessage = gson.fromJson(message.getPayload(), WSMessage.class);
                if (wsMessage.messageType == MessageType.SUBSCRIBE) {
                    SubscribeMessage subscribeMessage = (SubscribeMessage) wsMessage;
                    PumpTask task = map.get(session.getId(), null);
                    if (task == null) {
                        LOGGER.error("Task for session %s is null.").with(session.getId());
                        return;
                    }
                    final TickCursor cursor = task.cursor;
                    if (cursor == null) {
                        LOGGER.error("Cursor for session %s is null.").with(session.getId());
                        return;
                    }
                    changeSubscription(subscribeMessage, cursor, task);
                } else if (wsMessage.messageType == MessageType.SET_SUBSCRIPTION) {
                    SetSubscriptionMessage setSubscriptionMessage = (SetSubscriptionMessage) wsMessage;
                    PumpTask task = map.get(session.getId(), null);
                    if (task == null) {
                        LOGGER.error("Task for session %s is null.").with(session.getId());
                        return;
                    }
                    final TickCursor cursor = task.cursor;
                    if (cursor == null) {
                        LOGGER.error("Cursor for session %s is null.").with(session.getId());
                        return;
                    }
                    changeSubscription(setSubscriptionMessage, cursor, task);
                }
            } catch (JsonParseException | IllegalStateException exc) {
                LOGGER.error().append("unknown message format: ")
                        .append(message.getPayload())
                        .append('\n')
                        .append(exc)
                        .commit();
            }
            return;
        }
        super.handleTextMessage(session, message);
    }