Search in sources :

Example 1 with HttpResponse

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

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));
}
Also used : HttpResponse(io.vertx.rxjava.ext.web.client.HttpResponse) WebClient(io.vertx.rxjava.ext.web.client.WebClient)

Example 3 with HttpResponse

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()));
}
Also used : HttpResponse(io.vertx.rxjava.ext.web.client.HttpResponse) WebClient(io.vertx.rxjava.ext.web.client.WebClient)

Aggregations

HttpResponse (io.vertx.rxjava.ext.web.client.HttpResponse)3 WebClient (io.vertx.rxjava.ext.web.client.WebClient)3 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 JsonObject (io.vertx.core.json.JsonObject)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 CircuitBreaker (io.vertx.rxjava.circuitbreaker.CircuitBreaker)1 HystrixMetricHandler (io.vertx.rxjava.circuitbreaker.HystrixMetricHandler)1 AbstractVerticle (io.vertx.rxjava.core.AbstractVerticle)1 Router (io.vertx.rxjava.ext.web.Router)1 RoutingContext (io.vertx.rxjava.ext.web.RoutingContext)1 StaticHandler (io.vertx.rxjava.ext.web.handler.StaticHandler)1 SockJSHandler (io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler)1