org.springframework.messaging.support

## Class MessageHeaderAccessor

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

- Direct Known Subclasses:
    NativeMessageHeaderAccessor

      public class MessageHeaderAccessor
      extends Object

  A base class for read/write access to `MessageHeaders`. Supports creation of new headers or modification of existing message headers.

  Sub-classes can provide additional typed getters and setters for convenient access to specific headers. Getters and setters should delegate to `getHeader(String)` or `setHeader(String, Object)` respectively. At the end `toMap()` can be used to obtain the resulting headers.

  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Log` | `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MessageHeaderAccessor()` A constructor for creating new message headers.
    `MessageHeaderAccessor(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` | `copyHeaders(Map<String,?> headersToCopy)` Copy the name-value pairs from the provided Map.
    `void` | `copyHeadersIfAbsent(Map<String,?> headersToCopy)` Copy the name-value pairs from the provided Map.
    `MimeType` | `getContentType()`
    `Object` | `getErrorChannel()`
    `Object` | `getHeader(String headerName)`
    `UUID` | `getId()`
    `Object` | `getReplyChannel()`
    `Long` | `getTimestamp()`
    `boolean` | `isModified()`
    `protected boolean` | `isReadOnly(String headerName)`
    `void` | `removeHeader(String headerName)` Remove the value for the given header name.
    `void` | `removeHeaders(String... headerPatterns)` Removes all headers provided via array of 'headerPatterns'.
    `void` | `setContentType(MimeType contentType)`
    `void` | `setErrorChannel(MessageChannel errorChannel)`
    `void` | `setErrorChannelName(String errorChannelName)`
    `void` | `setHeader(String name, Object value)` Set the value for the given header name.
    `void` | `setHeaderIfAbsent(String name, Object value)` Set the value for the given header name only if the header name is not already associated with a value.
    `void` | `setReplyChannel(MessageChannel replyChannel)`
    `void` | `setReplyChannelName(String replyChannelName)`
    `Map<String,Object>` | `toMap()` Return a header map including original, wrapped headers (if any) plus additional header updates made through accessor methods.
    `String` | `toString()`
    `protected void` | `verifyType(String headerName, Object headerValue)`

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

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

- - ### Field Detail

    - #### logger

          protected Log logger

  - ### Constructor Detail

    - #### MessageHeaderAccessor

          public MessageHeaderAccessor()

      A constructor for creating new message headers.

    - #### MessageHeaderAccessor

          public MessageHeaderAccessor(Message<?> message)

      A constructor for accessing and modifying existing message headers.

  - ### Method Detail

    - #### toMap

          public Map<String,Object> toMap()

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

    - #### isModified

          public boolean isModified()

    - #### getHeader

          public Object getHeader(String headerName)

    - #### setHeader

          public void setHeader(String name,
                                Object value)

      Set the value for the given header name. If the provided value is `null` the header will be removed.

    - #### isReadOnly

          protected boolean isReadOnly(String headerName)

    - #### setHeaderIfAbsent

          public void setHeaderIfAbsent(String name,
                                        Object value)

      Set the value for the given header name only if the header name is not already associated with a value.

    - #### removeHeaders

          public void removeHeaders(String... headerPatterns)

      Removes all headers provided via array of 'headerPatterns'. As the name suggests the array may contain simple matching patterns for header names. Supported pattern styles are: "xxx*", "*xxx", "*xxx*" and "xxx*yyy".

    - #### removeHeader

          public void removeHeader(String headerName)

      Remove the value for the given header name.

    - #### copyHeaders

          public void copyHeaders(Map<String,?> headersToCopy)

      Copy the name-value pairs from the provided Map. This operation will overwrite any existing values. Use { `copyHeadersIfAbsent(Map)` to avoid overwriting values.

    - #### copyHeadersIfAbsent

          public void copyHeadersIfAbsent(Map<String,?> headersToCopy)

      Copy the name-value pairs from the provided Map. This operation will not overwrite any existing values.

    - #### getId

          public UUID getId()

    - #### getTimestamp

          public Long getTimestamp()

    - #### setReplyChannel

          public void setReplyChannel(MessageChannel replyChannel)

    - #### getReplyChannel

          public Object getReplyChannel()

    - #### setReplyChannelName

          public void setReplyChannelName(String replyChannelName)

    - #### setErrorChannel

          public void setErrorChannel(MessageChannel errorChannel)

    - #### getErrorChannel

          public Object getErrorChannel()

    - #### setErrorChannelName

          public void setErrorChannelName(String errorChannelName)

    - #### getContentType

          public MimeType getContentType()

    - #### setContentType

          public void setContentType(MimeType contentType)

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### verifyType

          protected void verifyType(String headerName,
                                    Object headerValue)