@Test
  public void handleMessageToClientConnectAck() {

    StompHeaderAccessor connectHeaders = StompHeaderAccessor.create(StompCommand.CONNECT);
    connectHeaders.setHeartbeat(10000, 10000);
    connectHeaders.setNativeHeader(StompHeaderAccessor.STOMP_ACCEPT_VERSION_HEADER, "1.0,1.1");
    Message<?> connectMessage =
        MessageBuilder.withPayload(new byte[0]).setHeaders(connectHeaders).build();

    SimpMessageHeaderAccessor connectAckHeaders =
        SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT_ACK);
    connectAckHeaders.setHeader(SimpMessageHeaderAccessor.CONNECT_MESSAGE_HEADER, connectMessage);
    Message<byte[]> connectAckMessage =
        MessageBuilder.withPayload(new byte[0]).setHeaders(connectAckHeaders).build();

    this.protocolHandler.handleMessageToClient(this.session, connectAckMessage);

    verifyNoMoreInteractions(this.channel);

    // Check CONNECTED reply

    assertEquals(1, this.session.getSentMessages().size());
    TextMessage textMessage = (TextMessage) this.session.getSentMessages().get(0);
    Message<?> message =
        new StompDecoder().decode(ByteBuffer.wrap(textMessage.getPayload().getBytes()));
    StompHeaderAccessor replyHeaders = StompHeaderAccessor.wrap(message);

    assertEquals(StompCommand.CONNECTED, replyHeaders.getCommand());
    assertEquals("1.1", replyHeaders.getVersion());
    assertArrayEquals(new long[] {0, 0}, replyHeaders.getHeartbeat());
    assertEquals("joe", replyHeaders.getNativeHeader("user-name").get(0));
  }
  @Test
  public void handleMessageFromClientInvalidStompCommand() {

    TextMessage textMessage = new TextMessage("FOO");

    this.protocolHandler.handleMessageFromClient(this.session, textMessage, this.channel);

    verifyZeroInteractions(this.channel);
    assertEquals(1, this.session.getSentMessages().size());
    TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
    assertTrue(actual.getPayload().startsWith("ERROR"));
  }
コード例 #3
0
    @Override
    protected void handleTextMessage(WebSocketSession session, TextMessage textMessage)
        throws Exception {

      ByteBuffer payload = ByteBuffer.wrap(textMessage.getPayload().getBytes(UTF_8));
      List<Message<byte[]>> messages = this.decoder.decode(payload);

      for (Message message : messages) {
        StompHeaderAccessor headers = StompHeaderAccessor.wrap(message);

        if (StompCommand.CONNECTED.equals(headers.getCommand())) {

          this.stompMessageHandler.afterConnected(session, headers);
        } else if (StompCommand.MESSAGE.equals(headers.getCommand())) {
          this.stompMessageHandler.handleMessage(message);
        } else if (StompCommand.RECEIPT.equals(headers.getCommand())) {
          this.stompMessageHandler.handleReceipt(headers.getReceiptId());
        } else if (StompCommand.ERROR.equals(headers.getCommand())) {
          this.stompMessageHandler.handleError(message);
        } else if (StompCommand.ERROR.equals(headers.getCommand())) {
          this.stompMessageHandler.afterDisconnected();
        } else {
          LOGGER.debug("Unhandled message " + message);
        }
      }
    }
