Package org.springframework.messaging.simp

Examples of org.springframework.messaging.simp.SimpMessageHeaderAccessor


    StompHeaderAccessor connectHeaders = StompHeaderAccessor.create(StompCommand.CONNECT);
    connectHeaders.setHeartbeat(10000, 10000);
    connectHeaders.setAcceptVersion("1.0,1.1");
    Message<?> connectMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, connectHeaders.getMessageHeaders());

    SimpMessageHeaderAccessor connectAckHeaders = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT_ACK);
    connectAckHeaders.setHeader(SimpMessageHeaderAccessor.CONNECT_MESSAGE_HEADER, connectMessage);
    Message<byte[]> connectAckMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, connectAckHeaders.getMessageHeaders());

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

    verifyNoMoreInteractions(this.channel);
View Full Code Here


    if (!checkDestinationPrefix(destination)) {
      return;
    }

    SimpMessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, SimpMessageHeaderAccessor.class);
    if (accessor == null) {
      throw new IllegalStateException(
          "No header accessor (not using the SimpMessagingTemplate?): " + message);
    }

    if (SimpMessageType.MESSAGE.equals(messageType)) {
      if (logger.isDebugEnabled()) {
        logger.debug("Processing " + accessor.getShortLogMessage(message.getPayload()));
      }
      sendMessageToSubscribers(destination, message);
    }
    else if (SimpMessageType.CONNECT.equals(messageType)) {
      if (logger.isDebugEnabled()) {
        logger.debug("Processing " + accessor.getShortLogMessage(EMPTY_PAYLOAD));
      }
      SimpMessageHeaderAccessor connectAck = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT_ACK);
      initHeaders(connectAck);
      connectAck.setSessionId(sessionId);
      connectAck.setHeader(SimpMessageHeaderAccessor.CONNECT_MESSAGE_HEADER, message);
      Message<byte[]> messageOut = MessageBuilder.createMessage(EMPTY_PAYLOAD, connectAck.getMessageHeaders());
      getClientOutboundChannel().send(messageOut);
    }
    else if (SimpMessageType.DISCONNECT.equals(messageType)) {
      if (logger.isDebugEnabled()) {
        logger.debug("Processing " + accessor.getShortLogMessage(EMPTY_PAYLOAD));
      }
      this.subscriptionRegistry.unregisterAllSubscriptions(sessionId);
      SimpMessageHeaderAccessor disconnectAck = SimpMessageHeaderAccessor.create(SimpMessageType.DISCONNECT_ACK);
      initHeaders(disconnectAck);
      disconnectAck.setSessionId(sessionId);
      Message<byte[]> messageOut = MessageBuilder.createMessage(EMPTY_PAYLOAD, disconnectAck.getMessageHeaders());
      getClientOutboundChannel().send(messageOut);
    }
    else if (SimpMessageType.SUBSCRIBE.equals(messageType)) {
      if (logger.isDebugEnabled()) {
        logger.debug("Processing " + accessor.getShortLogMessage(EMPTY_PAYLOAD));
View Full Code Here

    assertEquals("bar", message.getHeaders().get("foo"));
  }

  @Test
  public void toMessageWithMutableMessageHeaders() {
    SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
    accessor.setHeader("foo", "bar");
    accessor.setNativeHeader("fooNative", "barNative");
    accessor.setLeaveMutable(true);

    MessageHeaders headers = accessor.getMessageHeaders();
    Message<?> message = this.converter.toMessage("ABC", headers);

    assertSame(headers, message.getHeaders());
    assertNull(message.getHeaders().getId());
    assertNull(message.getHeaders().getTimestamp());
View Full Code Here

      builder.expected.add(new StompReceiptFrameMessageMatcher(sessionId, receiptId));
      return builder;
    }

    public static MessageExchangeBuilder send(String destination, String payload) {
      SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
      headers.setDestination(destination);
      Message<?> message = MessageBuilder.createMessage(payload.getBytes(UTF_8), headers.getMessageHeaders());
      return new MessageExchangeBuilder(message);
    }
View Full Code Here

  }

  @Test
  public void toNativeHeadersContentType() {

    SimpMessageHeaderAccessor simpHeaderAccessor = SimpMessageHeaderAccessor.create();
    simpHeaderAccessor.setContentType(MimeTypeUtils.APPLICATION_ATOM_XML);
    Message<byte[]> message = MessageBuilder.createMessage(new byte[0], simpHeaderAccessor.getMessageHeaders());

    StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(message);
    Map<String, List<String>> map = stompHeaderAccessor.toNativeHeaderMap();

    assertEquals("application/atom+xml", map.get(StompHeaderAccessor.STOMP_CONTENT_TYPE_HEADER).get(0));
View Full Code Here

  @Test
  public void testDestinationExcluded() throws Exception {

    this.brokerRelay.start();

    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
    headers.setSessionId("sess1");
    headers.setDestination("/user/daisy/foo");
    this.brokerRelay.handleMessage(MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders()));

    List<Message<byte[]>> sent = this.tcpClient.connection.messages;
    assertEquals(1, sent.size());
    assertEquals(StompCommand.CONNECT, StompHeaderAccessor.wrap(sent.get(0)).getCommand());
    assertNotNull("The prepared message does not have an accessor",
View Full Code Here

    assertNull(actual);
  }


  private Message<?> createMessage(SimpMessageType messageType, TestPrincipal user, String sessionId, String destination) {
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(messageType);
    if (destination != null) {
      headers.setDestination(destination);
    }
    if (user != null) {
      headers.setUser(user);
    }
    if (sessionId != null) {
      headers.setSessionId(sessionId);
    }
    return MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
  }
View Full Code Here

    assertEquals("Expected no elements " + actual, 0, actual.size());
  }


  private Message<?> subscribeMessage(String sessionId, String subscriptionId, String destination) {
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.SUBSCRIBE);
    headers.setSessionId(sessionId);
    headers.setSubscriptionId(subscriptionId);
    if (destination != null) {
      headers.setDestination(destination);
    }
    return MessageBuilder.withPayload("").copyHeaders(headers.toMap()).build();
  }
View Full Code Here

    }
    return MessageBuilder.withPayload("").copyHeaders(headers.toMap()).build();
  }

  private Message<?> unsubscribeMessage(String sessionId, String subscriptionId) {
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.UNSUBSCRIBE);
    headers.setSessionId(sessionId);
    headers.setSubscriptionId(subscriptionId);
    return MessageBuilder.withPayload("").copyHeaders(headers.toMap()).build();
  }
View Full Code Here

    headers.setSubscriptionId(subscriptionId);
    return MessageBuilder.withPayload("").copyHeaders(headers.toMap()).build();
  }

  private Message<?> message(String destination) {
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create();
    headers.setDestination(destination);
    return MessageBuilder.withPayload("").copyHeaders(headers.toMap()).build();
  }
View Full Code Here

TOP

Related Classes of org.springframework.messaging.simp.SimpMessageHeaderAccessor

Copyright © 2018 www.massapicom. 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.