Search in sources :

Example 1 with SessionExpiredEvent

use of org.springframework.session.events.SessionExpiredEvent in project spring-session by spring-projects.

the class WebSocketRegistryListenerTests method setup.

@Before
public void setup() {
    String sessionId = "session-id";
    MapSession session = new MapSession(sessionId);
    this.attributes = new HashMap<>();
    SessionRepositoryMessageInterceptor.setSessionId(this.attributes, sessionId);
    given(this.wsSession.getAttributes()).willReturn(this.attributes);
    given(this.wsSession.getPrincipal()).willReturn(this.principal);
    given(this.wsSession.getId()).willReturn("wsSession-id");
    given(this.wsSession2.getAttributes()).willReturn(this.attributes);
    given(this.wsSession2.getPrincipal()).willReturn(this.principal);
    given(this.wsSession2.getId()).willReturn("wsSession-id2");
    Map<String, Object> headers = new HashMap<>();
    headers.put(SimpMessageHeaderAccessor.SESSION_ATTRIBUTES, this.attributes);
    given(this.message.getHeaders()).willReturn(new MessageHeaders(headers));
    this.listener = new WebSocketRegistryListener();
    this.connect = new SessionConnectEvent(this.listener, this.wsSession);
    this.connect2 = new SessionConnectEvent(this.listener, this.wsSession2);
    this.disconnect = new SessionDisconnectEvent(this.listener, this.message, this.wsSession.getId(), CloseStatus.NORMAL);
    this.deleted = new SessionDeletedEvent(this.listener, session);
    this.expired = new SessionExpiredEvent(this.listener, session);
}
Also used : HashMap(java.util.HashMap) SessionDeletedEvent(org.springframework.session.events.SessionDeletedEvent) SessionDisconnectEvent(org.springframework.web.socket.messaging.SessionDisconnectEvent) SessionExpiredEvent(org.springframework.session.events.SessionExpiredEvent) MapSession(org.springframework.session.MapSession) MessageHeaders(org.springframework.messaging.MessageHeaders) SessionConnectEvent(org.springframework.session.web.socket.events.SessionConnectEvent) Before(org.junit.Before)

Example 2 with SessionExpiredEvent

use of org.springframework.session.events.SessionExpiredEvent in project redisson by redisson.

the class RedissonSessionRepository method onMessage.

@Override
public void onMessage(String pattern, String channel, String body) {
    if (createdTopic.getPatternNames().contains(pattern)) {
        RedissonSession session = getSession(body);
        if (session != null) {
            publishEvent(new SessionCreatedEvent(this, session));
        }
    } else if (deletedTopic.getPatternNames().contains(pattern)) {
        String id = body.split(":")[1];
        RedissonSession session = new RedissonSession(id);
        if (session.load()) {
            session.clearPrincipal();
            publishEvent(new SessionDeletedEvent(this, session));
        } else {
            publishEvent(new SessionDeletedEvent(this, id));
        }
    } else if (expiredTopic.getPatternNames().contains(pattern)) {
        String id = body.split(":")[1];
        RedissonSession session = new RedissonSession(id);
        if (session.load()) {
            session.clearPrincipal();
            publishEvent(new SessionExpiredEvent(this, session));
        } else {
            publishEvent(new SessionExpiredEvent(this, id));
        }
    }
}
Also used : SessionCreatedEvent(org.springframework.session.events.SessionCreatedEvent) SessionDeletedEvent(org.springframework.session.events.SessionDeletedEvent) SessionExpiredEvent(org.springframework.session.events.SessionExpiredEvent)

Aggregations

SessionDeletedEvent (org.springframework.session.events.SessionDeletedEvent)2 SessionExpiredEvent (org.springframework.session.events.SessionExpiredEvent)2 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 MessageHeaders (org.springframework.messaging.MessageHeaders)1 MapSession (org.springframework.session.MapSession)1 SessionCreatedEvent (org.springframework.session.events.SessionCreatedEvent)1 SessionConnectEvent (org.springframework.session.web.socket.events.SessionConnectEvent)1 SessionDisconnectEvent (org.springframework.web.socket.messaging.SessionDisconnectEvent)1