Top Description Fields Constructors Methods
org.springframework.messaging.simp

public Class SimpMessageHeaderAccessor

extends NativeMessageHeaderAccessor
Class Inheritance
Known Direct Subclasses
org.springframework.messaging.simp.stomp.StompHeaderAccessor
Imports
java.security.Principal, java.util.List, .Map, java.util.function.Consumer, org.springframework.lang.Nullable, org.springframework.messaging.Message, org.springframework.messaging.support.IdTimestampMessageHeaderInitializer, .MessageHeaderAccessor, .NativeMessageHeaderAccessor, org.springframework.util.Assert, .CollectionUtils

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 toMap() to obtain the updated headers.

Author
Rossen Stoyanchev
Since
4.0

Field Summary

Modifier and TypeField and Description
public static final String
public static final String
public static final String
private static final IdTimestampMessageHeaderInitializer
public static final String
public static final String
IGNORE_ERROR

A header that indicates to the broker that the sender will ignore errors.

public static final String
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.

public static final String
public static final String
public static final String
public static final String
private Consumer<Principal>
Inherited from org.springframework.messaging.support.NativeMessageHeaderAccessor:
NATIVE_HEADERS

Constructor Summary

AccessConstructor and Description
protected
SimpMessageHeaderAccessor(SimpMessageType messageType, Map<String, List<String>> externalSourceHeaders)

A constructor for creating new message headers.

protected
SimpMessageHeaderAccessor(Message<?> message)

A constructor for accessing and modifying existing message headers.

Method Summary

Modifier and TypeMethod and Description
public static SimpMessageHeaderAccessor
public static SimpMessageHeaderAccessor
create(SimpMessageType messageType)

Create an instance with the given org.springframework.messaging.simp.SimpMessageType.

protected MessageHeaderAccessor
createAccessor(Message<?>
the message to build a new accessor for
message
)

Overrides org.springframework.messaging.support.MessageHeaderAccessor.createAccessor.

Build a 'nested' accessor for the given message.
private StringBuilder
public String
public static String
public String
getDetailedLogMessage(Object
the payload that corresponds to the headers.
payload
)

Overrides org.springframework.messaging.support.MessageHeaderAccessor.getDetailedLogMessage.

Return a more detailed message for logging purposes.
public static long[]
public SimpMessageType
public static SimpMessageType
public Map<String, Object>
getSessionAttributes()

Return the attributes associated with the current session.

public static Map<String, Object>
public String
getSessionId()

Return the id of the current session.

public static String
public String
getShortLogMessage(Object
the payload that corresponds to the headers.
payload
)

Overrides org.springframework.messaging.support.MessageHeaderAccessor.getShortLogMessage.

Return a concise message for logging purposes.
public String
public static String
public Principal
getUser()

Return the user associated with the current session.

public static Principal
getUser(Map<String, Object> headers)

public void
setDestination(String destination)

public void
public void
setSessionAttributes(Map<String, Object> attributes)

A static alternative for access to the session attributes header.

public void
setSessionId(String sessionId)

public void
setSubscriptionId(String subscriptionId)

public void
setUser(Principal principal)

public void
setUserChangeCallback(Consumer<Principal>
the callback to invoke
callback
)

Provide a callback to be invoked if and when setUser(Principal) is called.

public static SimpMessageHeaderAccessor
wrap(Message<?> message)

Create an instance by copying the headers of a Message.

Inherited from org.springframework.messaging.support.NativeMessageHeaderAccessor:
addNativeHeaderaddNativeHeaderscontainsNativeHeadercopyHeaderscopyHeadersIfAbsentgetFirstNativeHeadergetFirstNativeHeadergetNativeHeadergetNativeHeadersremoveNativeHeadersetImmutablesetNativeHeadersetNativeHeaderValuestoNativeHeaderMap

Field Detail

CONNECT_MESSAGE_HEADERback to summary
public static final String CONNECT_MESSAGE_HEADER
DESTINATION_HEADERback to summary
public static final String DESTINATION_HEADER
DISCONNECT_MESSAGE_HEADERback to summary
public static final String DISCONNECT_MESSAGE_HEADER
headerInitializerback to summary
private static final IdTimestampMessageHeaderInitializer headerInitializer
HEART_BEAT_HEADERback to summary
public static final String HEART_BEAT_HEADER
IGNORE_ERRORback to summary
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.

MESSAGE_TYPE_HEADERback to summary
public static final String MESSAGE_TYPE_HEADER
ORIGINAL_DESTINATIONback to summary
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.

SESSION_ATTRIBUTESback to summary
public static final String SESSION_ATTRIBUTES
SESSION_ID_HEADERback to summary
public static final String SESSION_ID_HEADER
SUBSCRIPTION_ID_HEADERback to summary
public static final String SUBSCRIPTION_ID_HEADER
USER_HEADERback to summary
public static final String USER_HEADER
userCallbackback to summary
private Consumer<Principal> userCallback
Annotations
@Nullable

