Class SessionRepositoryMessageInterceptor<S extends Session>

java.lang.Object
org.springframework.session.web.socket.server.SessionRepositoryMessageInterceptor<S>
Type Parameters:
S - the Session type
All Implemented Interfaces:
org.springframework.messaging.support.ChannelInterceptor, org.springframework.web.socket.server.HandshakeInterceptor

public final class SessionRepositoryMessageInterceptor<S extends Session> extends Object implements org.springframework.messaging.support.ChannelInterceptor, org.springframework.web.socket.server.HandshakeInterceptor

Acts as a ChannelInterceptor and a HandshakeInterceptor to ensure the Session.getLastAccessedTime() is up to date.

In order to work SessionRepositoryMessageInterceptor must be registered as a ChannelInterceptor and a HandshakeInterceptor .

Since:
1.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    afterHandshake(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, org.springframework.web.socket.WebSocketHandler wsHandler, Exception exception)
     
    boolean
    beforeHandshake(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, org.springframework.web.socket.WebSocketHandler wsHandler, Map<String,Object> attributes)
     
    static String
     
    org.springframework.messaging.Message<?>
    preSend(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel)
     
    void
    setMatchingMessageTypes(Set<org.springframework.messaging.simp.SimpMessageType> matchingMessageTypes)
    Sets the SimpMessageType to match on.
    static void
    setSessionId(Map<String,Object> attributes, String sessionId)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.messaging.support.ChannelInterceptor

    afterReceiveCompletion, afterSendCompletion, postReceive, postSend, preReceive
  • Constructor Details

    • SessionRepositoryMessageInterceptor

      public SessionRepositoryMessageInterceptor(SessionRepository<S> sessionRepository)
      Creates a new instance.
      Parameters:
      sessionRepository - the SessionRepository to use. Cannot be null.
  • Method Details

    • setMatchingMessageTypes

      public void setMatchingMessageTypes(Set<org.springframework.messaging.simp.SimpMessageType> matchingMessageTypes)

      Sets the SimpMessageType to match on. If the Message matches, then preSend(Message, MessageChannel) ensures the Session is not expired and updates the Session.getLastAccessedTime()

      The default is: SimpMessageType.CONNECT, SimpMessageType.MESSAGE, SimpMessageType.SUBSCRIBE, SimpMessageType.UNSUBSCRIBE.

      Parameters:
      matchingMessageTypes - the SimpMessageType to match on in preSend(Message, MessageChannel), else the Message is continued without accessing or updating the Session
    • preSend

      public org.springframework.messaging.Message<?> preSend(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel)
      Specified by:
      preSend in interface org.springframework.messaging.support.ChannelInterceptor
    • beforeHandshake

      public boolean beforeHandshake(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, org.springframework.web.socket.WebSocketHandler wsHandler, Map<String,Object> attributes)
      Specified by:
      beforeHandshake in interface org.springframework.web.socket.server.HandshakeInterceptor
    • afterHandshake

      public void afterHandshake(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, org.springframework.web.socket.WebSocketHandler wsHandler, Exception exception)
      Specified by:
      afterHandshake in interface org.springframework.web.socket.server.HandshakeInterceptor
    • getSessionId

      public static String getSessionId(Map<String,Object> attributes)
    • setSessionId

      public static void setSessionId(Map<String,Object> attributes, String sessionId)