Package org.springframework.messaging.simp

Examples of org.springframework.messaging.simp.SimpMessageHeaderAccessor


    verify(this.messageChannel).send(this.messageCaptor.capture());
    assertNotNull(this.messageCaptor.getValue());

    Message<?> message = this.messageCaptor.getValue();
    SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.wrap(message);

    assertNull("SimpMessageHeaderAccessor should have disabled id", headerAccessor.getId());
    assertNull("SimpMessageHeaderAccessor should have disabled timestamp", headerAccessor.getTimestamp());
    assertEquals(sessionId, headerAccessor.getSessionId());
    assertEquals(subscriptionId, headerAccessor.getSubscriptionId());
    assertEquals(destination, headerAccessor.getDestination());
    assertEquals(MIME_TYPE, headerAccessor.getContentType());
  }
View Full Code Here


    handler.handleReturnValue(PAYLOAD, this.subscribeEventReturnType, inputMessage);

    ArgumentCaptor<MessageHeaders> captor = ArgumentCaptor.forClass(MessageHeaders.class);
    verify(messagingTemplate).convertAndSend(eq("/dest"), eq(PAYLOAD), captor.capture());

    SimpMessageHeaderAccessor headerAccessor =
        MessageHeaderAccessor.getAccessor(captor.getValue(), SimpMessageHeaderAccessor.class);

    assertNotNull(headerAccessor);
    assertTrue(headerAccessor.isMutable());
    assertEquals(sessionId, headerAccessor.getSessionId());
    assertEquals(subscriptionId, headerAccessor.getSubscriptionId());
  }
View Full Code Here

    assertEquals(subscriptionId, headerAccessor.getSubscriptionId());
  }


  private Message<?> createInputMessage(String sessId, String subsId, String dest, Principal principal) {
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create();
    headers.setSessionId(sessId);
    headers.setSubscriptionId(subsId);
    headers.setDestination(dest);
    headers.setUser(principal);
    return MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toMap()).build();
  }
View Full Code Here

    if ((subscriptions.size() > 0) && logger.isDebugEnabled()) {
      logger.debug("Broadcasting to " + subscriptions.size() + " sessions.");
    }
    for (String sessionId : subscriptions.keySet()) {
      for (String subscriptionId : subscriptions.get(sessionId)) {
        SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
        initHeaders(headerAccessor);
        headerAccessor.setSessionId(sessionId);
        headerAccessor.setSubscriptionId(subscriptionId);
        headerAccessor.copyHeadersIfAbsent(message.getHeaders());
        Object payload = message.getPayload();
        Message<?> reply = MessageBuilder.createMessage(payload, headerAccessor.getMessageHeaders());
        try {
          getClientOutboundChannel().send(reply);
        }
        catch (Throwable ex) {
          logger.error("Failed to send " + message, ex);
View Full Code Here

    this.messagingTemplate.convertAndSend(destination, returnValue, createHeaders(sessionId, subscriptionId));
  }

  private MessageHeaders createHeaders(String sessionId, String subscriptionId) {
    SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
    if (getHeaderInitializer() != null) {
      getHeaderInitializer().initHeaders(headerAccessor);
    }
    headerAccessor.setSessionId(sessionId);
    headerAccessor.setSubscriptionId(subscriptionId);
    headerAccessor.setLeaveMutable(true);
    return headerAccessor.getMessageHeaders();
  }
View Full Code Here

        logger.trace("No user destinations found for " + result.getSourceDestination());
      }
      return;
    }
    if (SimpMessageType.MESSAGE.equals(SimpMessageHeaderAccessor.getMessageType(message.getHeaders()))) {
      SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.wrap(message);
      initHeaders(headerAccessor);
      String header = SimpMessageHeaderAccessor.ORIGINAL_DESTINATION;
      headerAccessor.setNativeHeader(header, result.getSubscribeDestination());
      message = MessageBuilder.createMessage(message.getPayload(), headerAccessor.getMessageHeaders());
    }
    if (logger.isDebugEnabled()) {
      logger.debug("Translated " + result.getSourceDestination() + " -> " + destinations);
    }
    for (String destination : destinations) {
View Full Code Here

    return (destination.startsWith("/") ?
        new String[] {defaultPrefix + destination} : new String[] {defaultPrefix + "/" + destination});
  }

  private MessageHeaders createHeaders(String sessionId) {
    SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
    if (getHeaderInitializer() != null) {
      getHeaderInitializer().initHeaders(headerAccessor);
    }
    headerAccessor.setSessionId(sessionId);
    headerAccessor.setLeaveMutable(true);
    return headerAccessor.getMessageHeaders();
  }
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.