Skip to content

Commit 4ae03ec

Browse files
committed
Use channelId for ReactorNettyWebSocketSession's id
Closes gh-35883
1 parent 1603045 commit 4ae03ec

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/NettyWebSocketSessionSupport.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,20 @@ public abstract class NettyWebSocketSessionSupport<T> extends AbstractWebSocketS
6161
messageTypes.put(PongWebSocketFrame.class, WebSocketMessage.Type.PONG);
6262
}
6363

64-
64+
/**
65+
* Constructor that uses the hashcode of the delegate as the session id.
66+
*/
6567
protected NettyWebSocketSessionSupport(T delegate, HandshakeInfo info, NettyDataBufferFactory factory) {
66-
super(delegate, ObjectUtils.getIdentityHexString(delegate), info, factory);
68+
this(delegate, ObjectUtils.getIdentityHexString(delegate), info, factory);
69+
}
70+
71+
/**
72+
* Variant of {@link #NettyWebSocketSessionSupport(Object, HandshakeInfo, NettyDataBufferFactory)}
73+
* with a given WebSocket session id.
74+
* @since 6.2.15
75+
*/
76+
protected NettyWebSocketSessionSupport(T delegate, String id, HandshakeInfo info, NettyDataBufferFactory factory) {
77+
super(delegate, id, info, factory);
6778
}
6879

6980

spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/ReactorNettyWebSocketSession.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,18 @@ public ReactorNettyWebSocketSession(WebsocketInbound inbound, WebsocketOutbound
6464
* Constructor with an additional maxFramePayloadLength argument.
6565
* @since 5.1
6666
*/
67-
@SuppressWarnings("rawtypes")
6867
public ReactorNettyWebSocketSession(WebsocketInbound inbound, WebsocketOutbound outbound,
6968
HandshakeInfo info, NettyDataBufferFactory bufferFactory,
7069
int maxFramePayloadLength) {
7170

72-
super(new WebSocketConnection(inbound, outbound), info, bufferFactory);
71+
super(new WebSocketConnection(inbound, outbound), getChannelId(inbound).asLongText(), info, bufferFactory);
7372
this.maxFramePayloadLength = maxFramePayloadLength;
74-
this.channelId = ((ChannelOperations) inbound).channel().id();
73+
this.channelId = getChannelId(inbound);
74+
}
75+
76+
@SuppressWarnings("rawtypes")
77+
private static ChannelId getChannelId(WebsocketInbound inbound) {
78+
return ((ChannelOperations) inbound).channel().id();
7579
}
7680

7781

0 commit comments

Comments
 (0)