use of io.vertx.rxjava.core.http.HttpServerResponse in project vertx-examples by vert-x3.
the class Server method start.
@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);
}
use of io.vertx.rxjava.core.http.HttpServerResponse in project vertx-openshift-it by cescoffier.
the class AbstractDatabaseVerticle method getOne.
protected void getOne(RoutingContext ctx) {
HttpServerResponse response = ctx.response().putHeader("Content-Type", "application/json");
store.read(ctx.get("id")).subscribe(json -> response.end(json.encodePrettily()), err -> {
if (err instanceof NoSuchElementException) {
error(ctx, 404, err);
} else if (err instanceof IllegalArgumentException) {
error(ctx, 415, err);
} else {
error(ctx, 500, err);
}
});
}
use of io.vertx.rxjava.core.http.HttpServerResponse in project vertx-openshift-it by cescoffier.
the class AbstractDatabaseVerticle method getAll.
protected void getAll(RoutingContext ctx) {
HttpServerResponse response = ctx.response().putHeader("Content-Type", "application/json");
JsonArray res = new JsonArray();
store.readAll().subscribe(res::add, err -> error(ctx, 415, err), () -> response.end(res.encodePrettily()));
}
Aggregations