提交 dc57cb2c 编写于 作者: R Rossen Stoyanchev

Update SessionDisconnectEvent

SessionDisconnectEvent now extends AbstractSubProtocolEvent.

Issue: SPR-12156
上级 4af98515
......@@ -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<byte[]> message, String sessionId, CloseStatus closeStatus) {
super(source, message);
Assert.notNull(sessionId, "'sessionId' must not be null");
this.sessionId = sessionId;
this.status = closeStatus;
......
......@@ -447,10 +447,10 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE
String userName = getSessionRegistryUserName(principal);
this.userSessionRegistry.unregisterSessionId(userName, session.getId());
}
Message<byte[]> 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<byte[]> createDisconnectMessage(WebSocketSession session) {
StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.DISCONNECT);
if (getHeaderInitializer() != null) {
getHeaderInitializer().initHeaders(headerAccessor);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册