Browse Source

Use channelId for ReactorNettyWebSocketSession's id

Closes gh-35883
pull/35943/head
rstoyanchev 2 weeks ago
parent
commit
4ae03ecd40
  1. 15
      spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/NettyWebSocketSessionSupport.java
  2. 10
      spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/ReactorNettyWebSocketSession.java

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

@ -61,9 +61,20 @@ public abstract class NettyWebSocketSessionSupport<T> extends AbstractWebSocketS @@ -61,9 +61,20 @@ public abstract class NettyWebSocketSessionSupport<T> 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);
}

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

@ -64,14 +64,18 @@ public class ReactorNettyWebSocketSession @@ -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();
}

Loading…
Cancel
Save