Search in sources :

Example 6 with HttpVersion

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

the class HttpMetricsTest method testServerConnectionClosed.

private void testServerConnectionClosed(HttpVersion protocol) throws Exception {
    server.close();
    server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setIdleTimeout(2));
    server.requestHandler(req -> {
        FakeHttpServerMetrics metrics = FakeMetricsBase.getMetrics(server);
        HttpServerMetric metric = metrics.getMetric(req);
        assertNotNull(metric);
        assertFalse(metric.failed.get());
        req.response().closeHandler(v -> {
            assertNull(metrics.getMetric(req));
            assertTrue(metric.failed.get());
            testComplete();
        });
    });
    startServer();
    client = vertx.createHttpClient(new HttpClientOptions().setProtocolVersion(protocol));
    HttpClientRequest req = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
    req.handler(resp -> {
    }).end();
    await();
}
Also used : FakeMetricsBase(io.vertx.test.fakemetrics.FakeMetricsBase) FakeMetricsFactory(io.vertx.test.fakemetrics.FakeMetricsFactory) HttpServerMetric(io.vertx.test.fakemetrics.HttpServerMetric) HttpServer(io.vertx.core.http.HttpServer) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) Context(io.vertx.core.Context) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpClientRequest(io.vertx.core.http.HttpClientRequest) FakeHttpServerMetrics(io.vertx.test.fakemetrics.FakeHttpServerMetrics) CountDownLatch(java.util.concurrent.CountDownLatch) Buffer(io.vertx.core.buffer.Buffer) MetricsOptions(io.vertx.core.metrics.MetricsOptions) HttpVersion(io.vertx.core.http.HttpVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerResponse(io.vertx.core.http.HttpServerResponse) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpClientMetric(io.vertx.test.fakemetrics.HttpClientMetric) HttpClient(io.vertx.core.http.HttpClient) FakeHttpClientMetrics(io.vertx.test.fakemetrics.FakeHttpClientMetrics) HttpClientRequest(io.vertx.core.http.HttpClientRequest) FakeHttpServerMetrics(io.vertx.test.fakemetrics.FakeHttpServerMetrics) HttpServerMetric(io.vertx.test.fakemetrics.HttpServerMetric) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 7 with HttpVersion

use of io.vertx.core.http.HttpVersion in project java-chassis by ServiceComb.

the class HttpClientPool method createHttpClientOptions.

@Override
public HttpClientOptions createHttpClientOptions() {
    HttpVersion ver = ServiceRegistryConfig.INSTANCE.getHttpVersion();
    HttpClientOptions httpClientOptions = new HttpClientOptions();
    httpClientOptions.setProtocolVersion(ver);
    httpClientOptions.setConnectTimeout(ServiceRegistryConfig.INSTANCE.getConnectionTimeout());
    httpClientOptions.setIdleTimeout(ServiceRegistryConfig.INSTANCE.getIdleConnectionTimeout());
    if (ver == HttpVersion.HTTP_2) {
        LOGGER.debug("service center client protocol version is HTTP/2");
        httpClientOptions.setHttp2ClearTextUpgrade(false);
    }
    if (ServiceRegistryConfig.INSTANCE.isSsl()) {
        LOGGER.debug("service center client performs requests over TLS");
        buildSecureClientOptions(httpClientOptions);
    }
    return httpClientOptions;
}
Also used : HttpVersion(io.vertx.core.http.HttpVersion) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Aggregations

HttpVersion (io.vertx.core.http.HttpVersion)7 HttpClientOptions (io.vertx.core.http.HttpClientOptions)5 HttpServerOptions (io.vertx.core.http.HttpServerOptions)4 Buffer (io.vertx.core.buffer.Buffer)3 HttpServer (io.vertx.core.http.HttpServer)3 Test (org.junit.Test)2 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ByteBuf (io.netty.buffer.ByteBuf)1 Unpooled (io.netty.buffer.Unpooled)1 Channel (io.netty.channel.Channel)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 ChannelHandler (io.netty.channel.ChannelHandler)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 ChannelOption (io.netty.channel.ChannelOption)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 FixedRecvByteBufAllocator (io.netty.channel.FixedRecvByteBufAllocator)1 ChannelGroup (io.netty.channel.group.ChannelGroup)1 ChannelGroupFuture (io.netty.channel.group.ChannelGroupFuture)1