public class MessageHeaders
extends java.lang.Object
implements java.util.Map<java.lang.String,java.lang.Object>, java.io.Serializable
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.MessageBuilder
,
MessageHeaderAccessor
,
Serialized FormModifier and Type | Field and Description |
---|---|
static java.lang.String |
CONTENT_TYPE |
private static IdGenerator |
defaultIdGenerator |
static java.lang.String |
ERROR_CHANNEL |
private java.util.Map<java.lang.String,java.lang.Object> |
headers |
static java.lang.String |
ID
The key for the Message ID.
|
static java.util.UUID |
ID_VALUE_NONE |
private static IdGenerator |
idGenerator |
private static Log |
logger |
static java.lang.String |
REPLY_CHANNEL |
private static long |
serialVersionUID |
static java.lang.String |
TIMESTAMP |
Modifier | Constructor and Description |
---|---|
|
MessageHeaders(java.util.Map<java.lang.String,java.lang.Object> headers)
Construct a
MessageHeaders with the given headers. |
protected |
MessageHeaders(java.util.Map<java.lang.String,java.lang.Object> headers,
java.util.UUID id,
java.lang.Long timestamp)
Constructor providing control over the ID and TIMESTAMP header values.
|
private |
MessageHeaders(MessageHeaders original,
java.util.Set<java.lang.String> keysToIgnore)
Copy constructor which allows for ignoring certain entries.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Since MessageHeaders are immutable, the call to this method
will result in
UnsupportedOperationException . |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> |
entrySet() |
boolean |
equals(java.lang.Object other) |
java.lang.Object |
get(java.lang.Object key) |
<T> T |
get(java.lang.Object key,
java.lang.Class<T> type) |
java.lang.Object |
getErrorChannel() |
java.util.UUID |
getId() |
protected static IdGenerator |
getIdGenerator() |
protected java.util.Map<java.lang.String,java.lang.Object> |
getRawHeaders() |
java.lang.Object |
getReplyChannel() |
java.lang.Long |
getTimestamp() |
int |
hashCode() |
boolean |
isEmpty() |
java.util.Set<java.lang.String> |
keySet() |
java.lang.Object |
put(java.lang.String key,
java.lang.Object value)
Since MessageHeaders are immutable, the call to this method
will result in
UnsupportedOperationException . |
void |
putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> map)
Since MessageHeaders are immutable, the call to this method
will result in
UnsupportedOperationException . |
private void |
readObject(java.io.ObjectInputStream in) |
java.lang.Object |
remove(java.lang.Object key)
Since MessageHeaders are immutable, the call to this method
will result in
UnsupportedOperationException . |
int |
size() |
java.lang.String |
toString() |
java.util.Collection<java.lang.Object> |
values() |
private void |
writeObject(java.io.ObjectOutputStream out) |
public static final java.util.UUID ID_VALUE_NONE
public static final java.lang.String ID
public static final java.lang.String TIMESTAMP
public static final java.lang.String CONTENT_TYPE
public static final java.lang.String REPLY_CHANNEL
public static final java.lang.String ERROR_CHANNEL
private static final long serialVersionUID
private static final Log logger
private static final IdGenerator defaultIdGenerator
private static volatile IdGenerator idGenerator
private final java.util.Map<java.lang.String,java.lang.Object> headers
public MessageHeaders(java.util.Map<java.lang.String,java.lang.Object> headers)
MessageHeaders
with the given headers. An ID
and
TIMESTAMP
headers will also be added, overriding any existing values.headers
- a map with headers to addprotected MessageHeaders(java.util.Map<java.lang.String,java.lang.Object> headers, java.util.UUID id, java.lang.Long timestamp)
private MessageHeaders(MessageHeaders original, java.util.Set<java.lang.String> keysToIgnore)
original
- the MessageHeaders to copykeysToIgnore
- the keys of the entries to ignoreprotected java.util.Map<java.lang.String,java.lang.Object> getRawHeaders()
protected static IdGenerator getIdGenerator()
public java.util.UUID getId()
public java.lang.Long getTimestamp()
public java.lang.Object getReplyChannel()
public java.lang.Object getErrorChannel()
public <T> T get(java.lang.Object key, java.lang.Class<T> type)
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<java.lang.String,java.lang.Object>
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<java.lang.String,java.lang.Object>
public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
entrySet
in interface java.util.Map<java.lang.String,java.lang.Object>
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map<java.lang.String,java.lang.Object>
public boolean isEmpty()
isEmpty
in interface java.util.Map<java.lang.String,java.lang.Object>
public java.util.Set<java.lang.String> keySet()
keySet
in interface java.util.Map<java.lang.String,java.lang.Object>
public int size()
size
in interface java.util.Map<java.lang.String,java.lang.Object>
public java.util.Collection<java.lang.Object> values()
values
in interface java.util.Map<java.lang.String,java.lang.Object>
public java.lang.Object put(java.lang.String key, java.lang.Object value)
UnsupportedOperationException
.put
in interface java.util.Map<java.lang.String,java.lang.Object>
public void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> map)
UnsupportedOperationException
.putAll
in interface java.util.Map<java.lang.String,java.lang.Object>
public java.lang.Object remove(java.lang.Object key)
UnsupportedOperationException
.remove
in interface java.util.Map<java.lang.String,java.lang.Object>
public void clear()
UnsupportedOperationException
.clear
in interface java.util.Map<java.lang.String,java.lang.Object>
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
java.io.IOException
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
public boolean equals(java.lang.Object other)
equals
in interface java.util.Map<java.lang.String,java.lang.Object>
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.util.Map<java.lang.String,java.lang.Object>
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object