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());
});
}
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);
});
}
Aggregations