use of io.vertx.reactivex.core.http.HttpClientRequest in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
HttpClient client = vertx.createHttpClient();
HttpClientRequest req = client.request(HttpMethod.GET, 8080, "localhost", "/");
req.toFlowable().flatMap(resp -> {
if (resp.statusCode() != 200) {
throw new RuntimeException("Wrong status code " + resp.statusCode());
}
return Flowable.just(Buffer.buffer()).mergeWith(resp.toFlowable());
}).reduce(Buffer::appendBuffer).map(buffer -> buffer.toString("UTF-8")).subscribe(data -> System.out.println("Server content " + data));
// End request
req.end();
}
use of io.vertx.reactivex.core.http.HttpClientRequest in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
HttpClient client = vertx.createHttpClient();
HttpClientRequest req = client.request(HttpMethod.GET, 8080, "localhost", "/");
req.toFlowable().flatMap(resp -> {
if (resp.statusCode() != 200) {
throw new RuntimeException("Wrong status code " + resp.statusCode());
}
return resp.toFlowable();
}).subscribe(data -> System.out.println("Server content " + data.toString("UTF-8")));
// End request
req.end();
}
use of io.vertx.reactivex.core.http.HttpClientRequest in project knotx by Cognifide.
the class SampleApplicationTest method request.
private static Observable<HttpClientResponse> request(HttpClient client, HttpMethod method, int port, String domain, String uri, Action1<HttpClientRequest> requestBuilder) {
return Observable.unsafeCreate(subscriber -> {
HttpClientRequest req = client.request(method, port, domain, uri);
Observable<HttpClientResponse> resp = req.toObservable();
resp.subscribe(subscriber);
requestBuilder.call(req);
req.end();
});
}
use of io.vertx.reactivex.core.http.HttpClientRequest in project knotx by Cognifide.
the class HttpRepositoryConnectorProxyImpl method get.
private Observable<HttpClientResponse> get(HttpClient client, RequestOptions requestOptions, MultiMap headers) {
return Observable.unsafeCreate(subscriber -> {
HttpClientRequest req = client.get(requestOptions);
req.headers().addAll(headers);
if (headers.get(HttpHeaderNames.HOST.toString()) != null) {
req.setHost(headers.get(HttpHeaderNames.HOST.toString()));
}
Observable<HttpClientResponse> resp = req.toObservable();
resp.subscribe(subscriber);
req.end();
});
}
use of io.vertx.reactivex.core.http.HttpClientRequest in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
HttpClient client = vertx.createHttpClient();
HttpClientRequest req = client.request(HttpMethod.GET, 8080, "localhost", "/");
req.toFlowable().flatMap(HttpClientResponse::toFlowable).map(buffer -> buffer.toJsonObject().mapTo(Data.class)).subscribe(data -> System.out.println("Got response " + data.message));
// End request
req.end();
}
Aggregations