@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 { 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); } }
request.toObservable() .map(buf -> ((Buffer)buf.getDelegate()).getBytes()) .lift(new JsonParserOperator()) // convert JSON file to JSON events HttpServerResponse res = request.response(); res.setStatusCode(200).end("{\"count:\": " + v + "}"); }, err -> { HttpServerResponse res = request.response(); if (err instanceof IllegalStateException) { res.setStatusCode(400);
public void handle(io.vertx.core.http.HttpServerRequest event) { handler.handle(io.vertx.rxjava.core.http.HttpServerRequest.newInstance(event)); } });
@Test public void testPost() { int times = 5; waitFor(times); HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080)); server.requestStream().handler(req -> req.bodyHandler(buff -> { assertEquals("onetwothree", buff.toString()); req.response().end(); })); try { server.listen(ar -> { client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions())); Observable<Buffer> stream = Observable.just(Buffer.buffer("one"), Buffer.buffer("two"), Buffer.buffer("three")); Single<HttpResponse<Buffer>> single = client .post(8080, "localhost", "/the_uri") .rxSendStream(stream); for (int i = 0; i < times; i++) { single.subscribe(resp -> complete(), this::fail); } }); await(); } finally { server.close(); } }
@Override public void onNext(HttpServerRequest 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(); } }); }
/** * Something has happened, so handle it. * @param event the event to handle */ public void handle(io.vertx.rxjava.core.http.HttpServerRequest event) { delegate.handle(event.getDelegate()); }
protected void requireLogin(RoutingContext context, BiConsumer<RoutingContext, JsonObject> biHandler) { Optional<JsonObject> principal = Optional.ofNullable(context.request().getHeader("user-principal")) .map(JsonObject::new); if (principal.isPresent()) { biHandler.accept(context, principal.get()); } else { context.response() .setStatusCode(401) .end(new JsonObject().put("message", "need_auth").encode()); } }
public static HttpServerRequest newInstance(io.vertx.core.http.HttpServerRequest arg) { return arg != null ? new HttpServerRequest(arg) : null; } }
@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); } }
public void handle(io.vertx.core.http.HttpServerRequest event) { handler.handle(io.vertx.rxjava.core.http.HttpServerRequest.newInstance(event)); } });
/** * Something has happened, so handle it. * @param event the event to handle */ public void handle(io.vertx.rxjava.core.http.HttpServerRequest event) { delegate.handle(event.getDelegate()); }
public static HttpServerRequest newInstance(io.vertx.core.http.HttpServerRequest arg) { return arg != null ? new HttpServerRequest(arg) : null; } }
@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); } }
/** * @return the HTTP request object */ public io.vertx.rxjava.core.http.HttpServerRequest request() { if (cached_0 != null) { return cached_0; } io.vertx.rxjava.core.http.HttpServerRequest ret = io.vertx.rxjava.core.http.HttpServerRequest.newInstance(delegate.request()); cached_0 = ret; return ret; }
/** * This method is used to provide a request to the router. Usually you take request from the * {@link io.vertx.rxjava.core.http.HttpServer#requestHandler} and pass it to this method. The * router then routes it to matching routes. * * This method is now deprecated you can use this object directly as a request handler, which * means there is no need for a method reference anymore. * @param request the request */ @Deprecated() public void accept(io.vertx.rxjava.core.http.HttpServerRequest request) { delegate.accept(request.getDelegate()); }
@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); } }
/** * @return the HTTP request object */ public io.vertx.rxjava.core.http.HttpServerRequest request() { if (cached_0 != null) { return cached_0; } io.vertx.rxjava.core.http.HttpServerRequest ret = io.vertx.rxjava.core.http.HttpServerRequest.newInstance(delegate.request()); cached_0 = ret; return ret; }
/** * This method is used to provide a request to the router. Usually you take request from the * {@link io.vertx.rxjava.core.http.HttpServer#requestHandler} and pass it to this method. The * router then routes it to matching routes. * * This method is now deprecated you can use this object directly as a request handler, which * means there is no need for a method reference anymore. * @param request the request */ @Deprecated() public void accept(io.vertx.rxjava.core.http.HttpServerRequest request) { delegate.accept(request.getDelegate()); }
@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); } }