S - the Session typepublic final class SessionRepositoryMessageInterceptor<S extends Session>
extends java.lang.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.
Session.getId() with the WebSocket Session attributes when
the handshake is performed. This is later used when intercepting messages to ensure the
Session.getLastAccessedTime() is updated.Message's that are have SimpMessageType that corresponds
to setMatchingMessageTypes(Set) and updates the last accessed time of the
Session. If the Session is expired, the Message is prevented
from proceeding.
In order to work SessionRepositoryMessageInterceptor must be registered as a
ChannelInterceptor and a HandshakeInterceptor .
| Constructor and Description |
|---|
SessionRepositoryMessageInterceptor(SessionRepository<S> sessionRepository)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
afterHandshake(org.springframework.http.server.ServerHttpRequest request,
org.springframework.http.server.ServerHttpResponse response,
org.springframework.web.socket.WebSocketHandler wsHandler,
java.lang.Exception exception) |
boolean |
beforeHandshake(org.springframework.http.server.ServerHttpRequest request,
org.springframework.http.server.ServerHttpResponse response,
org.springframework.web.socket.WebSocketHandler wsHandler,
java.util.Map<java.lang.String,java.lang.Object> attributes) |
static java.lang.String |
getSessionId(java.util.Map<java.lang.String,java.lang.Object> attributes) |
org.springframework.messaging.Message<?> |
preSend(org.springframework.messaging.Message<?> message,
org.springframework.messaging.MessageChannel channel) |
void |
setMatchingMessageTypes(java.util.Set<org.springframework.messaging.simp.SimpMessageType> matchingMessageTypes)
Sets the
SimpMessageType to match on. |
static void |
setSessionId(java.util.Map<java.lang.String,java.lang.Object> attributes,
java.lang.String sessionId) |
public SessionRepositoryMessageInterceptor(SessionRepository<S> sessionRepository)
sessionRepository - the SessionRepository to use. Cannot be null.public void setMatchingMessageTypes(java.util.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.
matchingMessageTypes - the SimpMessageType to match on in
preSend(Message, MessageChannel), else the Message is continued
without accessing or updating the Sessionpublic org.springframework.messaging.Message<?> preSend(org.springframework.messaging.Message<?> message,
org.springframework.messaging.MessageChannel channel)
preSend in interface org.springframework.messaging.support.ChannelInterceptorpublic boolean beforeHandshake(org.springframework.http.server.ServerHttpRequest request,
org.springframework.http.server.ServerHttpResponse response,
org.springframework.web.socket.WebSocketHandler wsHandler,
java.util.Map<java.lang.String,java.lang.Object> attributes)
beforeHandshake in interface org.springframework.web.socket.server.HandshakeInterceptorpublic void afterHandshake(org.springframework.http.server.ServerHttpRequest request,
org.springframework.http.server.ServerHttpResponse response,
org.springframework.web.socket.WebSocketHandler wsHandler,
java.lang.Exception exception)
afterHandshake in interface org.springframework.web.socket.server.HandshakeInterceptorpublic static java.lang.String getSessionId(java.util.Map<java.lang.String,java.lang.Object> attributes)
public static void setSessionId(java.util.Map<java.lang.String,java.lang.Object> attributes,
java.lang.String sessionId)