org.springframework.messaging.support

## Class NativeMessageHeaderAccessor

- java.lang.Object
- - org.springframework.messaging.support.MessageHeaderAccessor
  - - org.springframework.messaging.support.NativeMessageHeaderAccessor

- Direct Known Subclasses:
    SimpMessageHeaderAccessor

      public class NativeMessageHeaderAccessor
      extends MessageHeaderAccessor

  An extension of `MessageHeaderAccessor` that also stores and provides read/write access to message headers from an external source -- e.g. a Spring `Message` created to represent a STOMP message received from a STOMP client or message broker. Native message headers are kept in a `MultiValueMap` under the key `NATIVE_HEADERS`.

  This class is not intended for direct use but is rather expected to be consumed through sub-classes such as `StompHeaderAccessor`. Such sub-classes may provide factory methods to translate message headers from an external messaging source (e.g. STOMP) to Spring `Message` headers and reversely to translate Spring `Message` headers to a message to send to an external source.

  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `NATIVE_HEADERS`

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

      `logger`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `NativeMessageHeaderAccessor(Map<String,List<String>> nativeHeaders)` A constructor for creating new headers, accepting an optional native header map.
    `protected` | `NativeMessageHeaderAccessor(Message<?> message)` A constructor for accessing and modifying existing message headers.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addNativeHeader(String name, String value)` Add the specified native header value.
    `String` | `getFirstNativeHeader(String headerName)` Return the first value for the specified native header of `null`.
    `List<String>` | `getNativeHeader(String headerName)` Return all values for the specified native header or `null`.
    `boolean` | `isModified()`
    `void` | `setNativeHeader(String name, String value)` Set the specified native header value.
    `Map<String,Object>` | `toMap()` Return a header map including original, wrapped headers (if any) plus additional header updates made through accessor methods.
    `Map<String,List<String>>` | `toNativeHeaderMap()` Return a map with native headers including original, wrapped headers (if any) plus additional header updates made through accessor methods.

    - ### 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

    - #### NATIVE_HEADERS

          public static final String NATIVE_HEADERS

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### NativeMessageHeaderAccessor

          protected NativeMessageHeaderAccessor(Map<String,List<String>> nativeHeaders)

      A constructor for creating new headers, accepting an optional native header map.

    - #### NativeMessageHeaderAccessor

          protected NativeMessageHeaderAccessor(Message<?> message)

      A constructor for accessing and modifying existing message headers.

  - ### Method Detail

    - #### toMap

          public Map<String,Object> toMap()

      Description copied from class: `MessageHeaderAccessor`
      Return a header map including original, wrapped headers (if any) plus additional header updates made through accessor methods.
      Overrides:
        `toMap` in class `MessageHeaderAccessor`

    - #### isModified

          public boolean isModified()

      Overrides:
        `isModified` in class `MessageHeaderAccessor`

    - #### toNativeHeaderMap

          public Map<String,List<String>> toNativeHeaderMap()

      Return a map with native headers including original, wrapped headers (if any) plus additional header updates made through accessor methods.

    - #### getNativeHeader

          public List<String> getNativeHeader(String headerName)

      Return all values for the specified native header or `null`.

    - #### getFirstNativeHeader

          public String getFirstNativeHeader(String headerName)

      Return the first value for the specified native header of `null`.

    - #### setNativeHeader

          public void setNativeHeader(String name,
                                      String value)

      Set the specified native header value.

    - #### addNativeHeader

          public void addNativeHeader(String name,
                                      String value)

      Add the specified native header value.