use of io.vertx.reactivex.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();
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.HttpClient 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.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.reactivex.core.http.HttpClient in project knotx by Cognifide.
the class SampleApplicationTest method testGetServerError.
private void testGetServerError(TestContext context, String url) {
HttpClient client = Vertx.newInstance(vertx.vertx()).createHttpClient();
Async async = context.async();
client.getNow(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url, resp -> resp.bodyHandler(body -> {
context.assertEquals(resp.statusCode(), HttpResponseStatus.INTERNAL_SERVER_ERROR.code());
client.close();
async.complete();
}));
}
use of io.vertx.reactivex.core.http.HttpClient 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);
}
Aggregations