Search in sources :

Example 1 with HttpServerResponse

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);
}
Also used : HttpServerResponse(io.vertx.rxjava.core.http.HttpServerResponse) HttpServer(io.vertx.rxjava.core.http.HttpServer)

Example 2 with HttpServerResponse

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);
        }
    });
}
Also used : HttpServerResponse(io.vertx.rxjava.core.http.HttpServerResponse) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with HttpServerResponse

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()));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) HttpServerResponse(io.vertx.rxjava.core.http.HttpServerResponse)

Aggregations

HttpServerResponse (io.vertx.rxjava.core.http.HttpServerResponse)3 JsonArray (io.vertx.core.json.JsonArray)1 HttpServer (io.vertx.rxjava.core.http.HttpServer)1 NoSuchElementException (java.util.NoSuchElementException)1