Search in sources :

Example 1 with RoutingContext

use of io.vertx.rxjava.ext.web.RoutingContext in project vertx-openshift-it by cescoffier.

the class GreetingServiceVerticle method greeting.

private void greeting(RoutingContext rc) {
    circuit.rxExecuteCommandWithFallback(future -> client.get("/api/name").rxSend().doOnEach(r -> System.out.println(r.getValue().bodyAsString())).map(HttpResponse::bodyAsJsonObject).map(json -> json.getString("name")).subscribe(future::complete, future::fail), error -> {
        System.out.println("Fallback called for " + error.getMessage());
        error.printStackTrace();
        return "Fallback";
    }).subscribe(name -> {
        JsonObject response = new JsonObject().put("content", String.format(template, name));
        rc.response().putHeader(CONTENT_TYPE.toString(), APPLICATION_JSON.toString()).end(response.encode());
    });
}
Also used : CircuitBreakerOptions(io.vertx.circuitbreaker.CircuitBreakerOptions) WebClientOptions(io.vertx.ext.web.client.WebClientOptions) HttpResponse(io.vertx.rxjava.ext.web.client.HttpResponse) Router(io.vertx.rxjava.ext.web.Router) RoutingContext(io.vertx.rxjava.ext.web.RoutingContext) CircuitBreaker(io.vertx.rxjava.circuitbreaker.CircuitBreaker) AbstractVerticle(io.vertx.rxjava.core.AbstractVerticle) WebClient(io.vertx.rxjava.ext.web.client.WebClient) PermittedOptions(io.vertx.ext.web.handler.sockjs.PermittedOptions) APPLICATION_JSON(io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_JSON) CONTENT_TYPE(io.vertx.core.http.HttpHeaders.CONTENT_TYPE) StaticHandler(io.vertx.rxjava.ext.web.handler.StaticHandler) HystrixMetricHandler(io.vertx.rxjava.circuitbreaker.HystrixMetricHandler) JsonObject(io.vertx.core.json.JsonObject) SockJSHandler(io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler) Handler(io.vertx.core.Handler) BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) HttpResponse(io.vertx.rxjava.ext.web.client.HttpResponse) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with RoutingContext

use of io.vertx.rxjava.ext.web.RoutingContext in project vertx-openshift-it by cescoffier.

the class OracleVerticle method addOne.

@Override
protected void addOne(RoutingContext ctx) {
    JsonObject item;
    try {
        item = ctx.getBodyAsJson();
    } catch (RuntimeException e) {
        error(ctx, 415, "invalid payload");
        return;
    }
    if (item == null) {
        error(ctx, 415, "invalid payload");
        return;
    }
    store.create(item).subscribe(json -> ((JdbcOracleVegetableStore) store).read(json.getString("rowId")).subscribe(entries -> ctx.response().putHeader("Location", "/api/vegetables/" + json.getLong("id")).putHeader("Content-Type", "application/json").setStatusCode(201).end(entries.encodePrettily())), err -> {
        writeError(ctx, err);
    });
}
Also used : Completable(rx.Completable) AbstractDatabaseVerticle(io.vertx.openshift.utils.AbstractDatabaseVerticle) Single(rx.Single) Router(io.vertx.rxjava.ext.web.Router) RoutingContext(io.vertx.rxjava.ext.web.RoutingContext) JsonObject(io.vertx.core.json.JsonObject) HttpServer(io.vertx.rxjava.core.http.HttpServer) Errors.error(io.vertx.openshift.utils.Errors.error) TestUtils(io.vertx.openshift.utils.TestUtils) JDBCClient(io.vertx.rxjava.ext.jdbc.JDBCClient) BodyHandler(io.vertx.rxjava.ext.web.handler.BodyHandler) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)2 Router (io.vertx.rxjava.ext.web.Router)2 RoutingContext (io.vertx.rxjava.ext.web.RoutingContext)2 APPLICATION_JSON (io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_JSON)1 CircuitBreakerOptions (io.vertx.circuitbreaker.CircuitBreakerOptions)1 Handler (io.vertx.core.Handler)1 CONTENT_TYPE (io.vertx.core.http.HttpHeaders.CONTENT_TYPE)1 WebClientOptions (io.vertx.ext.web.client.WebClientOptions)1 BridgeOptions (io.vertx.ext.web.handler.sockjs.BridgeOptions)1 PermittedOptions (io.vertx.ext.web.handler.sockjs.PermittedOptions)1 AbstractDatabaseVerticle (io.vertx.openshift.utils.AbstractDatabaseVerticle)1 Errors.error (io.vertx.openshift.utils.Errors.error)1 TestUtils (io.vertx.openshift.utils.TestUtils)1 CircuitBreaker (io.vertx.rxjava.circuitbreaker.CircuitBreaker)1 HystrixMetricHandler (io.vertx.rxjava.circuitbreaker.HystrixMetricHandler)1 AbstractVerticle (io.vertx.rxjava.core.AbstractVerticle)1 HttpServer (io.vertx.rxjava.core.http.HttpServer)1 JDBCClient (io.vertx.rxjava.ext.jdbc.JDBCClient)1 HttpResponse (io.vertx.rxjava.ext.web.client.HttpResponse)1 WebClient (io.vertx.rxjava.ext.web.client.WebClient)1