|
|
|
@ -51,10 +51,6 @@ public class ReactorNettyWebSocketClient implements WebSocketClient { |
|
|
|
|
|
|
|
|
|
|
|
private final Supplier<WebsocketClientSpec.Builder> specBuilderSupplier; |
|
|
|
private final Supplier<WebsocketClientSpec.Builder> specBuilderSupplier; |
|
|
|
|
|
|
|
|
|
|
|
private @Nullable Integer maxFramePayloadLength; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private @Nullable Boolean handlePing; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Default constructor. |
|
|
|
* Default constructor. |
|
|
|
@ -102,20 +98,14 @@ public class ReactorNettyWebSocketClient implements WebSocketClient { |
|
|
|
* @since 5.3 |
|
|
|
* @since 5.3 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public WebsocketClientSpec getWebsocketClientSpec() { |
|
|
|
public WebsocketClientSpec getWebsocketClientSpec() { |
|
|
|
return buildSpec(null); |
|
|
|
return buildWebSocketClientSpec(null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private WebsocketClientSpec buildSpec(@Nullable String protocols) { |
|
|
|
private WebsocketClientSpec buildWebSocketClientSpec(@Nullable String protocols) { |
|
|
|
WebsocketClientSpec.Builder builder = this.specBuilderSupplier.get(); |
|
|
|
WebsocketClientSpec.Builder builder = this.specBuilderSupplier.get(); |
|
|
|
if (StringUtils.hasText(protocols)) { |
|
|
|
if (StringUtils.hasText(protocols)) { |
|
|
|
builder.protocols(protocols); |
|
|
|
builder.protocols(protocols); |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.maxFramePayloadLength != null) { |
|
|
|
|
|
|
|
builder.maxFramePayloadLength(this.maxFramePayloadLength); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.handlePing != null) { |
|
|
|
|
|
|
|
builder.handlePing(this.handlePing); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return builder.build(); |
|
|
|
return builder.build(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -127,18 +117,18 @@ public class ReactorNettyWebSocketClient implements WebSocketClient { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Mono<Void> execute(URI url, HttpHeaders requestHeaders, WebSocketHandler handler) { |
|
|
|
public Mono<Void> execute(URI url, HttpHeaders requestHeaders, WebSocketHandler handler) { |
|
|
|
String protocols = StringUtils.collectionToCommaDelimitedString(handler.getSubProtocols()); |
|
|
|
String protocols = StringUtils.collectionToCommaDelimitedString(handler.getSubProtocols()); |
|
|
|
WebsocketClientSpec wsClientSpec = buildSpec(protocols); |
|
|
|
WebsocketClientSpec clientSpec = buildWebSocketClientSpec(protocols); |
|
|
|
return getHttpClient() |
|
|
|
return getHttpClient() |
|
|
|
.headers(nettyHeaders -> setNettyHeaders(requestHeaders, nettyHeaders)) |
|
|
|
.headers(nettyHeaders -> setNettyHeaders(requestHeaders, nettyHeaders)) |
|
|
|
.websocket(wsClientSpec) |
|
|
|
.websocket(clientSpec) |
|
|
|
.uri(url.toString()) |
|
|
|
.uri(url.toString()) |
|
|
|
.handle((inbound, outbound) -> { |
|
|
|
.handle((inbound, outbound) -> { |
|
|
|
HttpHeaders responseHeaders = toHttpHeaders(inbound); |
|
|
|
HttpHeaders responseHeaders = toHttpHeaders(inbound); |
|
|
|
String protocol = responseHeaders.getFirst("Sec-WebSocket-Protocol"); |
|
|
|
String protocol = responseHeaders.getFirst("Sec-WebSocket-Protocol"); |
|
|
|
HandshakeInfo info = new HandshakeInfo(url, responseHeaders, Mono.empty(), protocol); |
|
|
|
HandshakeInfo info = new HandshakeInfo(url, responseHeaders, Mono.empty(), protocol); |
|
|
|
NettyDataBufferFactory factory = new NettyDataBufferFactory(outbound.alloc()); |
|
|
|
NettyDataBufferFactory factory = new NettyDataBufferFactory(outbound.alloc()); |
|
|
|
WebSocketSession session = new ReactorNettyWebSocketSession(inbound, outbound, info, factory, |
|
|
|
WebSocketSession session = new ReactorNettyWebSocketSession( |
|
|
|
wsClientSpec.maxFramePayloadLength()); |
|
|
|
inbound, outbound, info, factory, clientSpec.maxFramePayloadLength()); |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
logger.debug("Started session '" + session.getId() + "' for " + url); |
|
|
|
logger.debug("Started session '" + session.getId() + "' for " + url); |
|
|
|
} |
|
|
|
} |
|
|
|
|