use of io.vertx.reactivex.core.http.HttpClientResponse 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.HttpClientResponse 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.HttpClientResponse in project knotx by Cognifide.
the class KnotxServerRoutingTest method testPostRequest.
private void testPostRequest(String url, Action1<HttpClientResponse> expectedResponse) {
HttpClient client = Vertx.newInstance(vertx.vertx()).createHttpClient();
String testBody = "a=b";
Observable<HttpClientResponse> request = request(client, HttpMethod.POST, KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url, req -> {
req.headers().set("content-length", String.valueOf(testBody.length()));
req.headers().set("content-type", "application/x-www-form-urlencoded");
req.write(testBody);
});
request.subscribe(expectedResponse::call);
}
use of io.vertx.reactivex.core.http.HttpClientResponse 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();
}
use of io.vertx.reactivex.core.http.HttpClientResponse in project vertx-examples by vert-x3.
the class Client method start.
@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 Flowable<JsonObject>
Flowable<JsonObject> obs1 = req1.toFlowable().flatMap(HttpClientResponse::toFlowable).map(buf -> new JsonObject(buf.toString("UTF-8")));
Flowable<JsonObject> obs2 = req2.toFlowable().flatMap(HttpClientResponse::toFlowable).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);
}, Throwable::printStackTrace);
req1.end();
req2.end();
}
Aggregations