public class MessageHeaderAccessor extends Object
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.
Constructor and Description |
---|
MessageHeaderAccessor()
A constructor for creating new message headers.
|
MessageHeaderAccessor(Message<?> message)
A constructor for accessing and modifying existing message headers.
|
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) |
protected final Log logger
public MessageHeaderAccessor()
public MessageHeaderAccessor(Message<?> message)
public Map<String,Object> toMap()
public boolean isModified()
public void setHeader(String name, Object value)
If the provided value is null
, the header will be removed.
public void setHeaderIfAbsent(String name, Object value)
public void removeHeader(String headerName)
public void removeHeaders(String... headerPatterns)
As the name suggests, array may contain simple matching patterns for header names. Supported pattern styles are: "xxx*", "*xxx", "*xxx*" and "xxx*yyy".
public void copyHeaders(Map<String,?> headersToCopy)
This operation will overwrite any existing values. Use
copyHeadersIfAbsent(Map)
to avoid overwriting values.
public void copyHeadersIfAbsent(Map<String,?> headersToCopy)
This operation will not overwrite any existing values.
protected boolean isReadOnly(String headerName)
public UUID getId()
public Long getTimestamp()
public void setReplyChannelName(String replyChannelName)
public void setReplyChannel(MessageChannel replyChannel)
public Object getReplyChannel()
public void setErrorChannelName(String errorChannelName)
public void setErrorChannel(MessageChannel errorChannel)
public Object getErrorChannel()
public void setContentType(MimeType contentType)
public MimeType getContentType()