use of io.vertx.rxjava.core.http.HttpClient in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
HttpClient client = vertx.createHttpClient();
client.put(8080, "localhost", "/", resp -> {
System.out.println("Got response " + resp.statusCode());
resp.handler(buf -> System.out.println(buf.toString("UTF-8")));
}).setChunked(true).putHeader("Content-Type", "text/plain").write("hello").end();
}
use of io.vertx.rxjava.core.http.HttpClient in project vertx-openshift-it by cescoffier.
the class GatewayVerticle method webclient.
private void webclient(RoutingContext routingContext) {
String host = routingContext.request().getParam("host");
final HttpClient httpClient = vertx.createHttpClient(new HttpClientOptions().setDefaultHost(host).setKeepAlive(false));
forward(routingContext, httpClient, true);
}
use of io.vertx.rxjava.core.http.HttpClient in project georocket by georocket.
the class ElasticsearchInstaller method doDownload.
/**
* Download a file
* @param downloadUrl the URL to download from
* @param dest the destination file
* @return a single emitting exactly one item once the file has been
* downloaded
*/
private Single<Void> doDownload(String downloadUrl, AsyncFile dest) {
ObservableFuture<Void> observable = RxHelper.observableFuture();
Handler<AsyncResult<Void>> handler = observable.toHandler();
HttpClientOptions options = new HttpClientOptions();
if (downloadUrl.startsWith("https")) {
options.setSsl(true);
}
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest req = client.getAbs(downloadUrl);
req.exceptionHandler(t -> handler.handle(Future.failedFuture(t)));
req.handler(res -> {
if (res.statusCode() != 200) {
handler.handle(Future.failedFuture(new HttpException(res.statusCode(), res.statusMessage())));
return;
}
// get content-length
int length;
int[] read = { 0 };
int[] lastOutput = { 0 };
String contentLength = res.getHeader("Content-Length");
if (contentLength != null) {
length = Integer.parseInt(contentLength);
} else {
length = 0;
}
res.exceptionHandler(t -> handler.handle(Future.failedFuture(t)));
// download file contents, log progress
res.handler(buf -> {
read[0] += buf.length();
if (lastOutput[0] == 0 || read[0] - lastOutput[0] > 1024 * 2048) {
logProgress(length, read[0]);
lastOutput[0] = read[0];
}
dest.write(buf);
});
res.endHandler(v -> {
logProgress(length, read[0]);
handler.handle(Future.succeededFuture());
});
});
req.end();
return observable.toSingle();
}
Aggregations