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 (for example, 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 Summary
FieldsModifier 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 NativeMessageHeaderAccessor
NATIVE_HEADERSFields inherited from class MessageHeaderAccessor
DEFAULT_CHARSET -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSimpMessageHeaderAccessor(Message<?> message) A constructor for accessing and modifying existing message headers.protectedSimpMessageHeaderAccessor(SimpMessageType messageType, @Nullable Map<String, List<String>> externalSourceHeaders) A constructor for creating new message headers. -
Method Summary
Modifier 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.getDestination(Map<String, Object> headers) getDetailedLogMessage(@Nullable Object payload) Return a more detailed message for logging purposes.static long @Nullable []getHeartbeat(Map<String, Object> headers) static @Nullable 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.getSessionId(Map<String, Object> headers) getShortLogMessage(Object payload) Return a concise message for logging purposes.getSubscriptionId(Map<String, Object> headers) getUser()Return the user associated with the current session.voidsetDestination(@Nullable String destination) voidsetMessageTypeIfNotSet(SimpMessageType messageType) voidsetSessionAttributes(@Nullable Map<String, Object> attributes) A static alternative for access to the session attributes header.voidsetSessionId(@Nullable String sessionId) voidsetSubscriptionId(@Nullable String subscriptionId) voidvoidsetUserChangeCallback(Consumer<Principal> callback) Provide a callback to be invoked if and whensetUser(Principal)is called.static SimpMessageHeaderAccessorCreate an instance by copying the headers of a Message.Methods inherited from class NativeMessageHeaderAccessor
addNativeHeader, addNativeHeaders, containsNativeHeader, copyHeaders, copyHeadersIfAbsent, getFirstNativeHeader, getFirstNativeHeader, getNativeHeader, getNativeHeaders, removeNativeHeader, setImmutable, setNativeHeader, setNativeHeaderValues, toNativeHeaderMapMethods inherited from class MessageHeaderAccessor
fromMap, fromMessageHeaders, 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
-
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_DESTINATION
A header for internal use with "user" destinations where we need to restore the destination prior to sending messages to clients.- See Also:
-
IGNORE_ERROR
A 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
-
SimpMessageHeaderAccessor
-
SimpMessageHeaderAccessor
A constructor for accessing and modifying existing message headers.This constructor is protected. See factory methods in this class and subclasses.
-
-
Method Details
-
createAccessor
Description copied from class:MessageHeaderAccessorBuild a 'nested' accessor for the given message.- Overrides:
createAccessorin classMessageHeaderAccessor- 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
-
getSessionId
-
setSessionAttributes
-
getSessionAttributes
-
setUser
-
getUser
-
setUserChangeCallback
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.- Parameters:
callback- the callback to invoke- Since:
- 5.1.9
-
getShortLogMessage
Description copied from class:MessageHeaderAccessorReturn a concise message for logging purposes.- Overrides:
getShortLogMessagein classMessageHeaderAccessor- Parameters:
payload- the payload that corresponds to the headers.- Returns:
- the message
-
getDetailedLogMessage
Description copied from class:MessageHeaderAccessorReturn a more detailed message for logging purposes.- Overrides:
getDetailedLogMessagein classMessageHeaderAccessor- Parameters:
payload- the payload that corresponds to the headers.- Returns:
- the message
-
create
Create an instance withSimpMessageTypeMESSAGE. -
create
Create an instance with the givenSimpMessageType. -
wrap
Create an instance by copying the headers of a Message. -
getMessageType
-
getDestination
-
getSubscriptionId
-
getSessionId
-
getSessionAttributes
-
getUser
-
getHeartbeat
-