use of io.vertx.rxjava.ext.web.client.HttpResponse 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.client.HttpResponse in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
Single<HttpResponse<Data>> request = client.get(8080, "localhost", "/").as(BodyCodec.json(Data.class)).rxSend();
// Fire the request
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
// Again
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
// And again
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
}
use of io.vertx.rxjava.ext.web.client.HttpResponse in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
Single<HttpResponse<String>> request = client.get(8080, "localhost", "/").as(BodyCodec.string()).rxSend();
// Fire the request
request.subscribe(resp -> System.out.println("Server content " + resp.body()));
// Again
request.subscribe(resp -> System.out.println("Server content " + resp.body()));
// And again
request.subscribe(resp -> System.out.println("Server content " + resp.body()));
}
Aggregations