类 NativeMessageHeaderAccessor
- java.lang.Object
- org.springframework.messaging.support.MessageHeaderAccessor
- org.springframework.messaging.support.NativeMessageHeaderAccessor
public class NativeMessageHeaderAccessor extends MessageHeaderAccessor
An extension ofMessageHeaderAccessor
that also stores and provides read/write access to message headers from an external source -- e.g. a SpringMessage
created to represent a STOMP message received from a STOMP client or message broker. Native message headers are kept in aMap<String, List<String>>
under the keyNATIVE_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 SpringMessage
headers and reversely to translate SpringMessage
headers to a message to send to an external source.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
字段概要
字段 修饰符和类型 字段 说明 static String
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.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.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.Map<String,List<String>>
toNativeHeaderMap()
Return a copy of the native headers sub-map, or an empty map.从类继承的方法 org.springframework.messaging.support.MessageHeaderAccessor
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
字段详细资料
NATIVE_HEADERS
public static final String NATIVE_HEADERS
- 另请参阅:
- 常量字段值
构造器详细资料
NativeMessageHeaderAccessor
protected NativeMessageHeaderAccessor()
Protected constructor to create a new instance.
NativeMessageHeaderAccessor
protected NativeMessageHeaderAccessor(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(Message<?> message)
Protected constructor that copies headers from another message.
方法详细资料
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.
containsNativeHeader
public boolean containsNativeHeader(String headerName)
Whether the native header map contains the give header name.- 参数:
headerName
- the name of the header
getNativeHeader
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
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, 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.
addNativeHeader
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
. SeeMessageHeaderAccessor
for details.- 参数:
name
- the name of the headervalue
- the header value to set
addNativeHeaders
public void addNativeHeaders(MultiValueMap<String,String> headers)
Add the specified native headers to existing values.- 参数:
headers
- the headers to set
removeNativeHeader
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