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 Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
A header that indicates to the broker that the sender will ignore errors.static final String
static final String
A header for internal use with "user" destinations where we need to restore the destination prior to sending messages to clients.static final String
static final String
static final String
static final String
Fields inherited from class org.springframework.messaging.support.NativeMessageHeaderAccessor
NATIVE_HEADERS
Fields inherited from class org.springframework.messaging.support.MessageHeaderAccessor
DEFAULT_CHARSET
-
Constructor Summary
ModifierConstructorDescriptionprotected
SimpMessageHeaderAccessor
(Message<?> message) A constructor for accessing and modifying existing message headers.protected
SimpMessageHeaderAccessor
(SimpMessageType messageType, Map<String, List<String>> externalSourceHeaders) A constructor for creating new message headers. -
Method Summary
Modifier and TypeMethodDescriptionstatic SimpMessageHeaderAccessor
create()
Create an instance withSimpMessageType
MESSAGE
.static SimpMessageHeaderAccessor
create
(SimpMessageType messageType) Create an instance with the givenSimpMessageType
.protected MessageHeaderAccessor
createAccessor
(Message<?> message) Build a 'nested' accessor for the given message.static String
getDestination
(Map<String, Object> headers) getDetailedLogMessage
(Object payload) Return a more detailed message for logging purposes.static long[]
getHeartbeat
(Map<String, Object> headers) static SimpMessageType
getMessageType
(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 String
getSessionId
(Map<String, Object> headers) getShortLogMessage
(Object payload) Return a concise message for logging purposes.static String
getSubscriptionId
(Map<String, Object> headers) getUser()
Return the user associated with the current session.static Principal
void
setDestination
(String destination) void
setMessageTypeIfNotSet
(SimpMessageType messageType) void
setSessionAttributes
(Map<String, Object> attributes) A static alternative for access to the session attributes header.void
setSessionId
(String sessionId) void
setSubscriptionId
(String subscriptionId) void
void
setUserChangeCallback
(Consumer<Principal> callback) Provide a callback to be invoked if and whensetUser(Principal)
is called.static SimpMessageHeaderAccessor
Create an instance from the payload and headers of the given Message.Methods inherited from class org.springframework.messaging.support.NativeMessageHeaderAccessor
addNativeHeader, addNativeHeaders, containsNativeHeader, copyHeaders, copyHeadersIfAbsent, getFirstNativeHeader, getFirstNativeHeader, getNativeHeader, getNativeHeaders, removeNativeHeader, setImmutable, setNativeHeader, setNativeHeaderValues, toNativeHeaderMap
Methods inherited from class 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
-
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
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 class and subclasses.
-
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:MessageHeaderAccessor
Build a 'nested' accessor for the given message.- Overrides:
createAccessor
in 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
Return the id of the current session. -
setSessionAttributes
A static alternative for access to the session attributes header. -
getSessionAttributes
Return the attributes associated with the current session. -
setUser
-
getUser
Return the user associated with the current session. -
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:MessageHeaderAccessor
Return a concise message for logging purposes.- Overrides:
getShortLogMessage
in classMessageHeaderAccessor
- Parameters:
payload
- the payload that corresponds to the headers.- Returns:
- the message
-
getDetailedLogMessage
Description copied from class:MessageHeaderAccessor
Return a more detailed message for logging purposes.- Overrides:
getDetailedLogMessage
in classMessageHeaderAccessor
- Parameters:
payload
- the payload that corresponds to the headers.- Returns:
- the message
-
create
Create an instance withSimpMessageType
MESSAGE
. -
create
Create an instance with the givenSimpMessageType
. -
wrap
Create an instance from the payload and headers of the given Message. -
getMessageType
-
getDestination
-
getSubscriptionId
-
getSessionId
-
getSessionAttributes
-
getUser
-
getHeartbeat
-