Class SessionRepositoryMessageInterceptor<S extends Session>
java.lang.Object
org.springframework.session.web.socket.server.SessionRepositoryMessageInterceptor<S>
- Type Parameters:
S- theSessiontype
- 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.
- Associates the
Session.getId()with the WebSocket Session attributes when the handshake is performed. This is later used when intercepting messages to ensure theSession.getLastAccessedTime()is updated. - Intercepts
Message's that are haveSimpMessageTypethat corresponds tosetMatchingMessageTypes(Set)and updates the last accessed time of theSession. If theSessionis expired, theMessageis prevented from proceeding.
In order to work SessionRepositoryMessageInterceptor must be registered as a
ChannelInterceptor and a HandshakeInterceptor .
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionSessionRepositoryMessageInterceptor(SessionRepository<S> sessionRepository) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidafterHandshake(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, org.springframework.web.socket.WebSocketHandler wsHandler, Exception exception) booleanbeforeHandshake(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, org.springframework.web.socket.WebSocketHandler wsHandler, Map<String, Object> attributes) static StringgetSessionId(Map<String, Object> attributes) org.springframework.messaging.Message<?>preSend(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel) voidsetMatchingMessageTypes(Set<org.springframework.messaging.simp.SimpMessageType> matchingMessageTypes) Sets theSimpMessageTypeto match on.static voidsetSessionId(Map<String, Object> attributes, String sessionId) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.messaging.support.ChannelInterceptor
afterReceiveCompletion, afterSendCompletion, postReceive, postSend, preReceive
-
Constructor Details
-
SessionRepositoryMessageInterceptor
Creates a new instance.- Parameters:
sessionRepository- theSessionRepositoryto use. Cannot be null.
-
-
Method Details
-
setMatchingMessageTypes
public void setMatchingMessageTypes(Set<org.springframework.messaging.simp.SimpMessageType> matchingMessageTypes) Sets the
SimpMessageTypeto match on. If theMessagematches, thenpreSend(Message, MessageChannel)ensures theSessionis not expired and updates theSession.getLastAccessedTime()The default is: SimpMessageType.CONNECT, SimpMessageType.MESSAGE, SimpMessageType.SUBSCRIBE, SimpMessageType.UNSUBSCRIBE.
- Parameters:
matchingMessageTypes- theSimpMessageTypeto match on inpreSend(Message, MessageChannel), else theMessageis continued without accessing or updating theSession
-
preSend
public org.springframework.messaging.Message<?> preSend(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel) - Specified by:
preSendin interfaceorg.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:
beforeHandshakein interfaceorg.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:
afterHandshakein interfaceorg.springframework.web.socket.server.HandshakeInterceptor
-
getSessionId
-
setSessionId
-