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 Log logger
public MessageHeaderAccessor()
public MessageHeaderAccessor(Message<?> message)
public Map<String,Object> toMap()
public boolean isModified()
public void setHeader(String name, Object value)
null
the
header will be removed.protected boolean isReadOnly(String headerName)
public void setHeaderIfAbsent(String name, Object value)
public void removeHeaders(String... headerPatterns)
public void removeHeader(String headerName)
public void copyHeaders(Map<String,?> headersToCopy)
copyHeadersIfAbsent(Map)
to avoid overwriting
values.public void copyHeadersIfAbsent(Map<String,?> headersToCopy)
public UUID getId()
public Long getTimestamp()
public void setReplyChannel(MessageChannel replyChannel)
public Object getReplyChannel()
public void setReplyChannelName(String replyChannelName)
public void setErrorChannel(MessageChannel errorChannel)
public Object getErrorChannel()
public void setErrorChannelName(String errorChannelName)
public MimeType getContentType()
public void setContentType(MimeType contentType)