List of usage examples for org.springframework.messaging.simp SimpMessageHeaderAccessor getSessionAttributes
@SuppressWarnings("unchecked") @Nullable public static Map<String, Object> getSessionAttributes(Map<String, Object> headers)
From source file:org.springframework.messaging.simp.SimpAttributes.java
/** * Extract the SiMP session attributes from the given message and * wrap them in a {@link SimpAttributes} instance. * @param message the message to extract session attributes from *//*from w ww .ja v a 2 s. co m*/ public static SimpAttributes fromMessage(Message<?> message) { Assert.notNull(message, "Message must not be null"); MessageHeaders headers = message.getHeaders(); String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); Map<String, Object> sessionAttributes = SimpMessageHeaderAccessor.getSessionAttributes(headers); if (sessionId == null) { throw new IllegalStateException("No session id in " + message); } if (sessionAttributes == null) { throw new IllegalStateException("No session attributes in " + message); } return new SimpAttributes(sessionId, sessionAttributes); }
From source file:org.springframework.session.web.socket.handler.WebSocketRegistryListener.java
public void onApplicationEvent(ApplicationEvent event) { if (event instanceof SessionDestroyedEvent) { SessionDestroyedEvent e = (SessionDestroyedEvent) event; closeWsSessions(e.getSessionId()); } else if (event instanceof SessionConnectEvent) { SessionConnectEvent e = (SessionConnectEvent) event; afterConnectionEstablished(e.getWebSocketSession()); } else if (event instanceof SessionDisconnectEvent) { SessionDisconnectEvent e = (SessionDisconnectEvent) event; Map<String, Object> sessionAttributes = SimpMessageHeaderAccessor .getSessionAttributes(e.getMessage().getHeaders()); String httpSessionId = sessionAttributes == null ? null : SessionRepositoryMessageInterceptor.getSessionId(sessionAttributes); afterConnectionClosed(httpSessionId, e.getSessionId()); }/*from www . j a va 2 s.c om*/ }