@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toObservable().subscribe(req -> { req.response().putHeader("content-type", "application/json").end(new JsonObject().put("time", System.currentTimeMillis()).toString()); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toObservable().subscribe(req -> { req.response().putHeader("content-type", "application/json").end(new JsonObject().put("time", System.currentTimeMillis()).toString()); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toObservable().subscribe(req -> { req.response().putHeader("content-type", "text/html").end("<html><body><h1>Hello from vert.x!</h1></body></html>"); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toObservable().subscribe(req -> { req.response().putHeader("content-type", "application/json").end("{\"message\":\"Hello World\"}"); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toObservable().subscribe(req -> { req.response().putHeader("content-type", "application/json").end("{\"message\":\"Hello World\"}"); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toObservable().subscribe(req -> { req.response().putHeader("content-type", "text/html").end("<html><body><h1>Hello from vert.x!</h1></body></html>"); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toObservable().subscribe(req -> { req.response().putHeader("content-type", "text/html").end("<html><body><h1>Hello from vert.x!</h1></body></html>"); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toObservable().subscribe(req -> { HttpServerResponse resp = req.response(); String contentType = req.getHeader("Content-Type"); if (contentType != null) { resp.putHeader("Content-Type", contentType); } resp.setChunked(true); req.toObservable().subscribe( resp::write, err -> {}, resp::end ); }); server.listen(8080); } }
@Override public void start() throws Exception { Router router = Router.router(vertx); router.route().handler(routingContext -> { routingContext.response().putHeader("content-type", "text/html").end("Hello World!"); }); vertx.createHttpServer().requestHandler(router).listen(8080); } }
@Override public void start() throws Exception { Router router = Router.router(vertx); router.route("/news-feed/*").handler(SockJSHandler.create(vertx).socketHandler(sockJSSocket -> { // Consumer the event bus address as an Observable Observable<String> msg = vertx.eventBus().<String>consumer("news-feed") .bodyStream() .toObservable(); // Send the event to the client Subscription subscription = msg.subscribe(sockJSSocket::write); // Unsubscribe when the socket closes sockJSSocket.endHandler(v -> { subscription.unsubscribe(); }); })); // Serve the static resources router.route().handler(StaticHandler.create()); vertx.createHttpServer().requestHandler(router).listen(8080); // Publish a message to the address "news-feed" every second vertx.setPeriodic(1000, t -> vertx.eventBus().publish("news-feed", "news from the server!")); } }
/** * Like {@link io.vertx.rxjava.core.http.HttpServer#listen} but supplying a handler that will be called when the server is actually listening (or has failed). * @return * @deprecated use {@link #rxListen} instead */ @Deprecated() public Observable<io.vertx.rxjava.core.http.HttpServer> listenObservable() { io.vertx.rx.java.ObservableFuture<io.vertx.rxjava.core.http.HttpServer> listenHandler = io.vertx.rx.java.RxHelper.observableFuture(); listen(listenHandler.toHandler()); return listenHandler; }
/** * Like {@link io.vertx.rxjava.core.http.HttpServer#listen} but supplying a handler that will be called when the server is actually listening (or has failed). * @param port the port to listen on * @return * @deprecated use {@link #rxListen} instead */ @Deprecated() public Observable<io.vertx.rxjava.core.http.HttpServer> listenObservable(int port) { io.vertx.rx.java.ObservableFuture<io.vertx.rxjava.core.http.HttpServer> listenHandler = io.vertx.rx.java.RxHelper.observableFuture(); listen(port, listenHandler.toHandler()); return listenHandler; }
/** * Tell the server to start listening on the given address supplying * a handler that will be called when the server is actually * listening (or has failed). * @param address the address to listen on * @return */ public Single<io.vertx.rxjava.core.http.HttpServer> rxListen(io.vertx.rxjava.core.net.SocketAddress address) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { listen(address, fut); })); }
/** * Like {@link io.vertx.rxjava.core.http.HttpServer#listen} but supplying a handler that will be called when the server is actually * listening (or has failed). * @param port the port to listen on * @param host the host to listen on * @return */ public Single<io.vertx.rxjava.core.http.HttpServer> rxListen(int port, String host) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { listen(port, host, fut); })); }
/** * Like {@link io.vertx.rxjava.core.http.HttpServer#listen} but supplying a handler that will be called when the server is actually listening (or has failed). * @return */ public Single<io.vertx.rxjava.core.http.HttpServer> rxListen() { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { listen(fut); })); }
/** * Like {@link io.vertx.rxjava.core.http.HttpServer#listen} but supplying a handler that will be called when the server is actually listening (or has failed). * @param port the port to listen on * @return */ public Single<io.vertx.rxjava.core.http.HttpServer> rxListen(int port) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { listen(port, fut); })); }
/** * Like {@link io.vertx.rxjava.core.http.HttpServer#listen} but supplying a handler that will be called when the server is actually * listening (or has failed). * @param port the port to listen on * @param host the host to listen on * @return */ public Single<io.vertx.rxjava.core.http.HttpServer> rxListen(int port, String host) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { listen(port, host, fut); })); }
/** * Tell the server to start listening on the given address supplying * a handler that will be called when the server is actually * listening (or has failed). * @param address the address to listen on * @return */ public Single<io.vertx.rxjava.core.http.HttpServer> rxListen(io.vertx.rxjava.core.net.SocketAddress address) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { listen(address, fut); })); }
/** * Like {@link io.vertx.rxjava.core.http.HttpServer#listen} but supplying a handler that will be called when the server is actually listening (or has failed). * @return */ public Single<io.vertx.rxjava.core.http.HttpServer> rxListen() { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { listen(fut); })); }
/** * Like {@link io.vertx.rxjava.core.http.HttpServer#listen} but supplying a handler that will be called when the server is actually listening (or has failed). * @param port the port to listen on * @return */ public Single<io.vertx.rxjava.core.http.HttpServer> rxListen(int port) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { listen(port, fut); })); }