Class SimpMessageHeaderAccessor

Direct Known Subclasses:
StompHeaderAccessor

public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor
A base class for working with message headers in simple messaging protocols that support basic messaging patterns. Provides uniform access to specific values common across protocols such as a destination, message type (e.g. publish, subscribe, etc), session ID, and others.

Use one of the static factory methods in this class, then call getters and setters, and at the end if necessary call MessageHeaderAccessor.toMap() to obtain the updated headers.

Since:
4.0
Author:
Rossen Stoyanchev
  • Field Details

  • Constructor Details

    • SimpMessageHeaderAccessor

      protected SimpMessageHeaderAccessor(SimpMessageType messageType, @Nullable Map<String,List<String>> externalSourceHeaders)
      A constructor for creating new message headers.

      This constructor is protected. See factory methods in this class and subclasses.

    • SimpMessageHeaderAccessor

      protected SimpMessageHeaderAccessor(Message<?> message)
      A constructor for accessing and modifying existing message headers.

      This constructor is protected. See factory methods in this class and subclasses.

  • Method Details

    • createAccessor

      protected MessageHeaderAccessor createAccessor(Message<?> message)
      Description copied from class: MessageHeaderAccessor
      Build a 'nested' accessor for the given message.
      Overrides:
      createAccessor in class MessageHeaderAccessor
      Parameters:
      message - the message to build a new accessor for
      Returns:
      the nested accessor (typically a specific subclass)
    • setMessageTypeIfNotSet

      public void setMessageTypeIfNotSet(SimpMessageType messageType)
    • getMessageType

      @Nullable public SimpMessageType getMessageType()
    • setDestination

      public void setDestination(@Nullable String destination)
    • getDestination

      @Nullable public String getDestination()
    • setSubscriptionId

      public void setSubscriptionId(@Nullable String subscriptionId)
    • getSubscriptionId

      @Nullable public String getSubscriptionId()
    • setSessionId

      public void setSessionId(@Nullable String sessionId)
    • getSessionId

      @Nullable public String getSessionId()
      Return the id of the current session.
    • setSessionAttributes

      public void setSessionAttributes(@Nullable Map<String,Object> attributes)
      A static alternative for access to the session attributes header.
    • getSessionAttributes

      @Nullable public Map<String,Object> getSessionAttributes()
      Return the attributes associated with the current session.
    • setUser

      public void setUser(@Nullable Principal principal)
    • getUser

      @Nullable public Principal getUser()
      Return the user associated with the current session.
    • setUserChangeCallback

      public void setUserChangeCallback(Consumer<Principal> callback)
      Provide a callback to be invoked if and when setUser(Principal) is called. This is used internally on the inbound channel to detect token-based authentications through an interceptor.
      Parameters:
      callback - the callback to invoke
      Since:
      5.1.9
    • getShortLogMessage

      public String getShortLogMessage(Object payload)
      Description copied from class: MessageHeaderAccessor
      Return a concise message for logging purposes.
      Overrides:
      getShortLogMessage in class MessageHeaderAccessor
      Parameters:
      payload - the payload that corresponds to the headers.
      Returns:
      the message
    • getDetailedLogMessage

      public String getDetailedLogMessage(@Nullable Object payload)
      Description copied from class: MessageHeaderAccessor
      Return a more detailed message for logging purposes.
      Overrides:
      getDetailedLogMessage in class MessageHeaderAccessor
      Parameters:
      payload - the payload that corresponds to the headers.
      Returns:
      the message
    • create

      public static SimpMessageHeaderAccessor create()
      Create an instance with SimpMessageType MESSAGE.
    • create

      public static SimpMessageHeaderAccessor create(SimpMessageType messageType)
      Create an instance with the given SimpMessageType.
    • wrap

      public static SimpMessageHeaderAccessor wrap(Message<?> message)
      Create an instance from the payload and headers of the given Message.
    • getMessageType

      @Nullable public static SimpMessageType getMessageType(Map<String,Object> headers)
    • getDestination

      @Nullable public static String getDestination(Map<String,Object> headers)
    • getSubscriptionId

      @Nullable public static String getSubscriptionId(Map<String,Object> headers)
    • getSessionId

      @Nullable public static String getSessionId(Map<String,Object> headers)
    • getSessionAttributes

      @Nullable public static Map<String,Object> getSessionAttributes(Map<String,Object> headers)
    • getUser

      @Nullable public static Principal getUser(Map<String,Object> headers)
    • getHeartbeat

      @Nullable public static long[] getHeartbeat(Map<String,Object> headers)