org.springframework.messaging

## Class MessageHeaders

- java.lang.Object
- - org.springframework.messaging.MessageHeaders

All Implemented Interfaces:
  Serializable, Map<String,Object>

    public class MessageHeaders
    extends Object
    implements Map<String,Object>, Serializable

The headers for a `Message`.

IMPORTANT: This class is immutable. Any mutating operation such as `put(..)`, `putAll(..)` and others will throw `UnsupportedOperationException`.

Subclasses do have access to the raw headers, however, via `getRawHeaders()`.

One way to create message headers is to use the `MessageBuilder`:

     MessageBuilder.withPayload("foo").setHeader("key1", "value1").setHeader("key2", "value2");

A second option is to create `GenericMessage` passing a payload as `Object` and headers as a `java.util.Map`:

     Map headers = new HashMap();
     headers.put("key1", "value1");
     headers.put("key2", "value2");
     new GenericMessage("foo", headers);

A third option is to use `MessageHeaderAccessor` or one of its subclasses to create specific categories of headers.

Since:
  4.0
Author:
  Arjen Poutsma, Mark Fisher, Gary Russell, Juergen Hoeller
See Also:
  `MessageBuilder`, `MessageHeaderAccessor`, Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from interface java.util.Map

`Map.Entry<K,V>`

### Field Summary

Fields
`static String` `CONTENT_TYPE` The key for the message content type.
`static String` `ERROR_CHANNEL` The key for the message error channel.
`static String` `ID` The key for the Message ID.
`static UUID` `ID_VALUE_NONE` UUID for none.
`static String` `REPLY_CHANNEL` The key for the message reply channel.
`static String` `TIMESTAMP` The key for the message timestamp.

### Constructor Summary

Constructors
`` `MessageHeaders(Map<String,Object> headers)` Construct a `MessageHeaders` with the given headers.
`protected` `MessageHeaders(Map<String,Object> headers, UUID id, Long timestamp)` Constructor providing control over the ID and TIMESTAMP header values.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `clear()` Since MessageHeaders are immutable, the call to this method will result in `UnsupportedOperationException`.
`boolean` `containsKey(Object key)`
`boolean` `containsValue(Object value)`
`Set<Map.Entry<String,Object>>` `entrySet()`
`boolean` `equals(Object other)`
`Object` `get(Object key)`
`<T> T` `get(Object key, Class<T> type)`
`Object` `getErrorChannel()`
`UUID` `getId()`
`protected static org.springframework.util.IdGenerator` `getIdGenerator()`
`protected Map<String,Object>` `getRawHeaders()`
`Object` `getReplyChannel()`
`Long` `getTimestamp()`
`int` `hashCode()`
`boolean` `isEmpty()`
`Set<String>` `keySet()`
`Object` `put(String key, Object value)` Since MessageHeaders are immutable, the call to this method will result in `UnsupportedOperationException`.
`void` `putAll(Map<? extends String,? extends Object> map)` Since MessageHeaders are immutable, the call to this method will result in `UnsupportedOperationException`.
`Object` `remove(Object key)` Since MessageHeaders are immutable, the call to this method will result in `UnsupportedOperationException`.
`int` `size()`
`String` `toString()`
`Collection<Object>` `values()`

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

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

### Methods inherited from interface java.util.Map

`compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll`

### Field Detail

#### ID_VALUE_NONE

    public static final UUID ID_VALUE_NONE

UUID for none.

#### ID

    public static final String ID

The key for the Message ID. This is an automatically generated UUID and should never be explicitly set in the header map except in the case of Message deserialization where the serialized Message's generated UUID is being restored.

See Also:
  Constant Field Values

#### TIMESTAMP

    public static final String TIMESTAMP

The key for the message timestamp.

See Also:
  Constant Field Values

#### CONTENT_TYPE

    public static final String CONTENT_TYPE

The key for the message content type.

See Also:
  Constant Field Values

#### REPLY_CHANNEL

    public static final String REPLY_CHANNEL

The key for the message reply channel.

See Also:
  Constant Field Values

#### ERROR_CHANNEL

    public static final String ERROR_CHANNEL

The key for the message error channel.

See Also:
  Constant Field Values

### Constructor Detail

#### MessageHeaders

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

Construct a `MessageHeaders` with the given headers. An `ID` and `TIMESTAMP` headers will also be added, overriding any existing values.

Parameters:
  `headers` - a map with headers to add

#### MessageHeaders

    protected MessageHeaders(@Nullable
                             Map<String,Object> headers,
                             @Nullable
                             UUID id,
                             @Nullable
                             Long timestamp)

Constructor providing control over the ID and TIMESTAMP header values.

Parameters:
  `headers` - a map with headers to add
  `id` - the `ID` header value
  `timestamp` - the `TIMESTAMP` header value

### Method Detail

#### getRawHeaders

    protected Map<String,Object> getRawHeaders()

#### getIdGenerator

    protected static org.springframework.util.IdGenerator getIdGenerator()

#### getId

    @Nullable
    public UUID getId()

#### getTimestamp

    @Nullable
    public Long getTimestamp()

#### getReplyChannel

    @Nullable
    public Object getReplyChannel()

#### getErrorChannel

    @Nullable
    public Object getErrorChannel()

#### get

    @Nullable
    public <T> T get(Object key,
                               Class<T> type)

#### containsKey

    public boolean containsKey(Object key)

Specified by:
  `containsKey` in interface `Map<String,Object>`

#### containsValue

    public boolean containsValue(Object value)

Specified by:
  `containsValue` in interface `Map<String,Object>`

#### entrySet

    public Set<Map.Entry<String,Object>> entrySet()

Specified by:
  `entrySet` in interface `Map<String,Object>`

#### get

    @Nullable
    public Object get(Object key)

Specified by:
  `get` in interface `Map<String,Object>`

#### isEmpty

    public boolean isEmpty()

Specified by:
  `isEmpty` in interface `Map<String,Object>`

#### keySet

    public Set<String> keySet()

Specified by:
  `keySet` in interface `Map<String,Object>`

#### size

    public int size()

Specified by:
  `size` in interface `Map<String,Object>`

#### values

    public Collection<Object> values()

Specified by:
  `values` in interface `Map<String,Object>`

#### put

    public Object put(String key,
                      Object value)

Since MessageHeaders are immutable, the call to this method will result in `UnsupportedOperationException`.

Specified by:
  `put` in interface `Map<String,Object>`

#### putAll

    public void putAll(Map<? extends String,? extends Object> map)

Since MessageHeaders are immutable, the call to this method will result in `UnsupportedOperationException`.

Specified by:
  `putAll` in interface `Map<String,Object>`

#### remove

    public Object remove(Object key)

Since MessageHeaders are immutable, the call to this method will result in `UnsupportedOperationException`.

Specified by:
  `remove` in interface `Map<String,Object>`

#### clear

    public void clear()

Since MessageHeaders are immutable, the call to this method will result in `UnsupportedOperationException`.

Specified by:
  `clear` in interface `Map<String,Object>`

#### equals

    public boolean equals(@Nullable
                          Object other)

Specified by:
  `equals` in interface `Map<String,Object>`
Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Specified by:
  `hashCode` in interface `Map<String,Object>`
Overrides:
  `hashCode` in class `Object`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`