Search in sources :

Example 36 with HttpClient

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

the class HTTP2Examples method useMaxStreams.

public void useMaxStreams(Vertx vertx) {
    HttpClientOptions clientOptions = new HttpClientOptions().setHttp2MultiplexingLimit(10).setHttp2MaxPoolSize(3);
    // Uses up to 3 connections and up to 10 streams per connection
    HttpClient client = vertx.createHttpClient(clientOptions);
}
Also used : HttpClient(io.vertx.core.http.HttpClient) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 37 with HttpClient

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

the class HTTP2Examples method example8.

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

Example 38 with HttpClient

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

the class VertxImpl method createHttpClient.

public HttpClient createHttpClient(HttpClientOptions options) {
    CloseFuture closeFuture = new CloseFuture();
    HttpClient client;
    if (options.isShared()) {
        client = createSharedClient(SharedHttpClient.SHARED_MAP_NAME, options.getName(), closeFuture, cf -> createHttpClient(options, cf));
        client = new SharedHttpClient(this, closeFuture, client);
    } else {
        client = createHttpClient(options, closeFuture);
    }
    resolveCloseFuture().add(closeFuture);
    return client;
}
Also used : HttpServerImpl(io.vertx.core.http.impl.HttpServerImpl) NetServerImpl(io.vertx.core.net.impl.NetServerImpl) DnsResolverProvider(io.vertx.core.impl.resolver.DnsResolverProvider) HttpClientImpl(io.vertx.core.http.impl.HttpClientImpl) HttpServer(io.vertx.core.http.HttpServer) NetClientImpl(io.vertx.core.net.impl.NetClientImpl) VertxThreadFactory(io.vertx.core.spi.VertxThreadFactory) AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) InetAddress(java.net.InetAddress) EventBus(io.vertx.core.eventbus.EventBus) WindowsFileSystem(io.vertx.core.file.impl.WindowsFileSystem) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) Logger(io.vertx.core.impl.logging.Logger) ClusterManager(io.vertx.core.spi.cluster.ClusterManager) java.util.concurrent(java.util.concurrent) Set(java.util.Set) MetricsProvider(io.vertx.core.spi.metrics.MetricsProvider) EventLoop(io.netty.channel.EventLoop) ResourceLeakDetector(io.netty.util.ResourceLeakDetector) Future(io.vertx.core.Future) ServerID(io.vertx.core.net.impl.ServerID) InetSocketAddress(java.net.InetSocketAddress) NetClientOptions(io.vertx.core.net.NetClientOptions) DnsClient(io.vertx.core.dns.DnsClient) AddressResolverGroup(io.netty.resolver.AddressResolverGroup) NetServerOptions(io.vertx.core.net.NetServerOptions) PoolMetrics(io.vertx.core.spi.metrics.PoolMetrics) FileSystem(io.vertx.core.file.FileSystem) HttpClient(io.vertx.core.http.HttpClient) DatagramSocketImpl(io.vertx.core.datagram.impl.DatagramSocketImpl) VerticleFactory(io.vertx.core.spi.VerticleFactory) LoggerFactory(io.vertx.core.impl.logging.LoggerFactory) io.vertx.core(io.vertx.core) DatagramSocket(io.vertx.core.datagram.DatagramSocket) DnsClientImpl(io.vertx.core.dns.impl.DnsClientImpl) DnsClientOptions(io.vertx.core.dns.DnsClientOptions) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) SharedData(io.vertx.core.shareddata.SharedData) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) ArrayList(java.util.ArrayList) SharedDataImpl(io.vertx.core.shareddata.impl.SharedDataImpl) EventBusInternal(io.vertx.core.eventbus.impl.EventBusInternal) FileResolver(io.vertx.core.spi.file.FileResolver) HttpClientOptions(io.vertx.core.http.HttpClientOptions) NetClient(io.vertx.core.net.NetClient) WeakReference(java.lang.ref.WeakReference) Metrics(io.vertx.core.spi.metrics.Metrics) EventBusImpl(io.vertx.core.eventbus.impl.EventBusImpl) EventLoopGroup(io.netty.channel.EventLoopGroup) PromiseInternal(io.vertx.core.impl.future.PromiseInternal) Transport(io.vertx.core.net.impl.transport.Transport) NodeSelector(io.vertx.core.spi.cluster.NodeSelector) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) ExecutorServiceFactory(io.vertx.core.spi.ExecutorServiceFactory) VertxTracer(io.vertx.core.spi.tracing.VertxTracer) IOException(java.io.IOException) SharedHttpClient(io.vertx.core.http.impl.SharedHttpClient) File(java.io.File) FileSystemImpl(io.vertx.core.file.impl.FileSystemImpl) AtomicLong(java.util.concurrent.atomic.AtomicLong) NetServer(io.vertx.core.net.NetServer) TCPServerBase(io.vertx.core.net.impl.TCPServerBase) HttpServerOptions(io.vertx.core.http.HttpServerOptions) ClusteredEventBus(io.vertx.core.eventbus.impl.clustered.ClusteredEventBus) HttpClient(io.vertx.core.http.HttpClient) SharedHttpClient(io.vertx.core.http.impl.SharedHttpClient) SharedHttpClient(io.vertx.core.http.impl.SharedHttpClient)

