public class NativeMessageHeaderAccessor extends MessageHeaderAccessor
MessageHeaderAccessor
sub-class that supports storage and access of
headers from an external source such as a message broker. Headers from the
external source are kept separate from other headers, in a sub-map under the
key NATIVE_HEADERS
. This allows separating processing headers from
headers that need to be sent to or received from the external source.
This class is likely to be used through indirectly through a protocol specific sub-class that also provide factory methods to translate message headers to an from an external messaging source.
Modifier and Type | Field and Description |
---|---|
static String |
NATIVE_HEADERS
The header name used to store native headers.
|
DEFAULT_CHARSET
Modifier | Constructor and Description |
---|---|
protected |
NativeMessageHeaderAccessor()
Protected constructor to create a new instance.
|
protected |
NativeMessageHeaderAccessor(Map<String,List<String>> nativeHeaders)
Protected constructor to create an instance with the given native headers.
|
protected |
NativeMessageHeaderAccessor(Message<?> message)
Protected constructor that copies headers from another message.
|
Modifier and Type | Method and Description |
---|---|
void |
addNativeHeader(String name,
String value)
Add the specified native header value to existing values.
|
void |
addNativeHeaders(MultiValueMap<String,String> headers)
Add the specified native headers to existing values.
|
boolean |
containsNativeHeader(String headerName)
Whether the native header map contains the give header name.
|
void |
copyHeaders(Map<String,?> headersToCopy)
Copy the name-value pairs from the provided Map.
|
String |
getFirstNativeHeader(String headerName)
Return the first value for the specified native header, if present.
|
static String |
getFirstNativeHeader(String headerName,
Map<String,Object> headers)
Return the first value for the specified native header,
or
null if none. |
List<String> |
getNativeHeader(String headerName)
Return all values for the specified native header, if present.
|
protected Map<String,List<String>> |
getNativeHeaders()
Subclasses can use this method to access the "native" headers sub-map.
|
List<String> |
removeNativeHeader(String headerName)
Remove the specified native header value replacing existing values.
|
void |
setHeader(String name,
Object value)
Set the value for the given header name.
|
void |
setImmutable()
By default when
MessageHeaderAccessor.getMessageHeaders() is called, "this"
MessageHeaderAccessor instance can no longer be used to modify the
underlying message headers. |
void |
setNativeHeader(String name,
String value)
Set the specified native header value replacing existing values.
|
Map<String,List<String>> |
toNativeHeaderMap()
Return a copy of the native headers sub-map, or an empty map.
|
copyHeadersIfAbsent, createAccessor, getAccessor, getAccessor, getAccessor, getContentType, getDetailedLogMessage, getDetailedPayloadLogMessage, getErrorChannel, getHeader, getId, getMessageHeaders, getMutableAccessor, getReplyChannel, getShortLogMessage, getShortPayloadLogMessage, getTimestamp, isModified, isMutable, isReadableContentType, isReadOnly, removeHeader, removeHeaders, setContentType, setErrorChannel, setErrorChannelName, setHeaderIfAbsent, setLeaveMutable, setModified, setReplyChannel, setReplyChannelName, toMap, toMessageHeaders, toString, verifyType
public static final String NATIVE_HEADERS
protected NativeMessageHeaderAccessor()
protected NativeMessageHeaderAccessor(@Nullable Map<String,List<String>> nativeHeaders)
nativeHeaders
- native headers to create the message with (may be null
)@Nullable protected Map<String,List<String>> getNativeHeaders()
public Map<String,List<String>> toNativeHeaderMap()
public void setImmutable()
MessageHeaderAccessor
MessageHeaderAccessor.getMessageHeaders()
is called, "this"
MessageHeaderAccessor
instance can no longer be used to modify the
underlying message headers. However if MessageHeaderAccessor.setLeaveMutable(boolean)
is used, this method is necessary to indicate explicitly when the
MessageHeaders
instance should no longer be modified.setImmutable
in class MessageHeaderAccessor
public void setHeader(String name, @Nullable Object value)
MessageHeaderAccessor
If the provided value is null
, the header will be removed.
setHeader
in class MessageHeaderAccessor
public void copyHeaders(@Nullable Map<String,?> headersToCopy)
MessageHeaderAccessor
This operation will overwrite any existing values. Use
MessageHeaderAccessor.copyHeadersIfAbsent(Map)
to avoid overwriting values.
copyHeaders
in class MessageHeaderAccessor
public boolean containsNativeHeader(String headerName)
headerName
- the name of the header@Nullable public List<String> getNativeHeader(String headerName)
headerName
- the name of the headernull
if none@Nullable public String getFirstNativeHeader(String headerName)
headerName
- the name of the headernull
if nonepublic void setNativeHeader(String name, @Nullable String value)
In order for this to work, the accessor must be mutable
. See MessageHeaderAccessor
for details.
public void addNativeHeader(String name, @Nullable String value)
In order for this to work, the accessor must be mutable
. See MessageHeaderAccessor
for details.
name
- the name of the headervalue
- the header value to setpublic void addNativeHeaders(@Nullable MultiValueMap<String,String> headers)
headers
- the headers to set@Nullable public List<String> removeNativeHeader(String headerName)
In order for this to work, the accessor must be mutable
. See MessageHeaderAccessor
for details.
headerName
- the name of the headernull
if the header was not present@Nullable public static String getFirstNativeHeader(String headerName, Map<String,Object> headers)
null
if none.headerName
- the name of the headerheaders
- the headers map to introspectnull
if none