Java Code Examples for io.rsocket.transport.ServerTransport#ConnectionAcceptor
The following examples show how to use
io.rsocket.transport.ServerTransport#ConnectionAcceptor .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RSocketServer.java From rsocket-java with Apache License 2.0 | 5 votes |
/** * An alternative to {@link #bind(ServerTransport)} that is useful for installing RSocket on a * server that is started independently. * * @see io.rsocket.examples.transport.ws.WebSocketHeadersSample */ public ServerTransport.ConnectionAcceptor asConnectionAcceptor() { return new ServerTransport.ConnectionAcceptor() { private final ServerSetup serverSetup = serverSetup(); @Override public Mono<Void> apply(DuplexConnection connection) { return acceptor(serverSetup, connection); } }; }
Example 2
Source File: WebSocketTransportIntegrationTest.java From rsocket-java with Apache License 2.0 | 5 votes |
@Test public void sendStreamOfDataWithExternalHttpServerTest() { ServerTransport.ConnectionAcceptor acceptor = RSocketServer.create( SocketAcceptor.forRequestStream( payload -> Flux.range(0, 10).map(i -> DefaultPayload.create(String.valueOf(i))))) .asConnectionAcceptor(); DisposableServer server = HttpServer.create() .host("localhost") .route(router -> router.ws("/test", WebsocketRouteTransport.newHandler(acceptor))) .bindNow(); RSocket rsocket = RSocketConnector.connectWith( WebsocketClientTransport.create( URI.create("ws://" + server.host() + ":" + server.port() + "/test"))) .block(); StepVerifier.create(rsocket.requestStream(EmptyPayload.INSTANCE)) .expectSubscription() .expectNextCount(10) .expectComplete() .verify(Duration.ofMillis(1000)); }
Example 3
Source File: WebSocketHeadersSample.java From rsocket-java with Apache License 2.0 | 4 votes |
public static void main(String[] args) { ServerTransport.ConnectionAcceptor connectionAcceptor = RSocketServer.create(SocketAcceptor.forRequestResponse(Mono::just)) .payloadDecoder(PayloadDecoder.ZERO_COPY) .asConnectionAcceptor(); DisposableServer server = HttpServer.create() .host("localhost") .port(0) .route( routes -> routes.get( "/", (req, res) -> { if (req.requestHeaders().containsValue("Authorization", "test", true)) { return res.sendWebsocket( (in, out) -> connectionAcceptor .apply(new WebsocketDuplexConnection((Connection) in)) .then(out.neverComplete())); } res.status(HttpResponseStatus.UNAUTHORIZED); return res.send(); })) .bindNow(); logger.debug( "\n\nStart of Authorized WebSocket Connection\n----------------------------------\n"); WebsocketClientTransport transport = WebsocketClientTransport.create(server.host(), server.port()) .header("Authorization", "test"); RSocket clientRSocket = RSocketConnector.create() .keepAlive(Duration.ofMinutes(10), Duration.ofMinutes(10)) .payloadDecoder(PayloadDecoder.ZERO_COPY) .connect(transport) .block(); Flux.range(1, 100) .concatMap(i -> clientRSocket.requestResponse(ByteBufPayload.create("Hello " + i))) .doOnNext(payload -> logger.debug("Processed " + payload.getDataUtf8())) .blockLast(); clientRSocket.dispose(); logger.debug( "\n\nStart of Unauthorized WebSocket Upgrade\n----------------------------------\n"); RSocketConnector.create() .keepAlive(Duration.ofMinutes(10), Duration.ofMinutes(10)) .payloadDecoder(PayloadDecoder.ZERO_COPY) .connect(WebsocketClientTransport.create(server.host(), server.port())) .block(); }
Example 4
Source File: RSocketFactory.java From rsocket-java with Apache License 2.0 | 4 votes |
@Override public ServerTransport.ConnectionAcceptor toConnectionAcceptor() { return server.asConnectionAcceptor(); }
Example 5
Source File: RSocketFactory.java From rsocket-java with Apache License 2.0 | votes |
ServerTransport.ConnectionAcceptor toConnectionAcceptor();