Example 39 with HttpClient

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

the class HostnameResolutionTest method testHttp.

@Test
public void testHttp() throws Exception {
    HttpClient client = vertx.createHttpClient();
    HttpServer server = vertx.createHttpServer().requestHandler(req -> {
        req.response().end("foo");
    });
    try {
        CountDownLatch listenLatch = new CountDownLatch(1);
        server.listen(8080, "vertx.io", onSuccess(s -> {
            listenLatch.countDown();
        }));
        awaitLatch(listenLatch);
        client.request(HttpMethod.GET, 8080, "vertx.io", "/somepath", onSuccess(req -> {
            req.send(onSuccess(resp -> {
                Buffer buffer = Buffer.buffer();
                resp.handler(buffer::appendBuffer);
                resp.endHandler(v -> {
                    assertEquals(Buffer.buffer("foo"), buffer);
                    testComplete();
                });
            }));
        }));
        await();
    } finally {
        client.close();
        server.close();
    }
}
Also used : VertxException(io.vertx.core.VertxException) RecordClass(org.apache.directory.server.dns.messages.RecordClass) java.util(java.util) HttpServer(io.vertx.core.http.HttpServer) CompletableFuture(java.util.concurrent.CompletableFuture) VertxTestBase(io.vertx.test.core.VertxTestBase) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) InetAddress(java.net.InetAddress) TestUtils(io.vertx.test.core.TestUtils) JsonObject(io.vertx.core.json.JsonObject) FakeDNSServer(io.vertx.test.fakedns.FakeDNSServer) NetClient(io.vertx.core.net.NetClient) ResourceRecord(org.apache.directory.server.dns.messages.ResourceRecord) VertxImpl(io.vertx.core.impl.VertxImpl) VertxInternal(io.vertx.core.impl.VertxInternal) ChannelInitializer(io.netty.channel.ChannelInitializer) AddressResolver(io.vertx.core.impl.AddressResolver) DnsAttribute(org.apache.directory.server.dns.store.DnsAttribute) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) InetSocketAddress(java.net.InetSocketAddress) UnknownHostException(java.net.UnknownHostException) File(java.io.File) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) Bootstrap(io.netty.bootstrap.Bootstrap) CountDownLatch(java.util.concurrent.CountDownLatch) NetServerOptions(io.vertx.core.net.NetServerOptions) Buffer(io.vertx.core.buffer.Buffer) NetServer(io.vertx.core.net.NetServer) HttpMethod(io.vertx.core.http.HttpMethod) RecordType(org.apache.directory.server.dns.messages.RecordType) HttpClient(io.vertx.core.http.HttpClient) Buffer(io.vertx.core.buffer.Buffer) HttpClient(io.vertx.core.http.HttpClient) HttpServer(io.vertx.core.http.HttpServer) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 40 with HttpClient

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

the class NettyCompatTest method testHttp2.

@Test
public void testHttp2() {
    vertx.createHttpServer(new HttpServerOptions().setUseAlpn(true).setSsl(true).setSslEngineOptions(new OpenSSLEngineOptions()).setKeyCertOptions(Cert.SERVER_JKS.get())).requestHandler(req -> req.response().end("OK")).listen(8443, "localhost", onSuccess(s -> {
        HttpClient client = vertx.createHttpClient(new HttpClientOptions().setSsl(true).setSslEngineOptions(new OpenSSLEngineOptions()).setTrustStoreOptions(Trust.SERVER_JKS.get()));
        client.request(HttpMethod.GET, 8443, "localhost", "/somepath", onSuccess(req -> {
            req.send(onSuccess(resp -> {
                resp.bodyHandler(buff -> {
                    assertEquals("OK", buff.toString());
                    testComplete();
                });
            }));
        }));
    }));
    await();
}
Also used : OpenSSLEngineOptions(io.vertx.core.net.OpenSSLEngineOptions) VertxInternal(io.vertx.core.impl.VertxInternal) HttpMethod(io.vertx.core.http.HttpMethod) Cert(io.vertx.test.tls.Cert) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Trust(io.vertx.test.tls.Trust) Test(org.junit.Test) HttpClientOptions(io.vertx.core.http.HttpClientOptions) VertxTestBase(io.vertx.test.core.VertxTestBase) HttpClient(io.vertx.core.http.HttpClient) HttpClient(io.vertx.core.http.HttpClient) HttpServerOptions(io.vertx.core.http.HttpServerOptions) OpenSSLEngineOptions(io.vertx.core.net.OpenSSLEngineOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) 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