@Override public void start() throws Exception { HttpClient client = vertx.createHttpClient(); // Create two requests HttpClientRequest req1 = client.request(HttpMethod.GET, 8080, "localhost", "/"); HttpClientRequest req2 = client.request(HttpMethod.GET, 8080, "localhost", "/"); // Turn the requests responses into Observable<JsonObject> Observable<JsonObject> obs1 = req1.toObservable().flatMap(HttpClientResponse::toObservable). map(buf -> new JsonObject(buf.toString("UTF-8"))); Observable<JsonObject> obs2 = req2.toObservable().flatMap(HttpClientResponse::toObservable). map(buf -> new JsonObject(buf.toString("UTF-8"))); // Combine the responses with the zip into a single response obs1.zipWith(obs2, (b1, b2) -> new JsonObject().put("req1", b1).put("req2", b2)). subscribe(json -> { System.out.println("Got combined result " + json); }, err -> { err.printStackTrace(); }); req1.end(); req2.end(); } }
public void handle(AsyncResult<io.vertx.core.http.HttpClient> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpClient.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } });
/** * @see #get(HttpClient, int, String, String, MultiMap) */ public static Observable<HttpClientResponse> get(HttpClient client, String host, String requestURI) { return Observable.create(subscriber -> { HttpClientRequest req = client.get(host, requestURI); Observable<HttpClientResponse> resp = req.toObservable(); resp.subscribe(subscriber); req.end(); }); }
/** * Sends an HTTP GET request to the server with the specified options, specifying a response handler to receive * the response * @param options the request options * @return a reference to this, so the API can be used fluently */ public Single<io.vertx.rxjava.core.http.HttpClientResponse> rxGetNow(RequestOptions options) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { getNow(options, fut); })); }
/** * Sends an HTTP OPTIONS request to the server at the default host and port, specifying a response handler to receive * the response * @param requestURI the relative URI * @return a reference to this, so the API can be used fluently */ public Single<io.vertx.rxjava.core.http.HttpClientResponse> rxOptionsNow(String requestURI) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { optionsNow(requestURI, fut); })); }
/** * Sends an HTTP HEAD request to the server at the default host and port, specifying a response handler to receive * the response * @param requestURI the relative URI * @return a reference to this, so the API can be used fluently */ public Single<io.vertx.rxjava.core.http.HttpClientResponse> rxHeadNow(String requestURI) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { headNow(requestURI, fut); })); }
/** * Wrap an <code>httpClient</code> with a web client and default options. * <p> * Only the specific web client portion of the <code>options</code> is used, the {@link io.vertx.core.http.HttpClientOptions} * of the <code>httpClient</code> is reused. * @param httpClient the to wrap * @param options the Web Client options * @return the web client */ public static io.vertx.rxjava.ext.web.client.WebClient wrap(io.vertx.rxjava.core.http.HttpClient httpClient, WebClientOptions options) { io.vertx.rxjava.ext.web.client.WebClient ret = io.vertx.rxjava.ext.web.client.WebClient.newInstance(io.vertx.ext.web.client.WebClient.wrap(httpClient.getDelegate(), options)); return ret; }
public static HttpClient newInstance(io.vertx.core.http.HttpClient arg) { return arg != null ? new HttpClient(arg) : null; } }
void sendDatapoint(String dbname, String msg) { LOG.trace("Sending measures length = {} Bytes ", msg.length()); this.http.post("/write?db=" + dbname, response -> { if (response.statusCode() >= 400) { LOG.warn("{} {}", response.statusCode(), response.statusMessage()); response.bodyHandler(data -> LOG.warn(data.toString())); } }).end(msg); }
HttpClientRequest req = client.getAbs(downloadUrl);
public void handle(AsyncResult<io.vertx.core.http.HttpClient> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpClient.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } });
/** * @see #get(HttpClient, int, String, String, MultiMap) */ public static Observable<HttpClientResponse> get(HttpClient client, String requestURI) { return Observable.create(subscriber -> { HttpClientRequest req = client.get(requestURI); Observable<HttpClientResponse> resp = req.toObservable(); resp.subscribe(subscriber); req.end(); }); }
/** * Sends an HTTP GET request to the server at the specified host and default port, specifying a response handler to receive * the response * @param host the host * @param requestURI the relative URI * @return a reference to this, so the API can be used fluently */ public Single<io.vertx.rxjava.core.http.HttpClientResponse> rxGetNow(String host, String requestURI) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { getNow(host, requestURI, fut); })); }
/** * Sends an HTTP OPTIONS request to the server at the specified host and default port, specifying a response handler to receive * the response * @param host the host * @param requestURI the relative URI * @return a reference to this, so the API can be used fluently */ public Single<io.vertx.rxjava.core.http.HttpClientResponse> rxOptionsNow(String host, String requestURI) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { optionsNow(host, requestURI, fut); })); }
/** * Sends an HTTP HEAD request to the server with the specified options, specifying a response handler to receive * the response * @param options the request options * @return a reference to this, so the API can be used fluently */ public Single<io.vertx.rxjava.core.http.HttpClientResponse> rxHeadNow(RequestOptions options) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { headNow(options, fut); })); }
/** * Wrap an <code>httpClient</code> with a web client and default options. * @param httpClient the to wrap * @return the web client */ public static io.vertx.rxjava.ext.web.client.WebClient wrap(io.vertx.rxjava.core.http.HttpClient httpClient) { io.vertx.rxjava.ext.web.client.WebClient ret = io.vertx.rxjava.ext.web.client.WebClient.newInstance(io.vertx.ext.web.client.WebClient.wrap(httpClient.getDelegate())); return ret; }
public static HttpClient newInstance(io.vertx.core.http.HttpClient arg) { return arg != null ? new HttpClient(arg) : null; } }
@Override public void start() throws Exception { HttpClient client = vertx.createHttpClient(); HttpClientRequest req = client.request(HttpMethod.GET, 8080, "localhost", "/"); req.toObservable(). flatMap(HttpClientResponse::toObservable). // Unmarshall the response to the Data object via Jackon lift(io.vertx.rxjava.core.RxHelper.unmarshaller(Data.class)). subscribe( data -> { System.out.println("Got response " + data.message); }); // End request req.end(); } }
public void handle(AsyncResult<io.vertx.core.http.HttpClient> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpClient.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } });
/** * @see #get(HttpClient, int, String, String, MultiMap) */ public static Observable<HttpClientResponse> get(HttpClient client, int port, String host, String requestURI) { return Observable.create(subscriber -> { HttpClientRequest req = client.get(port, host, requestURI); Observable<HttpClientResponse> resp = req.toObservable(); resp.subscribe(subscriber); req.end(); }); }