public class NativeMessageHeaderAccessor extends MessageHeaderAccessor
MessageHeaderAccessor
that also stores and provides read/write
access to message headers from an external source -- e.g. a Spring Message
created to represent a STOMP message received from a STOMP client or message broker.
Native message headers are kept in a Map<String, List<String>>
under the key
NATIVE_HEADERS
.
This class is not intended for direct use but is rather expected to be used
indirectly through protocol-specific sub-classes such as
StompHeaderAccessor
.
Such sub-classes may provide factory methods to translate message headers from
an external messaging source (e.g. STOMP) to Spring Message
headers and
reversely to translate Spring Message
headers to a message to send to an
external source.
Modifier and Type | Field and Description |
---|---|
static String |
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.
|
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.
|
List<String> |
removeNativeHeader(String headerName)
Remove the specified native header value replacing existing values.
|
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.
|
copyHeaders, copyHeadersIfAbsent, createAccessor, getAccessor, getAccessor, getContentType, getDetailedLogMessage, getDetailedPayloadLogMessage, getErrorChannel, getHeader, getId, getMessageHeaders, getMutableAccessor, getReplyChannel, getShortLogMessage, getShortPayloadLogMessage, getTimestamp, isModified, isMutable, isReadableContentType, isReadOnly, removeHeader, removeHeaders, setContentType, setErrorChannel, setErrorChannelName, setHeader, setHeaderIfAbsent, setLeaveMutable, setModified, setReplyChannel, setReplyChannelName, toMap, toMessageHeaders, toString, verifyType
public static final String NATIVE_HEADERS
protected NativeMessageHeaderAccessor()
protected NativeMessageHeaderAccessor(Map<String,List<String>> nativeHeaders)
nativeHeaders
- native headers to create the message with (may be null
)protected NativeMessageHeaderAccessor(Message<?> message)
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 boolean containsNativeHeader(String headerName)
headerName
- the name of the headerpublic List<String> getNativeHeader(String headerName)
headerName
- the name of the headernull
if nonepublic String getFirstNativeHeader(String headerName)
headerName
- the name of the headernull
if nonepublic void setNativeHeader(String name, String value)
In order for this to work, the accessor must be mutable
. See MessageHeaderAccessor
for details.
public void addNativeHeader(String name, 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(MultiValueMap<String,String> headers)
headers
- the headers to setpublic 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 presentpublic 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