S - the ExpiringSession typepublic final class SessionRepositoryMessageInterceptor<S extends ExpiringSession>
extends org.springframework.messaging.support.ChannelInterceptorAdapter
implements org.springframework.web.socket.server.HandshakeInterceptor
Acts as a ChannelInterceptor and a HandshakeInterceptor to ensure the
ExpiringSession.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
ExpiringSession.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,
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 |
getSessionId(Map<String,Object> attributes) |
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) |
public SessionRepositoryMessageInterceptor(SessionRepository<S> sessionRepository)
sessionRepository - the SessionRepository to use. Cannot be null.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 ExpiringSession.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.ChannelInterceptorpreSend in class org.springframework.messaging.support.ChannelInterceptorAdapterpublic boolean beforeHandshake(org.springframework.http.server.ServerHttpRequest request,
org.springframework.http.server.ServerHttpResponse response,
org.springframework.web.socket.WebSocketHandler wsHandler,
Map<String,Object> attributes)
throws Exception
beforeHandshake in interface org.springframework.web.socket.server.HandshakeInterceptorExceptionpublic void afterHandshake(org.springframework.http.server.ServerHttpRequest request,
org.springframework.http.server.ServerHttpResponse response,
org.springframework.web.socket.WebSocketHandler wsHandler,
Exception exception)
afterHandshake in interface org.springframework.web.socket.server.HandshakeInterceptor