コード例 #4
0
  @Override
  public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
    JsonObject jsonMessage = gson.fromJson(message.getPayload(), JsonObject.class);

    log.debug("Incoming message: {}", jsonMessage);

    switch (jsonMessage.get("id").getAsString()) {
      case "start":
        start(session, jsonMessage);
        break;
      case "show_faces":
        setVisualization(session, jsonMessage);
        break;
      case "scale_factor":
        setScaleFactor(session, jsonMessage);
        break;
      case "process_num_frames":
        setProcessNumberFrames(session, jsonMessage);
        break;
      case "width_to_process":
        setWidthToProcess(session, jsonMessage);
        break;
      case "get_stats":
        getStats(session);
        break;
      case "euclidean_dis":
        setEuclideanDistance(session, jsonMessage);
        break;
      case "area_threshold":
        setAreaThreshold(session, jsonMessage);
        break;
      case "track_treshold":
        setTrackThreshold(session, jsonMessage);
        break;
      case "stop":
        {
          UserSession user = users.remove(session.getId());
          if (user != null) {
            user.release();
          }
          break;
        }
      case "onIceCandidate":
        {
          JsonObject candidate = jsonMessage.get("candidate").getAsJsonObject();
          UserSession user = users.get(session.getId());
          if (user != null) {
            user.addCandidate(candidate);
          }
          break;
        }

      default:
        error(session, "Invalid message with id " + jsonMessage.get("id").getAsString());
        break;
    }
  }
コード例 #5
0
  @Override
  public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
    JsonObject jsonMessage = gson.fromJson(message.getPayload(), JsonObject.class);

    log.debug("Incoming message: {}", jsonMessage);

    switch (jsonMessage.get("id").getAsString()) {
      case "start":
        start(session, jsonMessage);
        break;
      case "show_mouths":
        setVisualization(session, jsonMessage);
        break;
      case "scale_factor":
        log.debug("Case scale factor");
        setScaleFactor(session, jsonMessage);
        break;
      case "process_num_frames":
        log.debug("Case process num frames");
        setProcessNumberFrames(session, jsonMessage);
        break;
      case "width_to_process":
        log.debug("Case width to process");
        setWidthToProcess(session, jsonMessage);
        break;
      case "stop":
        {
          UserSession user = users.remove(session.getId());
          if (user != null) {
            user.release();
          }
          break;
        }
      case "onIceCandidate":
        {
          JsonObject candidate = jsonMessage.get("candidate").getAsJsonObject();

          UserSession user = users.get(session.getId());
          if (user != null) {
            IceCandidate cand =
                new IceCandidate(
                    candidate.get("candidate").getAsString(),
                    candidate.get("sdpMid").getAsString(),
                    candidate.get("sdpMLineIndex").getAsInt());
            user.addCandidate(cand);
          }
          break;
        }

      default:
        sendError(session, "Invalid message with id " + jsonMessage.get("id").getAsString());
        break;
    }
  }
コード例 #6
0
 @Override
 protected void handleTextMessage(WebSocketSession session, TextMessage message) {
   List<WebSocketSession> sessions = Sessions.getSessions();
   for (WebSocketSession webSocketSession : sessions) {
     try {
       webSocketSession.sendMessage(new TextMessage(message.getPayload()));
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }
コード例 #7
0
 @Override
 public void handleMessage(WebSocketSession session, TextMessage message) {
   // The text message should just contain the id of the ballot
   try {
     String payload = message.getPayload();
     Long id = Long.parseLong(payload);
     // now update the hash map
     sessions.put(session, id);
   } catch (Exception e) {
     // We cannot parse the message or other so try to remove the session
     sessions.remove(session.getId());
   }
 }
コード例 #8
0
 @Override
 protected void sendTextMessage(TextMessage message) throws IOException {
   getNativeSession().getBasicRemote().sendText(message.getPayload(), message.isLast());
 }
コード例 #9
0
 @Override
 protected void sendTextMessage(TextMessage message) throws IOException {
   getNativeSession().getRemote().sendString(message.getPayload());
 }
コード例 #10
0
 @Override
 protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
   super.handleTextMessage(session, message);
   TextMessage returnMessage = new TextMessage(message.getPayload() + " received at server");
   session.sendMessage(returnMessage);
 }
コード例 #11
0
 @Override
 protected ResponseEntity<String> executeSendRequestInternal(
     URI url, HttpHeaders headers, TextMessage message) {
   return executeRequest(url, Methods.POST, headers, message.getPayload());
 }