From dc57cb2c9fa366ba5e6ac3f9723dc83af173c3f4 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 18 Sep 2014 15:21:11 -0400 Subject: [PATCH] Update SessionDisconnectEvent SessionDisconnectEvent now extends AbstractSubProtocolEvent. Issue: SPR-12156 --- .../socket/messaging/SessionDisconnectEvent.java | 13 +++++-------- .../socket/messaging/StompSubProtocolHandler.java | 6 +++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionDisconnectEvent.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionDisconnectEvent.java index 02a76a37ba..6fe228f81a 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionDisconnectEvent.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionDisconnectEvent.java @@ -17,7 +17,7 @@ package org.springframework.web.socket.messaging; -import org.springframework.context.ApplicationEvent; +import org.springframework.messaging.Message; import org.springframework.util.Assert; import org.springframework.web.socket.CloseStatus; @@ -32,21 +32,18 @@ import org.springframework.web.socket.CloseStatus; * @since 4.0.3 */ @SuppressWarnings("serial") -public class SessionDisconnectEvent extends ApplicationEvent { +public class SessionDisconnectEvent extends AbstractSubProtocolEvent { private final String sessionId; private final CloseStatus status; + /** * Create a new event. - * - * @param source the component that published the event (never {@code null}) - * @param sessionId the disconnect message - * @param closeStatus */ - public SessionDisconnectEvent(Object source, String sessionId, CloseStatus closeStatus) { - super(source); + public SessionDisconnectEvent(Object source, Message message, String sessionId, CloseStatus closeStatus) { + super(source, message); Assert.notNull(sessionId, "'sessionId' must not be null"); this.sessionId = sessionId; this.status = closeStatus; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java index d68df830c7..d057de6ee7 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java @@ -447,10 +447,10 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE String userName = getSessionRegistryUserName(principal); this.userSessionRegistry.unregisterSessionId(userName, session.getId()); } + Message message = createDisconnectMessage(session); if (this.eventPublisher != null) { - publishEvent(new SessionDisconnectEvent(this, session.getId(), closeStatus)); + publishEvent(new SessionDisconnectEvent(this, message, session.getId(), closeStatus)); } - Message message = createDisconnectMessage(session); SimpAttributes simpAttributes = SimpAttributes.fromMessage(message); try { SimpAttributesContextHolder.setAttributes(simpAttributes); @@ -462,7 +462,7 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE } } - private Message createDisconnectMessage(WebSocketSession session) { + private Message createDisconnectMessage(WebSocketSession session) { StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.DISCONNECT); if (getHeaderInitializer() != null) { getHeaderInitializer().initHeaders(headerAccessor); -- GitLab