类 SimpMessageHeaderAccessor
- java.lang.Object
- org.springframework.messaging.support.MessageHeaderAccessor
- org.springframework.messaging.support.NativeMessageHeaderAccessor
- org.springframework.messaging.simp.SimpMessageHeaderAccessor
- 直接已知子类:
StompHeaderAccessor
public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor
A base class for working with message headers in simple messaging protocols that support basic messaging patterns. Provides uniform access to specific values common across protocols such as a destination, message type (e.g. publish, subscribe, etc), session id, and others.Use one of the static factory method in this class, then call getters and setters, and at the end if necessary call
MessageHeaderAccessor.toMap()to obtain the updated headers.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
字段概要
字段 修饰符和类型 字段 说明 static StringCONNECT_MESSAGE_HEADERstatic StringDESTINATION_HEADERstatic StringDISCONNECT_MESSAGE_HEADERstatic StringHEART_BEAT_HEADERstatic StringIGNORE_ERRORA header that indicates to the broker that the sender will ignore errors.static StringMESSAGE_TYPE_HEADERstatic StringORIGINAL_DESTINATIONA header for internal use with "user" destinations where we need to restore the destination prior to sending messages to clients.static StringSESSION_ATTRIBUTESstatic StringSESSION_ID_HEADERstatic StringSUBSCRIPTION_ID_HEADERstatic StringUSER_HEADER从类继承的字段 org.springframework.messaging.support.NativeMessageHeaderAccessor
NATIVE_HEADERS
从类继承的字段 org.springframework.messaging.support.MessageHeaderAccessor
DEFAULT_CHARSET
构造器概要
构造器 限定符 构造器 说明 protectedSimpMessageHeaderAccessor(Message<?> message)A constructor for accessing and modifying existing message headers.protectedSimpMessageHeaderAccessor(SimpMessageType messageType, Map<String,List<String>> externalSourceHeaders)A constructor for creating new message headers.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 static SimpMessageHeaderAccessorcreate()Create an instance withSimpMessageTypeMESSAGE.static SimpMessageHeaderAccessorcreate(SimpMessageType messageType)Create an instance with the givenSimpMessageType.protected MessageHeaderAccessorcreateAccessor(Message<?> message)Build a 'nested' accessor for the given message.StringgetDestination()static StringgetDestination(Map<String,Object> headers)StringgetDetailedLogMessage(Object payload)Return a more detailed message for logging purposes.static long[]getHeartbeat(Map<String,Object> headers)SimpMessageTypegetMessageType()static SimpMessageTypegetMessageType(Map<String,Object> headers)Map<String,Object>getSessionAttributes()Return the attributes associated with the current session.static Map<String,Object>getSessionAttributes(Map<String,Object> headers)StringgetSessionId()Return the id of the current session.static StringgetSessionId(Map<String,Object> headers)StringgetShortLogMessage(Object payload)Return a concise message for logging purposes.StringgetSubscriptionId()static StringgetSubscriptionId(Map<String,Object> headers)PrincipalgetUser()Return the user associated with the current session.static PrincipalgetUser(Map<String,Object> headers)voidsetDestination(String destination)voidsetMessageTypeIfNotSet(SimpMessageType messageType)voidsetSessionAttributes(Map<String,Object> attributes)A static alternative for access to the session attributes header.voidsetSessionId(String sessionId)voidsetSubscriptionId(String subscriptionId)voidsetUser(Principal principal)voidsetUserChangeCallback(Consumer<Principal> callback)Provide a callback to be invoked if and whensetUser(Principal)is called.static SimpMessageHeaderAccessorwrap(Message<?> message)Create an instance from the payload and headers of the given Message.从类继承的方法 org.springframework.messaging.support.NativeMessageHeaderAccessor
addNativeHeader, addNativeHeaders, containsNativeHeader, copyHeaders, copyHeadersIfAbsent, getFirstNativeHeader, getFirstNativeHeader, getNativeHeader, getNativeHeaders, removeNativeHeader, setImmutable, setNativeHeader, setNativeHeaderValues, toNativeHeaderMap
从类继承的方法 org.springframework.messaging.support.MessageHeaderAccessor
getAccessor, getAccessor, getAccessor, getContentType, getDetailedPayloadLogMessage, getErrorChannel, getHeader, getId, getMessageHeaders, getMutableAccessor, getReplyChannel, getShortPayloadLogMessage, getTimestamp, isModified, isMutable, isReadableContentType, isReadOnly, removeHeader, removeHeaders, setContentType, setErrorChannel, setErrorChannelName, setHeader, setHeaderIfAbsent, setLeaveMutable, setModified, setReplyChannel, setReplyChannelName, toMap, toMessageHeaders, toString, verifyType
字段详细资料
DESTINATION_HEADER
public static final String DESTINATION_HEADER
- 另请参阅:
- 常量字段值
MESSAGE_TYPE_HEADER
public static final String MESSAGE_TYPE_HEADER
- 另请参阅:
- 常量字段值
SESSION_ID_HEADER
public static final String SESSION_ID_HEADER
- 另请参阅:
- 常量字段值
SESSION_ATTRIBUTES
public static final String SESSION_ATTRIBUTES
- 另请参阅:
- 常量字段值
SUBSCRIPTION_ID_HEADER
public static final String SUBSCRIPTION_ID_HEADER
- 另请参阅:
- 常量字段值
USER_HEADER
public static final String USER_HEADER
- 另请参阅:
- 常量字段值
CONNECT_MESSAGE_HEADER
public static final String CONNECT_MESSAGE_HEADER
- 另请参阅:
- 常量字段值
DISCONNECT_MESSAGE_HEADER
public static final String DISCONNECT_MESSAGE_HEADER
- 另请参阅:
- 常量字段值
HEART_BEAT_HEADER
public static final String HEART_BEAT_HEADER
- 另请参阅:
- 常量字段值
ORIGINAL_DESTINATION
public static final String ORIGINAL_DESTINATION
A header for internal use with "user" destinations where we need to restore the destination prior to sending messages to clients.- 另请参阅:
- 常量字段值
IGNORE_ERROR
public static final String IGNORE_ERROR
A header that indicates to the broker that the sender will ignore errors. The header is simply checked for presence or absence.- 另请参阅:
- 常量字段值
构造器详细资料
SimpMessageHeaderAccessor
protected SimpMessageHeaderAccessor(SimpMessageType messageType, @Nullable Map<String,List<String>> externalSourceHeaders)
A constructor for creating new message headers. This constructor is protected. See factory methods in this and sub-classes.
SimpMessageHeaderAccessor
protected SimpMessageHeaderAccessor(Message<?> message)
A constructor for accessing and modifying existing message headers. This constructor is protected. See factory methods in this and sub-classes.
方法详细资料
createAccessor
protected MessageHeaderAccessor createAccessor(Message<?> message)
从类复制的说明:MessageHeaderAccessorBuild a 'nested' accessor for the given message.- 覆盖:
createAccessor在类中MessageHeaderAccessor- 参数:
message- the message to build a new accessor for- 返回:
- the nested accessor (typically a specific subclass)
setMessageTypeIfNotSet
public void setMessageTypeIfNotSet(SimpMessageType messageType)
getMessageType
@Nullable public SimpMessageType getMessageType()
setDestination
public void setDestination(@Nullable String destination)
getDestination
@Nullable public String getDestination()
setSubscriptionId
public void setSubscriptionId(@Nullable String subscriptionId)
getSubscriptionId
@Nullable public String getSubscriptionId()
setSessionId
public void setSessionId(@Nullable String sessionId)
getSessionId
@Nullable public String getSessionId()
Return the id of the current session.
setSessionAttributes
public void setSessionAttributes(@Nullable Map<String,Object> attributes)
A static alternative for access to the session attributes header.
getSessionAttributes
@Nullable public Map<String,Object> getSessionAttributes()
Return the attributes associated with the current session.
setUserChangeCallback
public void setUserChangeCallback(Consumer<Principal> callback)
Provide a callback to be invoked if and whensetUser(Principal)is called. This is used internally on the inbound channel to detect token-based authentications through an interceptor.- 参数:
callback- the callback to invoke- 从以下版本开始:
- 5.1.9
getShortLogMessage
public String getShortLogMessage(Object payload)
从类复制的说明:MessageHeaderAccessorReturn a concise message for logging purposes.- 覆盖:
getShortLogMessage在类中MessageHeaderAccessor- 参数:
payload- the payload that corresponds to the headers.- 返回:
- the message
getDetailedLogMessage
public String getDetailedLogMessage(@Nullable Object payload)
从类复制的说明:MessageHeaderAccessorReturn a more detailed message for logging purposes.- 覆盖:
getDetailedLogMessage在类中MessageHeaderAccessor- 参数:
payload- the payload that corresponds to the headers.- 返回:
- the message
create
public static SimpMessageHeaderAccessor create()
Create an instance withSimpMessageTypeMESSAGE.
create
public static SimpMessageHeaderAccessor create(SimpMessageType messageType)
Create an instance with the givenSimpMessageType.
wrap
public static SimpMessageHeaderAccessor wrap(Message<?> message)
Create an instance from the payload and headers of the given Message.
getMessageType
@Nullable public static SimpMessageType getMessageType(Map<String,Object> headers)
getSessionAttributes
@Nullable public static Map<String,Object> getSessionAttributes(Map<String,Object> headers)
getHeartbeat
@Nullable public static long[] getHeartbeat(Map<String,Object> headers)