Constructor Detail

SimpMessageHeaderAccessorback to summary
protected SimpMessageHeaderAccessor(SimpMessageType messageType, Map<String, List<String>> externalSourceHeaders)

A constructor for creating new message headers.

This constructor is protected. See factory methods in this class and subclasses.

SimpMessageHeaderAccessorback to summary
protected SimpMessageHeaderAccessor(Message<?> message)

A constructor for accessing and modifying existing message headers.

This constructor is protected. See factory methods in this class and subclasses.

Method Detail

createback to summary
public static SimpMessageHeaderAccessor create()

Create an instance with org.springframework.messaging.simp.SimpMessageType MESSAGE.

createback to summary
public static SimpMessageHeaderAccessor create(SimpMessageType messageType)

Create an instance with the given org.springframework.messaging.simp.SimpMessageType.

createAccessorback to summary
protected MessageHeaderAccessor createAccessor(Message<?> message)

Overrides org.springframework.messaging.support.MessageHeaderAccessor.createAccessor.

Doc from org.springframework.messaging.support.MessageHeaderAccessor.createAccessor.

Build a 'nested' accessor for the given message.

Parameters
message:Message<?>

the message to build a new accessor for

Returns:MessageHeaderAccessor

the nested accessor (typically a specific subclass)

Annotations
@Override
getBaseLogMessageback to summary
private StringBuilder getBaseLogMessage()
getDestinationback to summary
public String getDestination()
Annotations
@Nullable
getDestinationback to summary
public static String getDestination(Map<String, Object> headers)
Annotations
@Nullable
getDetailedLogMessageback to summary
public String getDetailedLogMessage(Object payload)

Overrides org.springframework.messaging.support.MessageHeaderAccessor.getDetailedLogMessage.

Doc from org.springframework.messaging.support.MessageHeaderAccessor.getDetailedLogMessage.

Return a more detailed message for logging purposes.

Parameters
payload:Object

the payload that corresponds to the headers.

Returns:String

the message

Annotations
@SuppressWarnings:unchecked
@Override
getHeartbeatback to summary
public static long[] getHeartbeat(Map<String, Object> headers)
Annotations
@Nullable
getMessageTypeback to summary
public SimpMessageType getMessageType()
Annotations
@Nullable
getMessageTypeback to summary
public static SimpMessageType getMessageType(Map<String, Object> headers)
Annotations
@Nullable
getSessionAttributesback to summary
public Map<String, Object> getSessionAttributes()

Return the attributes associated with the current session.

Annotations
@SuppressWarnings:unchecked
@Nullable
getSessionAttributesback to summary
public static Map<String, Object> getSessionAttributes(Map<String, Object> headers)
Annotations
@SuppressWarnings:unchecked
@Nullable
getSessionIdback to summary
public String getSessionId()

Return the id of the current session.

Annotations
@Nullable
getSessionIdback to summary
public static String getSessionId(Map<String, Object> headers)
Annotations
@Nullable
getShortLogMessageback to summary
public String getShortLogMessage(Object payload)

Overrides org.springframework.messaging.support.MessageHeaderAccessor.getShortLogMessage.

Doc from org.springframework.messaging.support.MessageHeaderAccessor.getShortLogMessage.

Return a concise message for logging purposes.

Parameters
payload:Object

the payload that corresponds to the headers.

Returns:String

the message

Annotations
@Override
getSubscriptionIdback to summary
public String getSubscriptionId()
Annotations
@Nullable
getSubscriptionIdback to summary
public static String getSubscriptionId(Map<String, Object> headers)
Annotations
@Nullable
getUserback to summary
public Principal getUser()

Return the user associated with the current session.

Annotations
@Nullable
getUserback to summary
public static Principal getUser(Map<String, Object> headers)
Annotations
@Nullable
setDestinationback to summary
public void setDestination(String destination)
setMessageTypeIfNotSetback to summary
public void setMessageTypeIfNotSet(SimpMessageType messageType)
setSessionAttributesback to summary
public void setSessionAttributes(Map<String, Object> attributes)

A static alternative for access to the session attributes header.

setSessionIdback to summary
public void setSessionId(String sessionId)
setSubscriptionIdback to summary
public void setSubscriptionId(String subscriptionId)
setUserback to summary
public void setUser(Principal principal)
setUserChangeCallbackback to summary
public void setUserChangeCallback(Consumer<Principal> callback)

Provide a callback to be invoked if and when setUser(Principal) is called. This is used internally on the inbound channel to detect token-based authentications through an interceptor.

Parameters
callback:Consumer<Principal>

the callback to invoke

Since
5.1.9
wrapback to summary
public static SimpMessageHeaderAccessor wrap(Message<?> message)

Create an instance by copying the headers of a Message.