Top Description Fields Constructors Methods
org.springframework.messaging.support

public Class NativeMessageHeaderAccessor

extends MessageHeaderAccessor
Class Inheritance
Known Direct Subclasses
org.springframework.messaging.simp.SimpMessageHeaderAccessor
Imports
java.util.ArrayList, .Collections, .List, .Map, org.springframework.lang.Nullable, org.springframework.messaging.Message, org.springframework.util.Assert, .CollectionUtils, .LinkedMultiValueMap, .MultiValueMap, .ObjectUtils

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.

Author
Rossen Stoyanchev
Since
4.0

Field Summary

Modifier and TypeField and Description
public static final String
NATIVE_HEADERS

The header name used to store native headers.

Inherited from org.springframework.messaging.support.MessageHeaderAccessor:
DEFAULT_CHARSET

Constructor Summary

AccessConstructor and Description
protected
NativeMessageHeaderAccessor()

Protected constructor to create a new instance.

protected
NativeMessageHeaderAccessor(Map<String, List<String>>
native headers to create the message with (may be null)
nativeHeaders
)

Protected constructor to create an instance with the given native headers.

protected
NativeMessageHeaderAccessor(Message<?> message)

Protected constructor that copies headers from another message.

Method Summary

Modifier and TypeMethod and Description
public void
addNativeHeader(String
the name of the header
name
,
String
the header value to set
value
)

Add the specified native header value to existing values.

public void
addNativeHeaders(MultiValueMap<String, String>
the headers to set
headers
)

Add the specified native headers to existing values.

public boolean
containsNativeHeader(String
the name of the header
headerName
)

Whether the native header map contains the give header name.

public void
copyHeaders(Map<String, ?> headersToCopy)

Overrides org.springframework.messaging.support.MessageHeaderAccessor.copyHeaders.

Copy the name-value pairs from the provided Map.

public void
copyHeadersIfAbsent(Map<String, ?> headersToCopy)

Overrides org.springframework.messaging.support.MessageHeaderAccessor.copyHeadersIfAbsent.

Copy the name-value pairs from the provided Map.

public String

Returns:

the associated value, or null if none
getFirstNativeHeader
(String
the name of the header
headerName
)

Return the first value for the specified native header, if present.

public static String

Returns:

the associated value, or null if none
getFirstNativeHeader
(String
the name of the header
headerName
,
Map<String, Object>
the headers map to introspect
headers
)

Return the first value for the specified native header, or null if none.

public List<String>

Returns:

