Examples of WebSocketState


Examples of org.springframework.integration.x.ip.websocket.WebSocketSerializer.WebSocketState

    }

    public boolean doOnMessage(Message<?> message) {
      Assert.isInstanceOf(WebSocketFrame.class, message.getPayload());
      WebSocketFrame payload = (WebSocketFrame) message.getPayload();
      WebSocketState state = getState(message);
      if (logger.isTraceEnabled()) {
        logger.trace(state);
      }
      if (payload.getRsv() > 0) {
        if (logger.isDebugEnabled()) {
          logger.debug("Reserved bits:" + payload.getRsv());
        }
        this.protocolViolation(message);
      }
      else if (payload.getType() == WebSocketFrame.TYPE_CLOSE) {
        try {
          if (logger.isDebugEnabled()) {
            logger.debug("Close, status:" + payload.getStatus());
          }
          // If we initiated the close, just close.
          if (!state.isCloseInitiated()) {
            if (payload.getStatus() < 0) {
              payload.setStatus((short) 1000);
            }
            this.send(message);
          }
          WebSocketEvent event = new WebSocketEvent(this.getTheConnection(),
              WebSocketEventType.WEBSOCKET_CLOSED, state.getPath(), state.getQueryString());
          this.getTheConnection().publishEvent(event);
          this.close();
        }
        catch (Exception e) {
          throw new MessageHandlingException(message, "Send failed", e);
        }
      }
      else if (state == null || state.isCloseInitiated()) {
        if (logger.isWarnEnabled()) {
          logger.warn("Message dropped - close initiated:" + message);
        }
      }
      else if ((payload.getType() & 0xff) == WebSocketFrame.TYPE_INVALID) {
        if (logger.isDebugEnabled()) {
          logger.debug("Invalid:" + payload.getPayload());
        }
        this.protocolViolation(message);
      }
      else if (payload.getType() == WebSocketFrame.TYPE_FRAGMENTED_CONTROL) {
        if (logger.isDebugEnabled()) {
          logger.debug("Fragmented Control Op");
        }
        this.protocolViolation(message);
      }
      else if (payload.getType() == WebSocketFrame.TYPE_PING) {
        try {
          if (logger.isDebugEnabled()) {
            logger.debug("Ping received on " + this.getConnectionId() + ":"
                + new String(payload.getBinary(), "UTF-8"));
          }
          if (payload.getBinary().length > 125) {
            this.protocolViolation(message);
          }
          else {
            WebSocketFrame pong = new WebSocketFrame(WebSocketFrame.TYPE_PONG, payload.getBinary());
            this.send(MessageBuilder.withPayload(pong)
                .copyHeaders(message.getHeaders())
                .build());
          }
        }
        catch (Exception e) {
          throw new MessageHandlingException(message, "Send failed", e);
        }
      }
      else if (payload.getType() == WebSocketFrame.TYPE_PONG) {
        if (logger.isDebugEnabled()) {
          logger.debug("Pong received on " + this.getConnectionId());
        }
      }
      else if (this.shook) {
        return super.onMessage(message);
      }
      else {
        try {
          doHandshake(payload, message.getHeaders());
          this.shook = true;
          WebSocketEvent event = new WebSocketEvent(this.getTheConnection(),
              WebSocketEventType.HANDSHAKE_COMPLETE, state.getPath(), state.getQueryString());
          this.getTheConnection().publishEvent(event);
        }
        catch (Exception e) {
          throw new MessageHandlingException(message, "Handshake failed", e);
        }
View Full Code Here

Examples of org.springframework.integration.x.ip.websocket.WebSocketSerializer.WebSocketState

    private WebSocketState getState(Object object) {
      Object stateKey = null;
      stateKey = this.getTheConnection().getDeserializerStateKey();
      Assert.notNull(stateKey, "StateKey must not be null:" + object);
      WebSocketState state = (WebSocketState) this.getRequiredDeserializer().getState(stateKey);
      Assert.notNull(state, "State must not be null:" + object);
      return state;
    }
View Full Code Here

Examples of org.springframework.integration.x.ip.websocket.WebSocketSerializer.WebSocketState

      WebSocketFrame close = new WebSocketFrame(WebSocketFrame.TYPE_CLOSE, error);
      close.setStatus(frame.getType() == WebSocketFrame.TYPE_INVALID_UTF8 ? (short) 1007 : (short) 1002);
      try {
        Object stateKey = this.getTheConnection().getDeserializerStateKey();
        if (stateKey != null) {
          WebSocketState webSocketState = (WebSocketState) this.getRequiredDeserializer().getState(stateKey);
          if (webSocketState != null) {
            webSocketState.setCloseInitiated(true);
          }
          this.send(MessageBuilder.withPayload(close)
              .copyHeaders(message.getHeaders())
              .build());
        }
View Full Code Here

Examples of org.springframework.integration.x.ip.websocket.WebSocketSerializer.WebSocketState

      return (WebSocketSerializer) deserializer;
    }

    public Map<String, String> getAdditionalHeaders() {
      Map<String, String> headers = new HashMap<String, String>();
      WebSocketState state = this.getState(this.getConnectionId());
      if (state.getPath() != null) {
        headers.put(WebSocketHeaders.PATH, state.getPath());
      }
      if (state.getQueryString() != null) {
        headers.put(WebSocketHeaders.QUERY_STRING, state.getQueryString());
      }
      return headers;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.