Class SimpMessageHeaderAccessor
java.lang.Object
org.springframework.messaging.support.MessageHeaderAccessor
org.springframework.messaging.support.NativeMessageHeaderAccessor
org.springframework.messaging.simp.SimpMessageHeaderAccessor
- Direct Known Subclasses:
- StompHeaderAccessor
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 methods in this class, then call getters and setters,
 and at the end if necessary call MessageHeaderAccessor.toMap() to obtain the updated headers.
- Since:
- 4.0
- Author:
- Rossen Stoyanchev
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringA header that indicates to the broker that the sender will ignore errors.static final Stringstatic final StringA header for internal use with "user" destinations where we need to restore the destination prior to sending messages to clients.static final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class org.springframework.messaging.support.NativeMessageHeaderAccessorNATIVE_HEADERSFields inherited from class org.springframework.messaging.support.MessageHeaderAccessorDEFAULT_CHARSET
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedSimpMessageHeaderAccessor(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.
- 
Method SummaryModifier and TypeMethodDescriptionstatic 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.static StringgetDestination(Map<String, Object> headers) getDetailedLogMessage(Object payload) Return a more detailed message for logging purposes.static long[]getHeartbeat(Map<String, Object> headers) static SimpMessageTypegetMessageType(Map<String, Object> headers) Return the attributes associated with the current session.getSessionAttributes(Map<String, Object> headers) Return the id of the current session.static StringgetSessionId(Map<String, Object> headers) getShortLogMessage(Object payload) Return a concise message for logging purposes.static StringgetSubscriptionId(Map<String, Object> headers) getUser()Return the user associated with the current session.static PrincipalvoidsetDestination(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) voidvoidsetUserChangeCallback(Consumer<Principal> callback) Provide a callback to be invoked if and whensetUser(Principal)is called.static SimpMessageHeaderAccessorCreate an instance from the payload and headers of the given Message.Methods inherited from class org.springframework.messaging.support.NativeMessageHeaderAccessoraddNativeHeader, addNativeHeaders, containsNativeHeader, copyHeaders, copyHeadersIfAbsent, getFirstNativeHeader, getFirstNativeHeader, getNativeHeader, getNativeHeaders, removeNativeHeader, setImmutable, setNativeHeader, setNativeHeaderValues, toNativeHeaderMapMethods inherited from class org.springframework.messaging.support.MessageHeaderAccessorgetAccessor, 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
- 
Field Details- 
DESTINATION_HEADER- See Also:
 
- 
MESSAGE_TYPE_HEADER- See Also:
 
- 
SESSION_ID_HEADER- See Also:
 
- 
SESSION_ATTRIBUTES- See Also:
 
- 
SUBSCRIPTION_ID_HEADER- See Also:
 
- 
USER_HEADER- See Also:
 
- 
CONNECT_MESSAGE_HEADER- See Also:
 
- 
DISCONNECT_MESSAGE_HEADER- See Also:
 
- 
HEART_BEAT_HEADER- See Also:
 
- 
ORIGINAL_DESTINATIONA header for internal use with "user" destinations where we need to restore the destination prior to sending messages to clients.- See Also:
 
- 
IGNORE_ERRORA header that indicates to the broker that the sender will ignore errors. The header is simply checked for presence or absence.- See Also:
 
 
- 
- 
Constructor Details- 
SimpMessageHeaderAccessorprotected 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 class and subclasses. 
- 
SimpMessageHeaderAccessorA constructor for accessing and modifying existing message headers.This constructor is protected. See factory methods in this class and subclasses. 
 
- 
- 
Method Details- 
createAccessorDescription copied from class:MessageHeaderAccessorBuild a 'nested' accessor for the given message.- Overrides:
- createAccessorin class- MessageHeaderAccessor
- Parameters:
- message- the message to build a new accessor for
- Returns:
- the nested accessor (typically a specific subclass)
 
- 
setMessageTypeIfNotSet
- 
getMessageType
- 
setDestination
- 
getDestination
- 
setSubscriptionId
- 
getSubscriptionId
- 
setSessionId
- 
getSessionIdReturn the id of the current session.
- 
setSessionAttributesA static alternative for access to the session attributes header.
- 
getSessionAttributesReturn the attributes associated with the current session.
- 
setUser
- 
getUserReturn the user associated with the current session.
- 
setUserChangeCallbackProvide 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.- Parameters:
- callback- the callback to invoke
- Since:
- 5.1.9
 
- 
getShortLogMessageDescription copied from class:MessageHeaderAccessorReturn a concise message for logging purposes.- Overrides:
- getShortLogMessagein class- MessageHeaderAccessor
- Parameters:
- payload- the payload that corresponds to the headers.
- Returns:
- the message
 
- 
getDetailedLogMessageDescription copied from class:MessageHeaderAccessorReturn a more detailed message for logging purposes.- Overrides:
- getDetailedLogMessagein class- MessageHeaderAccessor
- Parameters:
- payload- the payload that corresponds to the headers.
- Returns:
- the message
 
- 
createCreate an instance withSimpMessageTypeMESSAGE.
- 
createCreate an instance with the givenSimpMessageType.
- 
wrapCreate an instance from the payload and headers of the given Message.
- 
getMessageType
- 
getDestination
- 
getSubscriptionId
- 
getSessionId
- 
getSessionAttributes
- 
getUser
- 
getHeartbeat
 
-