use of io.vertx.reactivex.core.http.HttpClient in project knotx by Cognifide.
the class KnotxServerRoutingTest method testGetRequest.
private void testGetRequest(TestContext context, String url, String expectedResult) {
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(HttpResponseStatus.OK.code(), resp.statusCode());
context.assertTrue(resp.getHeader(EXPECTED_RESPONSE_HEADER) != null);
context.assertEquals(EXPECTED_XSERVER_HEADER_VALUE, resp.getHeader(EXPECTED_RESPONSE_HEADER));
try {
context.assertEquals(body.toString(), expectedResult, "Wrong engines processed request, expected " + expectedResult);
} catch (Exception e) {
context.fail(e);
}
client.close();
async.complete();
}));
}
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(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.HttpClient 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();
}
use of io.vertx.reactivex.core.http.HttpClient in project knotx by Cognifide.
the class KnotxServerRoutingTest method whenRequestingWithInvalidQuery_expectBadRequest.
@Test
@KnotxConfiguration("test-server.json")
public void whenRequestingWithInvalidQuery_expectBadRequest(TestContext context) {
HttpClient client = Vertx.newInstance(vertx.vertx()).createHttpClient();
Async async = context.async();
client.getNow(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html?q=~!@\\||$%^&*()_=-%22;;%27%22:%3C%3E/?]}{", resp -> {
context.assertEquals(HttpResponseStatus.BAD_REQUEST.code(), resp.statusCode());
client.close();
async.complete();
});
}
use of io.vertx.reactivex.core.http.HttpClient in project knotx by Cognifide.
the class SampleApplicationHeadersTest method testGetRequest.
private void testGetRequest(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 -> {
MultiMap headers = resp.headers();
headers.names().forEach(name -> {
context.assertEquals(resp.statusCode(), 200, "Wrong status code received.");
context.assertTrue(expectedHeaders.contains(name), "Header " + name + " is not expected.");
context.assertEquals(expectedHeaders.get(name), headers.get(name), "Wrong value of " + name + " header.");
});
async.complete();
});
}
Aggregations