public static ServerWebSocket newInstance(io.vertx.core.http.ServerWebSocket arg) { return arg != null ? new ServerWebSocket(arg) : null; } }
public void handle(io.vertx.core.http.ServerWebSocket event) { handler.handle(io.vertx.rxjava.core.http.ServerWebSocket.newInstance(event)); } });
@Test public void testWebsocketClientFlatMap() { HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080)); server.websocketStream().handler(ws -> { ws.write(Buffer.buffer("some_content")); ws.close(); }); server.listen(ar -> { HttpClient client = vertx.createHttpClient(new HttpClientOptions()); Buffer content = Buffer.buffer(); client. websocketStream(8080, "localhost", "/the_uri"). toObservable(). flatMap(WebSocket::toObservable). forEach(content::appendBuffer, err -> fail(), () -> { server.close(); assertEquals("some_content", content.toString("UTF-8")); testComplete(); }); }); await(); }
public synchronized io.vertx.rx.java.WriteStreamSubscriber<io.vertx.rxjava.core.buffer.Buffer> toSubscriber() { if (subscriber == null) { java.util.function.Function<io.vertx.rxjava.core.buffer.Buffer, io.vertx.core.buffer.Buffer> conv = io.vertx.rxjava.core.buffer.Buffer::getDelegate; subscriber = io.vertx.rx.java.RxHelper.toSubscriber(getDelegate(), conv); } return subscriber; }
@Override public void onNext(ServerWebSocket o) { Observable<Buffer> dataObs = o.toObservable(); dataObs.subscribe(new Observer<Buffer>() { LinkedList<Buffer> buffers = new LinkedList<>(); @Override public void onNext(Buffer buffer) { buffers.add(buffer); } @Override public void onError(Throwable e) { fail(e.getMessage()); } @Override public void onCompleted() { assertEquals(1, buffers.size()); assertEquals("foo", buffers.get(0).toString("UTF-8")); server.close(); } }); }
@Test public void testWebsocketClient() { HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080)); server.websocketStream().handler(ws -> { ws.write(Buffer.buffer("some_content")); ws.close(); }); server.listen(ar -> { HttpClient client = vertx.createHttpClient(new HttpClientOptions()); client.websocket(8080, "localhost", "/the_uri", ws -> { Buffer content = Buffer.buffer(); Observable<Buffer> observable = ws.toObservable(); observable.forEach(content::appendBuffer, err -> fail(), () -> { server.close(); assertEquals("some_content", content.toString("UTF-8")); testComplete(); }); }); }); await(); }
public synchronized io.vertx.rx.java.WriteStreamSubscriber<io.vertx.rxjava.core.buffer.Buffer> toSubscriber() { if (subscriber == null) { java.util.function.Function<io.vertx.rxjava.core.buffer.Buffer, io.vertx.core.buffer.Buffer> conv = io.vertx.rxjava.core.buffer.Buffer::getDelegate; subscriber = io.vertx.rx.java.RxHelper.toSubscriber(getDelegate(), conv); } return subscriber; }
public void handle(io.vertx.core.http.ServerWebSocket event) { handler.handle(io.vertx.rxjava.core.http.ServerWebSocket.newInstance(event)); } });
public void handle(io.vertx.rxjava.core.http.ServerWebSocket event) { delegate.webSocketHandler().handle(event.getDelegate()); } };
public static ServerWebSocket newInstance(io.vertx.core.http.ServerWebSocket arg) { return arg != null ? new ServerWebSocket(arg) : null; } }
/** * Upgrade the connection to a WebSocket connection. * <p> * This is an alternative way of handling WebSockets and can only be used if no websocket handlers are set on the * Http server, and can only be used during the upgrade request during the WebSocket handshake. * @return the WebSocket */ public io.vertx.rxjava.core.http.ServerWebSocket upgrade() { io.vertx.rxjava.core.http.ServerWebSocket ret = io.vertx.rxjava.core.http.ServerWebSocket.newInstance(delegate.upgrade()); return ret; }
public void handle(io.vertx.rxjava.core.http.ServerWebSocket event) { delegate.webSocketHandler().handle(event.getDelegate()); } };
/** * Upgrade the connection to a WebSocket connection. * <p> * This is an alternative way of handling WebSockets and can only be used if no websocket handlers are set on the * Http server, and can only be used during the upgrade request during the WebSocket handshake. * @return the WebSocket */ public io.vertx.rxjava.core.http.ServerWebSocket upgrade() { io.vertx.rxjava.core.http.ServerWebSocket ret = io.vertx.rxjava.core.http.ServerWebSocket.newInstance(delegate.upgrade()); return ret; }