use of org.springframework.web.reactive.socket.adapter.RxNettyWebSocketSession in project spring-framework by spring-projects.
the class RxNettyRequestUpgradeStrategy method upgrade.
@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, Optional<String> subProtocol) {
RxNettyServerHttpResponse response = (RxNettyServerHttpResponse) exchange.getResponse();
HttpServerResponse<?> rxNettyResponse = response.getRxNettyResponse();
HandshakeInfo info = getHandshakeInfo(exchange, subProtocol);
NettyDataBufferFactory factory = (NettyDataBufferFactory) response.bufferFactory();
WebSocketHandshaker handshaker = rxNettyResponse.acceptWebSocketUpgrade(conn -> {
RxNettyWebSocketSession session = new RxNettyWebSocketSession(conn, info, factory);
String name = HttpHandlerNames.WsServerDecoder.getName();
session.aggregateFrames(rxNettyResponse.unsafeNettyChannel(), name);
return RxReactiveStreams.toObservable(handler.handle(session));
});
if (subProtocol.isPresent()) {
handshaker = handshaker.subprotocol(subProtocol.get());
} else {
// TODO: https://github.com/reactor/reactor-netty/issues/20
handshaker = handshaker.subprotocol(new String[0]);
}
return Mono.from(RxReactiveStreams.toPublisher(handshaker));
}
use of org.springframework.web.reactive.socket.adapter.RxNettyWebSocketSession in project spring-framework by spring-projects.
the class RxNettyWebSocketClient method executeInternal.
@SuppressWarnings("cast")
private Observable<Void> executeInternal(URI url, HttpHeaders headers, WebSocketHandler handler) {
String[] protocols = beforeHandshake(url, headers, handler);
return createRequest(url, headers, protocols).flatMap(response -> {
Observable<WebSocketConnection> conn = response.getWebSocketConnection();
return (Observable<Tuple2<WebSocketResponse<ByteBuf>, WebSocketConnection>>) Observable.zip(Observable.just(response), conn, Tuples::of);
}).flatMap(tuple -> {
WebSocketResponse<ByteBuf> response = tuple.getT1();
WebSocketConnection conn = tuple.getT2();
HandshakeInfo info = afterHandshake(url, toHttpHeaders(response));
ByteBufAllocator allocator = response.unsafeNettyChannel().alloc();
NettyDataBufferFactory factory = new NettyDataBufferFactory(allocator);
RxNettyWebSocketSession session = new RxNettyWebSocketSession(conn, info, factory);
session.aggregateFrames(response.unsafeNettyChannel(), WsClientDecoder.getName());
return RxReactiveStreams.toObservable(handler.handle(session));
});
}
Aggregations