类 NativeMessageHeaderAccessor
- java.lang.Object
- org.springframework.messaging.support.MessageHeaderAccessor
- org.springframework.messaging.support.NativeMessageHeaderAccessor
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 keyNATIVE_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.
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
字段概要
字段 修饰符和类型 字段 说明 static String
NATIVE_HEADERS
The header name used to store native headers.从类继承的字段 org.springframework.messaging.support.MessageHeaderAccessor
DEFAULT_CHARSET
构造器概要
构造器 限定符 构造器 说明 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.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 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.void
copyHeadersIfAbsent(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, ornull
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
setImmutable()
By default whenMessageHeaderAccessor.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.void
setNativeHeaderValues(String name, List<String> values)
Variant ofaddNativeHeader(String, String)
for all values.Map<String,List<String>>
toNativeHeaderMap()
Return a copy of the native headers sub-map, or an empty map.从类继承的方法 org.springframework.messaging.support.MessageHeaderAccessor
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, setHeader, setHeaderIfAbsent, setLeaveMutable, setModified, setReplyChannel, setReplyChannelName, toMap, toMessageHeaders, toString, verifyType
字段详细资料
NATIVE_HEADERS
public static final String NATIVE_HEADERS
The header name used to store native headers.- 另请参阅:
- 常量字段值
构造器详细资料
NativeMessageHeaderAccessor
protected NativeMessageHeaderAccessor()
Protected constructor to create a new instance.
NativeMessageHeaderAccessor
protected NativeMessageHeaderAccessor(@Nullable Map<String,List<String>> nativeHeaders)
Protected constructor to create an instance with the given native headers.- 参数:
nativeHeaders
- native headers to create the message with (may benull
)
NativeMessageHeaderAccessor
protected NativeMessageHeaderAccessor(@Nullable Message<?> message)
Protected constructor that copies headers from another message.
方法详细资料
getNativeHeaders
@Nullable protected Map<String,List<String>> getNativeHeaders()
Subclasses can use this method to access the "native" headers sub-map.
toNativeHeaderMap
public Map<String,List<String>> toNativeHeaderMap()
Return a copy of the native headers sub-map, or an empty map.
setImmutable
public void setImmutable()
从类复制的说明:MessageHeaderAccessor
By default whenMessageHeaderAccessor.getMessageHeaders()
is called,"this"
MessageHeaderAccessor
instance 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 theMessageHeaders
instance should no longer be modified.
copyHeaders
public void copyHeaders(@Nullable Map<String,?> headersToCopy)
从类复制的说明:MessageHeaderAccessor
Copy the name-value pairs from the provided Map.This operation will overwrite any existing values. Use
MessageHeaderAccessor.copyHeadersIfAbsent(Map)
to avoid overwriting values.- 覆盖:
copyHeaders
在类中MessageHeaderAccessor
copyHeadersIfAbsent
public void copyHeadersIfAbsent(@Nullable Map<String,?> headersToCopy)
从类复制的说明:MessageHeaderAccessor
Copy the name-value pairs from the provided Map.This operation will not overwrite any existing values.
containsNativeHeader
public boolean containsNativeHeader(String headerName)
Whether the native header map contains the give header name.- 参数:
headerName
- the name of the header
getNativeHeader
@Nullable public List<String> getNativeHeader(String headerName)
Return all values for the specified native header, if present.- 参数:
headerName
- the name of the header- 返回:
- the associated values, or
null
if none
getFirstNativeHeader
@Nullable public String getFirstNativeHeader(String headerName)
Return the first value for the specified native header, if present.- 参数:
headerName
- the name of the header- 返回:
- the associated value, or
null
if none
setNativeHeader
public void setNativeHeader(String name, @Nullable String value)
Set the specified native header value replacing existing values.In order for this to work, the accessor must be
mutable
. SeeMessageHeaderAccessor
for details.
setNativeHeaderValues
public void setNativeHeaderValues(String name, @Nullable List<String> values)
Variant ofaddNativeHeader(String, String)
for all values.- 从以下版本开始:
- 5.2.12
addNativeHeader
public void addNativeHeader(String name, @Nullable String value)
Add the specified native header value to existing values.In order for this to work, the accessor must be
mutable
. SeeMessageHeaderAccessor
for details.- 参数:
name
- the name of the headervalue
- the header value to set
addNativeHeaders
public void addNativeHeaders(@Nullable MultiValueMap<String,String> headers)
Add the specified native headers to existing values.- 参数:
headers
- the headers to set
removeNativeHeader
@Nullable 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
. SeeMessageHeaderAccessor
for details.- 参数:
headerName
- the name of the header- 返回:
- the associated values, or
null
if the header was not present
getFirstNativeHeader
@Nullable public static String getFirstNativeHeader(String headerName, Map<String,Object> headers)
Return the first value for the specified native header, ornull
if none.- 参数:
headerName
- the name of the headerheaders
- the headers map to introspect- 返回:
- the associated value, or
null
if none