Class NativeMessageHeaderAccessor
java.lang.Object
org.springframework.messaging.support.MessageHeaderAccessor
org.springframework.messaging.support.NativeMessageHeaderAccessor
- Direct Known Subclasses:
- JmsMessageHeaderAccessor,- SimpMessageHeaderAccessor
MessageHeaderAccessor subclass 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 indirectly through a protocol-specific subclass that also provides factory methods to translate message headers to and from an external messaging source.
- Since:
- 4.0
- Author:
- Rossen Stoyanchev
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringThe header name used to store native headers.Fields inherited from class org.springframework.messaging.support.MessageHeaderAccessorDEFAULT_CHARSET
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedProtected constructor to create a new instance.protectedProtected constructor to create an instance with the given native headers.protectedNativeMessageHeaderAccessor(@Nullable Message<?> message) Protected constructor that copies headers from another message.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddNativeHeader(String name, @Nullable String value) Add the specified native header value to existing values.voidaddNativeHeaders(@Nullable MultiValueMap<String, String> headers) Add the specified native headers to existing values.booleancontainsNativeHeader(String headerName) Whether the native header map contains the give header name.voidcopyHeaders(@Nullable Map<String, ?> headersToCopy) Copy the name-value pairs from the provided Map.voidcopyHeadersIfAbsent(@Nullable Map<String, ?> headersToCopy) Copy the name-value pairs from the provided Map.getFirstNativeHeader(String headerName) Return the first value for the specified native header, if present.getFirstNativeHeader(String headerName, Map<String, Object> headers) Return the first value for the specified native header, ornullif none.getNativeHeader(String headerName) Return all values for the specified native header, if present.Subclasses can use this method to access the "native" headers sub-map.removeNativeHeader(String headerName) Remove the specified native header value replacing existing values.voidBy default, whenMessageHeaderAccessor.getMessageHeaders()is called,"this"MessageHeaderAccessorinstance can no longer be used to modify the underlying message headers.voidsetNativeHeader(String name, @Nullable String value) Set the specified native header value replacing existing values.voidsetNativeHeaderValues(String name, @Nullable List<String> values) Variant ofaddNativeHeader(String, String)for all values.Return a copy of the native headers sub-map, or an empty map.Methods inherited from class org.springframework.messaging.support.MessageHeaderAccessorcreateAccessor, fromMap, fromMessageHeaders, getAccessor, 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
- 
Field Details- 
NATIVE_HEADERS
 
- 
- 
Constructor Details- 
NativeMessageHeaderAccessorprotected NativeMessageHeaderAccessor()Protected constructor to create a new instance.
- 
NativeMessageHeaderAccessor
- 
NativeMessageHeaderAccessor
 
- 
- 
Method Details- 
getNativeHeaders
- 
toNativeHeaderMap
- 
setImmutablepublic void setImmutable()Description copied from class:MessageHeaderAccessorBy default, whenMessageHeaderAccessor.getMessageHeaders()is called,"this"MessageHeaderAccessorinstance can no longer be used to modify the underlying message headers. However ifMessageHeaderAccessor.setLeaveMutable(boolean)is used, this method is necessary to indicate explicitly when theMessageHeadersinstance should no longer be modified.- Overrides:
- setImmutablein class- MessageHeaderAccessor
 
- 
copyHeadersDescription copied from class:MessageHeaderAccessorCopy the name-value pairs from the provided Map.This operation will overwrite any existing values. Use MessageHeaderAccessor.copyHeadersIfAbsent(Map)to avoid overwriting values.- Overrides:
- copyHeadersin class- MessageHeaderAccessor
 
- 
copyHeadersIfAbsentDescription copied from class:MessageHeaderAccessorCopy the name-value pairs from the provided Map.This operation will not overwrite any existing values. - Overrides:
- copyHeadersIfAbsentin class- MessageHeaderAccessor
 
- 
containsNativeHeaderWhether the native header map contains the give header name.- Parameters:
- headerName- the name of the header
 
- 
getNativeHeader
- 
getFirstNativeHeader
- 
setNativeHeaderSet the specified native header value replacing existing values.In order for this to work, the accessor must be mutable. SeeMessageHeaderAccessorfor details.
- 
setNativeHeaderValuesVariant ofaddNativeHeader(String, String)for all values.- Since:
- 5.2.12
 
- 
addNativeHeaderAdd the specified native header value to existing values.In order for this to work, the accessor must be mutable. SeeMessageHeaderAccessorfor details.- Parameters:
- name- the name of the header
- value- the header value to set
 
- 
addNativeHeadersAdd the specified native headers to existing values.- Parameters:
- headers- the headers to set
 
- 
removeNativeHeaderRemove the specified native header value replacing existing values.In order for this to work, the accessor must be mutable. SeeMessageHeaderAccessorfor details.- Parameters:
- headerName- the name of the header
- Returns:
- the associated values, or nullif the header was not present
 
- 
getFirstNativeHeaderReturn the first value for the specified native header, ornullif none.- Parameters:
- headerName- the name of the header
- headers- the headers map to introspect
- Returns:
- the associated value, or nullif none
 
 
-