Search in sources :

Example 1 with WebSocketResponse

use of io.reactivex.netty.protocol.http.ws.client.WebSocketResponse 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));
    });
}
Also used : NettyDataBufferFactory(org.springframework.core.io.buffer.NettyDataBufferFactory) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Tuples(reactor.util.function.Tuples) Tuple2(reactor.util.function.Tuple2) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Observable(rx.Observable) ByteBuf(io.netty.buffer.ByteBuf) Map(java.util.Map) HttpClient(io.reactivex.netty.protocol.http.client.HttpClient) WebSocketHandler(org.springframework.web.reactive.socket.WebSocketHandler) URI(java.net.URI) HttpClientRequest(io.reactivex.netty.protocol.http.client.HttpClientRequest) RxEventLoopProvider(io.reactivex.netty.threads.RxEventLoopProvider) WebSocketResponse(io.reactivex.netty.protocol.http.ws.client.WebSocketResponse) HandshakeInfo(org.springframework.web.reactive.socket.HandshakeInfo) HttpHeaders(org.springframework.http.HttpHeaders) ObjectUtils(org.springframework.util.ObjectUtils) RxNettyWebSocketSession(org.springframework.web.reactive.socket.adapter.RxNettyWebSocketSession) WebSocketConnection(io.reactivex.netty.protocol.http.ws.WebSocketConnection) Mono(reactor.core.publisher.Mono) WebSocketRequest(io.reactivex.netty.protocol.http.ws.client.WebSocketRequest) List(java.util.List) RxReactiveStreams(rx.RxReactiveStreams) WsClientDecoder(io.reactivex.netty.protocol.http.HttpHandlerNames.WsClientDecoder) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) WebSocketConnection(io.reactivex.netty.protocol.http.ws.WebSocketConnection) RxNettyWebSocketSession(org.springframework.web.reactive.socket.adapter.RxNettyWebSocketSession) ByteBuf(io.netty.buffer.ByteBuf) NettyDataBufferFactory(org.springframework.core.io.buffer.NettyDataBufferFactory) Observable(rx.Observable) Tuple2(reactor.util.function.Tuple2) Tuples(reactor.util.function.Tuples) HandshakeInfo(org.springframework.web.reactive.socket.HandshakeInfo)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 WsClientDecoder (io.reactivex.netty.protocol.http.HttpHandlerNames.WsClientDecoder)1 HttpClient (io.reactivex.netty.protocol.http.client.HttpClient)1 HttpClientRequest (io.reactivex.netty.protocol.http.client.HttpClientRequest)1 WebSocketConnection (io.reactivex.netty.protocol.http.ws.WebSocketConnection)1 WebSocketRequest (io.reactivex.netty.protocol.http.ws.client.WebSocketRequest)1 WebSocketResponse (io.reactivex.netty.protocol.http.ws.client.WebSocketResponse)1 RxEventLoopProvider (io.reactivex.netty.threads.RxEventLoopProvider)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 NettyDataBufferFactory (org.springframework.core.io.buffer.NettyDataBufferFactory)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ObjectUtils (org.springframework.util.ObjectUtils)1 HandshakeInfo (org.springframework.web.reactive.socket.HandshakeInfo)1 WebSocketHandler (org.springframework.web.reactive.socket.WebSocketHandler)1