Class AbstractSubProtocolEvent

java.lang.Object
java.util.EventObject
org.springframework.context.ApplicationEvent
org.springframework.web.socket.messaging.AbstractSubProtocolEvent
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
SessionConnectedEvent, SessionConnectEvent, SessionDisconnectEvent, SessionSubscribeEvent, SessionUnsubscribeEvent

public abstract class AbstractSubProtocolEvent extends ApplicationEvent
A base class for events for a message received from a WebSocket client and parsed into a higher-level sub-protocol (e.g. STOMP).
Since:
4.1
Author:
Rossen Stoyanchev
See Also:
  • Constructor Details

    • AbstractSubProtocolEvent

      protected AbstractSubProtocolEvent(Object source, Message<byte[]> message)
      Create a new AbstractSubProtocolEvent.
      Parameters:
      source - the component that published the event (never null)
      message - the incoming message (never null)
    • AbstractSubProtocolEvent

      protected AbstractSubProtocolEvent(Object source, Message<byte[]> message, @Nullable Principal user)
      Create a new AbstractSubProtocolEvent.
      Parameters:
      source - the component that published the event (never null)
      message - the incoming message (never null)
  • Method Details

    • getMessage

      public Message<byte[]> getMessage()
      Return the Message associated with the event. Here is an example of obtaining information about the session id or any headers in the message:
       StompHeaderAccessor headers = StompHeaderAccessor.wrap(message);
       headers.getSessionId();
       headers.getSessionAttributes();
       headers.getPrincipal();
       
    • getUser

      @Nullable public Principal getUser()
      Return the user for the session associated with the event.
    • toString

      public String toString()
      Overrides:
      toString in class EventObject