the associated values, or null if none
getNativeHeader
(String
the name of the header
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.

public List<String>

Returns:

the associated values, or null if the header was not present
removeNativeHeader
(String
the name of the header
headerName
)

Remove the specified native header value replacing existing values.

public void
setImmutable()

Overrides org.springframework.messaging.support.MessageHeaderAccessor.setImmutable.

By default, when getMessageHeaders() is called, "this" MessageHeaderAccessor instance can no longer be used to modify the underlying message headers.

public void
setNativeHeader(String name, String value)

Set the specified native header value replacing existing values.

public void
setNativeHeaderValues(String name, List<String> values)

Variant of addNativeHeader(String, String) for all values.

public Map<String, List<String>>
toNativeHeaderMap()

Return a copy of the native headers sub-map, or an empty map.

Inherited from org.springframework.messaging.support.MessageHeaderAccessor:
createAccessorgetAccessorgetAccessorgetAccessorgetContentTypegetDetailedLogMessagegetDetailedPayloadLogMessagegetErrorChannelgetHeadergetIdgetMessageHeadersgetMutableAccessorgetReplyChannelgetShortLogMessagegetShortPayloadLogMessagegetTimestampisModifiedisMutableisReadableContentTypeisReadOnlyremoveHeaderremoveHeaderssetContentTypesetEnableTimestampsetErrorChannelsetErrorChannelNamesetHeadersetHeaderIfAbsentsetIdGeneratorsetLeaveMutablesetModifiedsetReplyChannelsetReplyChannelNametoMaptoMessageHeaderstoStringverifyType

Field Detail

NATIVE_HEADERSback to summary
public static final String NATIVE_HEADERS

The header name used to store native headers.

Constructor Detail

NativeMessageHeaderAccessorback to summary
protected NativeMessageHeaderAccessor()

Protected constructor to create a new instance.

NativeMessageHeaderAccessorback to summary
protected NativeMessageHeaderAccessor(Map<String, List<String>> nativeHeaders)

Protected constructor to create an instance with the given native headers.

Parameters
nativeHeaders:Map<String, List<String>>

native headers to create the message with (may be null)

NativeMessageHeaderAccessorback to summary
protected NativeMessageHeaderAccessor(Message<?> message)

Protected constructor that copies headers from another message.

Method Detail

addNativeHeaderback to summary
public void addNativeHeader(String name, String value)

Add the specified native header value to existing values.

In order for this to work, the accessor must be mutable. See MessageHeaderAccessor for details.

Parameters
name:String

the name of the header

value:String

the header value to set

addNativeHeadersback to summary
public void addNativeHeaders(MultiValueMap<String, String> headers)

Add the specified native headers to existing values.

Parameters
headers:MultiValueMap<String, String>

the headers to set

containsNativeHeaderback to summary
public boolean containsNativeHeader(String headerName)

Whether the native header map contains the give header name.

Parameters
headerName:String

the name of the header

copyHeadersback to summary
public void copyHeaders(Map<String, ?> headersToCopy)

Overrides org.springframework.messaging.support.MessageHeaderAccessor.copyHeaders.

Doc from org.springframework.messaging.support.MessageHeaderAccessor.copyHeaders.

Copy the name-value pairs from the provided Map.

This operation will overwrite any existing values. Use copyHeadersIfAbsent(Map) to avoid overwriting values.

Annotations
@Override
copyHeadersIfAbsentback to summary
public void copyHeadersIfAbsent(Map<String, ?> headersToCopy)

Overrides org.springframework.messaging.support.MessageHeaderAccessor.copyHeadersIfAbsent.

Doc from org.springframework.messaging.support.MessageHeaderAccessor.copyHeadersIfAbsent.

Copy the name-value pairs from the provided Map.

This operation will not overwrite any existing values.

Annotations
@Override
getFirstNativeHeaderback to summary
public String getFirstNativeHeader(String headerName)

Return the first value for the specified native header, if present.

Parameters
headerName:String

the name of the header

Returns:String

the associated value, or null if none

Annotations
@Nullable
getFirstNativeHeaderback to summary
public static String getFirstNativeHeader(String headerName, Map<String, Object> headers)

Return the first value for the specified native header, or null if none.

Parameters
headerName:String

the name of the header

headers:Map<String, Object>

the headers map to introspect

Returns:String

the associated value, or null if none

Annotations
@SuppressWarnings:unchecked
@Nullable
getNativeHeaderback to summary
public List<String> getNativeHeader(String headerName)

Return all values for the specified native header, if present.

Parameters
headerName:String

the name of the header

Returns:List<String>

the associated values, or null if none

Annotations
@Nullable
getNativeHeadersback to summary
protected Map<String, List<String>> getNativeHeaders()

Subclasses can use this method to access the "native" headers sub-map.

Annotations
@SuppressWarnings:unchecked
@Nullable
removeNativeHeaderback to summary
public List<String> removeNativeHeader(String headerName)

Remove the specified native header value replacing existing values.

In order for this to work, the accessor must be mutable. See MessageHeaderAccessor for details.

Parameters
headerName:String

the name of the header

Returns:List<String>

the associated values, or null if the header was not present

Annotations
@Nullable
setImmutableback to summary
public void setImmutable()

Overrides org.springframework.messaging.support.MessageHeaderAccessor.setImmutable.

Doc from org.springframework.messaging.support.MessageHeaderAccessor.setImmutable.

By default, when getMessageHeaders() is called, "this" MessageHeaderAccessor instance can no longer be used to modify the underlying message headers. However if setLeaveMutable(boolean) is used, this method is necessary to indicate explicitly when the MessageHeaders instance should no longer be modified.

Annotations
@Override
setNativeHeaderback to summary
public void setNativeHeader(String name, String value)

Set the specified native header value replacing existing values.

In order for this to work, the accessor must be mutable. See MessageHeaderAccessor for details.

setNativeHeaderValuesback to summary
public void setNativeHeaderValues(String name, List<String> values)

Variant of addNativeHeader(String, String) for all values.

Since
5.2.12
toNativeHeaderMapback to summary
public Map<String, List<String>> toNativeHeaderMap()

Return a copy of the native headers sub-map, or an empty map.