diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/NettyWebSocketSessionSupport.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/NettyWebSocketSessionSupport.java index 4c7d16644ea..e12af66f8d2 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/NettyWebSocketSessionSupport.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/NettyWebSocketSessionSupport.java @@ -61,9 +61,20 @@ public abstract class NettyWebSocketSessionSupport extends AbstractWebSocketS messageTypes.put(PongWebSocketFrame.class, WebSocketMessage.Type.PONG); } - + /** + * Constructor that uses the hashcode of the delegate as the session id. + */ protected NettyWebSocketSessionSupport(T delegate, HandshakeInfo info, NettyDataBufferFactory factory) { - super(delegate, ObjectUtils.getIdentityHexString(delegate), info, factory); + this(delegate, ObjectUtils.getIdentityHexString(delegate), info, factory); + } + + /** + * Variant of {@link #NettyWebSocketSessionSupport(Object, HandshakeInfo, NettyDataBufferFactory)} + * with a given WebSocket session id. + * @since 6.2.15 + */ + protected NettyWebSocketSessionSupport(T delegate, String id, HandshakeInfo info, NettyDataBufferFactory factory) { + super(delegate, id, info, factory); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/ReactorNettyWebSocketSession.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/ReactorNettyWebSocketSession.java index ea03f82b67d..37b63977ac4 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/ReactorNettyWebSocketSession.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/ReactorNettyWebSocketSession.java @@ -64,14 +64,18 @@ public class ReactorNettyWebSocketSession * Constructor with an additional maxFramePayloadLength argument. * @since 5.1 */ - @SuppressWarnings("rawtypes") public ReactorNettyWebSocketSession(WebsocketInbound inbound, WebsocketOutbound outbound, HandshakeInfo info, NettyDataBufferFactory bufferFactory, int maxFramePayloadLength) { - super(new WebSocketConnection(inbound, outbound), info, bufferFactory); + super(new WebSocketConnection(inbound, outbound), getChannelId(inbound).asLongText(), info, bufferFactory); this.maxFramePayloadLength = maxFramePayloadLength; - this.channelId = ((ChannelOperations) inbound).channel().id(); + this.channelId = getChannelId(inbound); + } + + @SuppressWarnings("rawtypes") + private static ChannelId getChannelId(WebsocketInbound inbound) { + return ((ChannelOperations) inbound).channel().id(); }