Search in sources :

Example 76 with HttpClient

use of io.vertx.core.http.HttpClient in project vert.x by eclipse.

the class HTTP2Examples method example7.

public void example7(Vertx vertx) {
    HttpClientOptions options = new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2).setSsl(true).setUseAlpn(true).setTrustAll(true);
    HttpClient client = vertx.createHttpClient(options);
}
Also used : HttpClient(io.vertx.core.http.HttpClient) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 77 with HttpClient

use of io.vertx.core.http.HttpClient in project vert.x by eclipse.

the class JsonTest method testHttp.

@Test
public void testHttp() {
    Vertx vertx = Vertx.vertx();
    try {
        vertx.createHttpServer().requestHandler(req -> {
            req.response().end("hello");
        }).listen(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, onSuccess(s -> {
            HttpClient client = vertx.createHttpClient();
            client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/").compose(req -> req.send().compose(HttpClientResponse::body)).onComplete(onSuccess(body -> {
                assertEquals("hello", body.toString());
                testComplete();
            }));
        }));
        await();
    } finally {
        vertx.close();
    }
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) JsonArray(io.vertx.core.json.JsonArray) EventBus(io.vertx.core.eventbus.EventBus) DEFAULT_HTTP_HOST(io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_HOST) HttpMethod(io.vertx.core.http.HttpMethod) Vertx(io.vertx.core.Vertx) DEFAULT_HTTP_PORT(io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_PORT) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test) VertxTestBase(io.vertx.test.core.VertxTestBase) HttpClient(io.vertx.core.http.HttpClient) HttpClient(io.vertx.core.http.HttpClient) Vertx(io.vertx.core.Vertx) Test(org.junit.Test)

Aggregations

HttpClient (io.vertx.core.http.HttpClient)77 Test (org.junit.Test)47 HttpClientRequest (io.vertx.core.http.HttpClientRequest)36 HttpClientOptions (io.vertx.core.http.HttpClientOptions)25 Vertx (io.vertx.core.Vertx)22 HttpMethod (io.vertx.core.http.HttpMethod)22 JsonObject (io.vertx.core.json.JsonObject)22 Handler (io.vertx.core.Handler)18 Buffer (io.vertx.core.buffer.Buffer)18 HttpClientResponse (io.vertx.core.http.HttpClientResponse)16 TimeUnit (java.util.concurrent.TimeUnit)16 HttpServer (io.vertx.core.http.HttpServer)15 Async (io.vertx.ext.unit.Async)15 Before (org.junit.Before)15 File (java.io.File)14 CountDownLatch (java.util.concurrent.CountDownLatch)14 URL (java.net.URL)12 HttpServerOptions (io.vertx.core.http.HttpServerOptions)11 IOException (java.io.IOException)10 List (java.util.List)10