@Override
  protected void doMessageReceived(HttpAcceptSession session, Object message) throws Exception {
    // this can happen if there is an error
    if (!(message instanceof WsMessage)) {
      return;
    }

    WsebSession wsebSession = getSession(session);
    WsMessage wsebMessage = (WsMessage) message;
    IoFilterChain filterChain = wsebSession.getTransportSession().getFilterChain();

    switch (wsebMessage.getKind()) {
      case COMMAND:
        for (Command command : ((WsCommandMessage) wsebMessage).getCommands()) {
          if (command == Command.close()) {
            session.setWriteHeader(HEADER_CONTENT_LENGTH, "0");
            session.close(false);
            filterChain.fireMessageReceived(new WsCloseMessage());
            break;
          } else if (command == Command.reconnect()) {
            session.setWriteHeader(HEADER_CONTENT_LENGTH, "0");
            session.close(false);
            break;
          }
          // no-op (0x00) - continue reading commands
        }
        break;
      default:
        filterChain.fireMessageReceived(wsebMessage);
        break;
    }
  }
Exemple #2
0
        @Override
        protected void doMessageReceived(HttpSession readSession, Object message) throws Exception {
          ResourceAddress readAddress = BridgeSession.REMOTE_ADDRESS.get(readSession);
          WsebSession wsebSession = sessionMap.get(readAddress);

          // handle parallel closure of WSE session during streaming read
          if (wsebSession == null) {
            if (logger.isDebugEnabled()) {
              logger.debug(
                  String.format("Could not find WsebSession for read address:\n" + readAddress));
            }
            return;
          }

          WsMessage wsebMessage = (WsMessage) message;
          IoBufferEx messageBytes = wsebMessage.getBytes();
          IoFilterChain filterChain = wsebSession.getTransportSession().getFilterChain();

          switch (wsebMessage.getKind()) {
            case COMMAND:
              for (Command command : ((WsCommandMessage) wsebMessage).getCommands()) {
                if (command == Command.reconnect()) {
                  // received a RECONNECT command
                  wsebSession.detachReader(readSession);
                  // re-attach downstream for read
                  final BridgeConnector bridgeConnector =
                      bridgeServiceFactory.newBridgeConnector(readAddress);
                  bridgeConnector.connect(readAddress, selectReadHandler(readAddress), null);
                  break;
                } else if (command == Command.close()) {
                  // Following should take care of sending CLOSE response and closing reader
                  // (downstream)
                  // Close case was not handled before 3.5.9
                  filterChain.fireMessageReceived(new WsCloseMessage());
                  break;
                }
                // no-op (0x00) - continue reading commands
              }
              break;
            default:
              filterChain.fireMessageReceived(wsebMessage);
              break;
          }
        }