use of io.vertx.core.http.HttpClient in project vertx-examples by vert-x3.
the class Proxy method start.
@Override
public void start() throws Exception {
HttpClient client = vertx.createHttpClient(new HttpClientOptions());
vertx.createHttpServer().requestHandler(req -> {
System.out.println("Proxying request: " + req.uri());
HttpClientRequest c_req = client.request(req.method(), 8282, "localhost", req.uri(), c_res -> {
System.out.println("Proxying response: " + c_res.statusCode());
req.response().setChunked(true);
req.response().setStatusCode(c_res.statusCode());
req.response().headers().setAll(c_res.headers());
c_res.handler(data -> {
System.out.println("Proxying response body: " + data.toString("ISO-8859-1"));
req.response().write(data);
});
c_res.endHandler((v) -> req.response().end());
});
c_req.setChunked(true);
c_req.headers().setAll(req.headers());
req.handler(data -> {
System.out.println("Proxying request body " + data.toString("ISO-8859-1"));
c_req.write(data);
});
req.endHandler((v) -> c_req.end());
}).listen(8080);
}
use of io.vertx.core.http.HttpClient in project vertx-examples by vert-x3.
the class ParameterizedTest method test.
@Test
public void test(TestContext context) {
HttpServer server = vertx.createHttpServer().requestHandler(req -> {
context.assertEquals(port, req.localAddress().port());
req.response().end();
});
server.listen(port, "localhost", context.asyncAssertSuccess(s -> {
HttpClient client = vertx.createHttpClient();
Async async = context.async();
HttpClientRequest req = client.get(port, "localhost", "/", resp -> {
context.assertEquals(200, resp.statusCode());
async.complete();
});
req.exceptionHandler(context::fail);
req.end();
}));
}
use of io.vertx.core.http.HttpClient in project vertx-examples by vert-x3.
the class JUnitAndAssertJTest method testHttpCall.
@Test
public void testHttpCall(TestContext context) {
// Send a request and get a response
HttpClient client = vertx.createHttpClient();
Async async = context.async();
client.getNow(8080, "localhost", "/", resp -> {
resp.exceptionHandler(context.exceptionHandler());
resp.bodyHandler(body -> {
assertThat(body.toString()).isEqualTo("foo");
client.close();
async.complete();
});
});
}
use of io.vertx.core.http.HttpClient in project vertx-examples by vert-x3.
the class JUnitAndHamcrestTest method testHTTPCall.
@Test
public void testHTTPCall(TestContext context) {
// Send a request and get a response
HttpClient client = vertx.createHttpClient();
Async async = context.async();
client.getNow(8080, "localhost", "/", resp -> {
resp.exceptionHandler(context.exceptionHandler());
resp.bodyHandler(body -> {
assertThat(body.toString(), is("foo"));
client.close();
async.complete();
});
});
}
use of io.vertx.core.http.HttpClient in project incubator-servicecomb-java-chassis by apache.
the class HttpClientPoolFactory method createClientPool.
@Override
public HttpClientWithContext createClientPool() {
Context context = Vertx.currentContext();
HttpClient httpClient = context.owner().createHttpClient(httpClientOptions);
return new HttpClientWithContext(httpClient, context);
}
Aggregations