org.springframework.messaging.simp.stomp

## Class StompHeaderAccessor

- java.lang.Object
- - org.springframework.messaging.support.MessageHeaderAccessor
  - - org.springframework.messaging.support.NativeMessageHeaderAccessor
    - - org.springframework.messaging.simp.SimpMessageHeaderAccessor
      - - org.springframework.messaging.simp.stomp.StompHeaderAccessor

-     public class StompHeaderAccessor
      extends SimpMessageHeaderAccessor

  A `MessageHeaderAccessor` to use when creating a `Message` from a decoded STOMP frame, or when encoding a `Message` to a STOMP frame.

  When created from STOMP frame content, the actual STOMP headers are stored in the native header sub-map managed by the parent class `NativeMessageHeaderAccessor` while the parent class `SimpMessageHeaderAccessor` manages common processing headers some of which are based on STOMP headers (e.g. destination, content-type, etc).

  An instance of this class can also be created by wrapping an existing `Message`. That message may have been created with the more generic `SimpMessageHeaderAccessor` in which case STOMP headers are created from common processing headers. In this case it is also necessary to invoke either `updateStompCommandAsClientMessage()` or `updateStompCommandAsServerMessage()` if sending a message and depending on whether a message is sent to a client or the message broker.

  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `STOMP_ACCEPT_VERSION_HEADER`
    `static String` | `STOMP_ACK_HEADER`
    `static String` | `STOMP_CONTENT_LENGTH_HEADER`
    `static String` | `STOMP_CONTENT_TYPE_HEADER`
    `static String` | `STOMP_DESTINATION_HEADER`
    `static String` | `STOMP_HEARTBEAT_HEADER`
    `static String` | `STOMP_HOST_HEADER`
    `static String` | `STOMP_ID_HEADER`
    `static String` | `STOMP_LOGIN_HEADER`
    `static String` | `STOMP_MESSAGE_HEADER`
    `static String` | `STOMP_MESSAGE_ID_HEADER`
    `static String` | `STOMP_NACK_HEADER`
    `static String` | `STOMP_PASSCODE_HEADER`
    `static String` | `STOMP_RECEIPT_HEADER`
    `static String` | `STOMP_RECEIPT_ID_HEADER`
    `static String` | `STOMP_SUBSCRIPTION_HEADER`
    `static String` | `STOMP_VERSION_HEADER`

    - ### Fields inherited from class org.springframework.messaging.simp.SimpMessageHeaderAccessor

      `CONNECT_MESSAGE_HEADER, DESTINATION_HEADER, DISCONNECT_MESSAGE_HEADER, HEART_BEAT_HEADER, IGNORE_ERROR, MESSAGE_TYPE_HEADER, ORIGINAL_DESTINATION, SESSION_ATTRIBUTES, SESSION_ID_HEADER, SUBSCRIPTION_ID_HEADER, USER_HEADER`

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

      `NATIVE_HEADERS`

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

      `DEFAULT_CHARSET`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static StompHeaderAccessor` | `create(StompCommand command)` Create an instance for the given STOMP command.
    `static StompHeaderAccessor` | `create(StompCommand command, Map<String,List<String>> headers)` Create an instance for the given STOMP command and headers.
    `protected MessageHeaderAccessor` | `createAccessor(Message<?> message)` Build a 'nested' accessor for the given message.
    `static StompHeaderAccessor` | `createForHeartbeat()` Create headers for a heartbeat.
    `Set<String>` | `getAcceptVersion()`
    `String` | `getAck()`
    `StompCommand` | `getCommand()` Return the STOMP command, or `null` if not yet set.
    `static StompCommand` | `getCommand(Map<String,Object> headers)` Return the STOMP command from the given headers, or `null` if not set.
    `Integer` | `getContentLength()`
    `static Integer` | `getContentLength(Map<String,List<String>> nativeHeaders)`
    `String` | `getDetailedLogMessage(Object payload)` Return a more detailed message for logging purposes.
    `long[]` | `getHeartbeat()`
    `String` | `getHost()`
    `String` | `getLogin()`
    `String` | `getMessage()`
    `String` | `getMessageId()`
    `String` | `getNack()`
    `protected Map<String,List<String>>` | `getNativeHeaders()` Subclasses can use this method to access the "native" headers sub-map.
    `String` | `getPasscode()` Return the passcode header value, or `null` if not set.
    `static String` | `getPasscode(Map<String,Object> headers)` Return the passcode header value, or `null` if not set.
    `String` | `getReceipt()`
    `String` | `getReceiptId()`
    `String` | `getShortLogMessage(Object payload)` Return a concise message for logging purposes.
    `String` | `getVersion()`
    `boolean` | `isHeartbeat()`
    `void` | `setAcceptVersion(String acceptVersion)`
    `void` | `setAck(String ack)`
    `void` | `setContentLength(int contentLength)`
    `void` | `setContentType(MimeType contentType)`
    `void` | `setDestination(String destination)`
    `void` | `setHeartbeat(long cx, long cy)`
    `void` | `setHost(String host)`
    `void` | `setLogin(String login)`
    `void` | `setMessage(String content)`
    `void` | `setMessageId(String id)`
    `void` | `setNack(String nack)`
    `void` | `setPasscode(String passcode)`
    `void` | `setReceipt(String receiptId)`
    `void` | `setReceiptId(String receiptId)`
    `void` | `setSubscriptionId(String subscriptionId)`
    `void` | `setVersion(String version)`
    `StompCommand` | `updateStompCommandAsClientMessage()`
    `void` | `updateStompCommandAsServerMessage()`
    `static StompHeaderAccessor` | `wrap(Message<?> message)` Create an instance from the payload and headers of the given Message.

    - ### Methods inherited from class org.springframework.messaging.simp.SimpMessageHeaderAccessor

      `create, create, getDestination, getDestination, getHeartbeat, getMessageType, getMessageType, getSessionAttributes, getSessionAttributes, getSessionId, getSessionId, getSubscriptionId, getSubscriptionId, getUser, getUser, setMessageTypeIfNotSet, setSessionAttributes, setSessionId, setUser, setUserChangeCallback`

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

      `addNativeHeader, addNativeHeaders, containsNativeHeader, copyHeaders, copyHeadersIfAbsent, getFirstNativeHeader, getFirstNativeHeader, getNativeHeader, removeNativeHeader, setImmutable, setNativeHeader, setNativeHeaderValues, toNativeHeaderMap`

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

      `getAccessor, getAccessor, getAccessor, getContentType, getDetailedPayloadLogMessage, getErrorChannel, getHeader, getId, getMessageHeaders, getMutableAccessor, getReplyChannel, getShortPayloadLogMessage, getTimestamp, isModified, isMutable, isReadableContentType, isReadOnly, removeHeader, removeHeaders, setErrorChannel, setErrorChannelName, setHeader, setHeaderIfAbsent, setLeaveMutable, setModified, setReplyChannel, setReplyChannelName, toMap, toMessageHeaders, toString, verifyType`

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

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

- - ### Field Detail

    - #### STOMP_ID_HEADER

          public static final String STOMP_ID_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_HOST_HEADER

          public static final String STOMP_HOST_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_ACCEPT_VERSION_HEADER

          public static final String STOMP_ACCEPT_VERSION_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_MESSAGE_ID_HEADER

          public static final String STOMP_MESSAGE_ID_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_RECEIPT_HEADER

          public static final String STOMP_RECEIPT_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_RECEIPT_ID_HEADER

          public static final String STOMP_RECEIPT_ID_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_SUBSCRIPTION_HEADER

          public static final String STOMP_SUBSCRIPTION_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_VERSION_HEADER

          public static final String STOMP_VERSION_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_MESSAGE_HEADER

          public static final String STOMP_MESSAGE_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_ACK_HEADER

          public static final String STOMP_ACK_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_NACK_HEADER

          public static final String STOMP_NACK_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_LOGIN_HEADER

          public static final String STOMP_LOGIN_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_PASSCODE_HEADER

          public static final String STOMP_PASSCODE_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_DESTINATION_HEADER

          public static final String STOMP_DESTINATION_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_CONTENT_TYPE_HEADER

          public static final String STOMP_CONTENT_TYPE_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_CONTENT_LENGTH_HEADER

          public static final String STOMP_CONTENT_LENGTH_HEADER

      See Also:
        Constant Field Values

    - #### STOMP_HEARTBEAT_HEADER

          public static final String STOMP_HEARTBEAT_HEADER

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### createAccessor

          protected MessageHeaderAccessor createAccessor(Message<?> message)

      Description copied from class: `MessageHeaderAccessor`
      Build a 'nested' accessor for the given message.
      Overrides:
        `createAccessor` in class `SimpMessageHeaderAccessor`
      Parameters:
        `message` - the message to build a new accessor for
      Returns:
        the nested accessor (typically a specific subclass)

    - #### getNativeHeaders

          @Nullable
          protected Map<String,List<String>> getNativeHeaders()

      Description copied from class: `NativeMessageHeaderAccessor`
      Subclasses can use this method to access the "native" headers sub-map.
      Overrides:
        `getNativeHeaders` in class `NativeMessageHeaderAccessor`

    - #### updateStompCommandAsClientMessage

          public StompCommand updateStompCommandAsClientMessage()

    - #### updateStompCommandAsServerMessage

          public void updateStompCommandAsServerMessage()

    - #### getCommand

          @Nullable
          public StompCommand getCommand()

      Return the STOMP command, or `null` if not yet set.

    - #### isHeartbeat

          public boolean isHeartbeat()

    - #### getHeartbeat

          public long[] getHeartbeat()

    - #### setAcceptVersion

          public void setAcceptVersion(String acceptVersion)

    - #### getAcceptVersion

          public Set<String> getAcceptVersion()

    - #### setHost

          public void setHost(@Nullable
                              String host)

    - #### getHost

          @Nullable
          public String getHost()

    - #### setDestination

          public void setDestination(@Nullable
                                     String destination)

      Overrides:
        `setDestination` in class `SimpMessageHeaderAccessor`

    - #### setContentType

          public void setContentType(MimeType contentType)

      Overrides:
        `setContentType` in class `MessageHeaderAccessor`

    - #### setSubscriptionId

          public void setSubscriptionId(@Nullable
                                        String subscriptionId)

      Overrides:
        `setSubscriptionId` in class `SimpMessageHeaderAccessor`

    - #### getContentLength

          @Nullable
          public Integer getContentLength()

    - #### setContentLength

          public void setContentLength(int contentLength)

    - #### setHeartbeat

          public void setHeartbeat(long cx,
                                   long cy)

    - #### setAck

          public void setAck(@Nullable
                             String ack)

    - #### getAck

          @Nullable
          public String getAck()

    - #### setNack

          public void setNack(@Nullable
                              String nack)

    - #### getNack

          @Nullable
          public String getNack()

    - #### setLogin

          public void setLogin(@Nullable
                               String login)

    - #### getLogin

          @Nullable
          public String getLogin()

    - #### setPasscode

          public void setPasscode(@Nullable
                                  String passcode)

    - #### getPasscode

          @Nullable
          public String getPasscode()

      Return the passcode header value, or `null` if not set.

    - #### setReceiptId

          public void setReceiptId(@Nullable
                                   String receiptId)

    - #### getReceiptId

          @Nullable
          public String getReceiptId()

    - #### setReceipt

          public void setReceipt(@Nullable
                                 String receiptId)

    - #### getReceipt

          @Nullable
          public String getReceipt()

    - #### getMessage

          @Nullable
          public String getMessage()

    - #### setMessage

          public void setMessage(@Nullable
                                 String content)

    - #### getMessageId

          @Nullable
          public String getMessageId()

    - #### setMessageId

          public void setMessageId(@Nullable
                                   String id)

    - #### getVersion

          @Nullable
          public String getVersion()

    - #### setVersion

          public void setVersion(@Nullable
                                 String version)

    - #### getShortLogMessage

          public String getShortLogMessage(Object payload)

      Description copied from class: `MessageHeaderAccessor`
      Return a concise message for logging purposes.
      Overrides:
        `getShortLogMessage` in class `SimpMessageHeaderAccessor`
      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 `SimpMessageHeaderAccessor`
      Parameters:
        `payload` - the payload that corresponds to the headers.
      Returns:
        the message

    - #### create

          public static StompHeaderAccessor create(StompCommand command)

      Create an instance for the given STOMP command.

    - #### create

          public static StompHeaderAccessor create(StompCommand command,
                                                   Map<String,List<String>> headers)

      Create an instance for the given STOMP command and headers.

    - #### createForHeartbeat

          public static StompHeaderAccessor createForHeartbeat()

      Create headers for a heartbeat. While a STOMP heartbeat frame does not have headers, a session id is needed for processing purposes at a minimum.

    - #### wrap

          public static StompHeaderAccessor wrap(Message<?> message)

      Create an instance from the payload and headers of the given Message.

    - #### getCommand

          @Nullable
          public static StompCommand getCommand(Map<String,Object> headers)

      Return the STOMP command from the given headers, or `null` if not set.

    - #### getPasscode

          @Nullable
          public static String getPasscode(Map<String,Object> headers)

      Return the passcode header value, or `null` if not set.

    - #### getContentLength

          @Nullable
          public static Integer getContentLength(Map<String,List<String>> nativeHeaders)