org.springframework.messaging.simp

## Class SimpMessageHeaderAccessor

- java.lang.Object
- - org.springframework.messaging.support.MessageHeaderAccessor
  - - org.springframework.messaging.support.NativeMessageHeaderAccessor
    - - org.springframework.messaging.simp.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 method in this class, then call getters and setters, and at the end if necessary call `NativeMessageHeaderAccessor.toMap()` to obtain the updated headers.

  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `CONNECT_MESSAGE_HEADER`
    `static String` | `DESTINATION_HEADER`
    `static String` | `MESSAGE_TYPE_HEADER`
    `static String` | `SESSION_ATTRIBUTES`
    `static String` | `SESSION_ID_HEADER`
    `static String` | `SUBSCRIPTION_ID_HEADER`
    `static String` | `USER_HEADER`

    - ### Fields inherited from class org.springframework.messaging.support.NativeMessageHeaderAccessor

      `NATIVE_HEADERS`

    - ### Fields inherited from class org.springframework.messaging.support.MessageHeaderAccessor

      `logger`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `SimpMessageHeaderAccessor(Message<?> message)` A constructor for accessing and modifying existing message headers.
    `protected` | `SimpMessageHeaderAccessor(SimpMessageType messageType, Map<String,List<String>> externalSourceHeaders)` A constructor for creating new message headers.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static SimpMessageHeaderAccessor` | `create()` Create `SimpMessageHeaderAccessor` for a new `Message` with `SimpMessageType.MESSAGE`.
    `static SimpMessageHeaderAccessor` | `create(SimpMessageType messageType)` Create `SimpMessageHeaderAccessor` for a new `Message` of a specific type.
    `String` | `getDestination()`
    `SimpMessageType` | `getMessageType()`
    `Map<String,Object>` | `getSessionAttributes()`
    `String` | `getSessionId()`
    `String` | `getSubscriptionId()`
    `Principal` | `getUser()`
    `void` | `setDestination(String destination)`
    `void` | `setMessageTypeIfNotSet(SimpMessageType messageType)`
    `void` | `setSessionAttributes(Map<String,Object> attributes)`
    `void` | `setSessionId(String sessionId)`
    `void` | `setSubscriptionId(String subscriptionId)`
    `void` | `setUser(Principal principal)`
    `static SimpMessageHeaderAccessor` | `wrap(Message<?> message)` Create `SimpMessageHeaderAccessor` from the headers of an existing message.

    - ### Methods inherited from class org.springframework.messaging.support.NativeMessageHeaderAccessor

      `addNativeHeader, getFirstNativeHeader, getNativeHeader, isModified, setNativeHeader, toMap, toNativeHeaderMap`

    - ### Methods inherited from class org.springframework.messaging.support.MessageHeaderAccessor

      `copyHeaders, copyHeadersIfAbsent, getContentType, getErrorChannel, getHeader, getId, getReplyChannel, getTimestamp, isReadOnly, removeHeader, removeHeaders, setContentType, setErrorChannel, setErrorChannelName, setHeader, setHeaderIfAbsent, setReplyChannel, setReplyChannelName, toString, verifyType`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### CONNECT_MESSAGE_HEADER

          public static final String CONNECT_MESSAGE_HEADER

      See Also:
        Constant Field Values

    - #### DESTINATION_HEADER

          public static final String DESTINATION_HEADER

      See Also:
        Constant Field Values

    - #### MESSAGE_TYPE_HEADER

          public static final String MESSAGE_TYPE_HEADER

      See Also:
        Constant Field Values

    - #### SESSION_ID_HEADER

          public static final String SESSION_ID_HEADER

      See Also:
        Constant Field Values

    - #### SESSION_ATTRIBUTES

          public static final String SESSION_ATTRIBUTES

      See Also:
        Constant Field Values

    - #### SUBSCRIPTION_ID_HEADER

          public static final String SUBSCRIPTION_ID_HEADER

      See Also:
        Constant Field Values

    - #### USER_HEADER

          public static final String USER_HEADER

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SimpMessageHeaderAccessor

          protected SimpMessageHeaderAccessor(SimpMessageType messageType,
                                              Map<String,List<String>> externalSourceHeaders)

      A constructor for creating new message headers. This constructor is protected. See factory methods in this and sub-classes.

    - #### SimpMessageHeaderAccessor

          protected SimpMessageHeaderAccessor(Message<?> message)

      A constructor for accessing and modifying existing message headers. This constructor is protected. See factory methods in this and sub-classes.

  - ### Method Detail

    - #### create

          public static SimpMessageHeaderAccessor create()

      Create `SimpMessageHeaderAccessor` for a new `Message` with `SimpMessageType.MESSAGE`.

    - #### create

          public static SimpMessageHeaderAccessor create(SimpMessageType messageType)

      Create `SimpMessageHeaderAccessor` for a new `Message` of a specific type.

    - #### wrap

          public static SimpMessageHeaderAccessor wrap(Message<?> message)

      Create `SimpMessageHeaderAccessor` from the headers of an existing message.

    - #### setMessageTypeIfNotSet

          public void setMessageTypeIfNotSet(SimpMessageType messageType)

    - #### getMessageType

          public SimpMessageType getMessageType()

    - #### setDestination

          public void setDestination(String destination)

    - #### getDestination

          public String getDestination()

    - #### getSubscriptionId

          public String getSubscriptionId()

    - #### setSubscriptionId

          public void setSubscriptionId(String subscriptionId)

    - #### getSessionId

          public String getSessionId()

    - #### setSessionId

          public void setSessionId(String sessionId)

    - #### getSessionAttributes

          public Map<String,Object> getSessionAttributes()

    - #### setSessionAttributes

          public void setSessionAttributes(Map<String,Object> attributes)

    - #### getUser

          public Principal getUser()

    - #### setUser

          public void setUser(Principal principal)