Update SessionDisconnectEvent
SessionDisconnectEvent now extends AbstractSubProtocolEvent. Issue: SPR-12156
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
package org.springframework.web.socket.messaging;
|
package org.springframework.web.socket.messaging;
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.socket.CloseStatus;
|
import org.springframework.web.socket.CloseStatus;
|
||||||
|
|
||||||
@@ -32,21 +32,18 @@ import org.springframework.web.socket.CloseStatus;
|
|||||||
* @since 4.0.3
|
* @since 4.0.3
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class SessionDisconnectEvent extends ApplicationEvent {
|
public class SessionDisconnectEvent extends AbstractSubProtocolEvent {
|
||||||
|
|
||||||
private final String sessionId;
|
private final String sessionId;
|
||||||
|
|
||||||
private final CloseStatus status;
|
private final CloseStatus status;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new event.
|
* 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) {
|
public SessionDisconnectEvent(Object source, Message<byte[]> message, String sessionId, CloseStatus closeStatus) {
|
||||||
super(source);
|
super(source, message);
|
||||||
Assert.notNull(sessionId, "'sessionId' must not be null");
|
Assert.notNull(sessionId, "'sessionId' must not be null");
|
||||||
this.sessionId = sessionId;
|
this.sessionId = sessionId;
|
||||||
this.status = closeStatus;
|
this.status = closeStatus;
|
||||||
|
|||||||
@@ -447,10 +447,10 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE
|
|||||||
String userName = getSessionRegistryUserName(principal);
|
String userName = getSessionRegistryUserName(principal);
|
||||||
this.userSessionRegistry.unregisterSessionId(userName, session.getId());
|
this.userSessionRegistry.unregisterSessionId(userName, session.getId());
|
||||||
}
|
}
|
||||||
|
Message<byte[]> message = createDisconnectMessage(session);
|
||||||
if (this.eventPublisher != null) {
|
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);
|
SimpAttributes simpAttributes = SimpAttributes.fromMessage(message);
|
||||||
try {
|
try {
|
||||||
SimpAttributesContextHolder.setAttributes(simpAttributes);
|
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);
|
StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.DISCONNECT);
|
||||||
if (getHeaderInitializer() != null) {
|
if (getHeaderInitializer() != null) {
|
||||||
getHeaderInitializer().initHeaders(headerAccessor);
|
getHeaderInitializer().initHeaders(headerAccessor);
|
||||||
|
|||||||
Reference in New Issue
Block a user