Search in sources :

Example 21 with HttpClientOptions

use of io.vertx.core.http.HttpClientOptions in project vertx-examples by vert-x3.

the class Client method start.

@Override
public void start() throws Exception {
    HttpClientRequest request = vertx.createHttpClient(new HttpClientOptions().setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(8080))).put(8282, "localhost", "/", resp -> {
        System.out.println("Got response " + resp.statusCode());
        resp.bodyHandler(body -> System.out.println("Got data " + body.toString("ISO-8859-1")));
    });
    request.setChunked(true);
    for (int i = 0; i < 10; i++) {
        request.write("client-chunk-" + i);
    }
    request.end();
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) ProxyOptions(io.vertx.core.net.ProxyOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 22 with HttpClientOptions

use of io.vertx.core.http.HttpClientOptions in project incubator-servicecomb-java-chassis by apache.

the class WebsocketClientPool 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.getIdleWatchTimeout());
    if (ver == HttpVersion.HTTP_2) {
        LOGGER.debug("service center ws client protocol version is HTTP/2");
        httpClientOptions.setHttp2ClearTextUpgrade(false);
    }
    if (ServiceRegistryConfig.INSTANCE.isSsl()) {
        LOGGER.debug("service center ws client performs requests over TLS");
        VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions);
    }
    return httpClientOptions;
}
Also used : HttpVersion(io.vertx.core.http.HttpVersion) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 23 with HttpClientOptions

use of io.vertx.core.http.HttpClientOptions in project incubator-servicecomb-java-chassis by apache.

the class AbstractClientPool method create.

public void create() {
    // 这里面是同步接口,且好像直接在事件线程中用,保险起见,先使用独立的vertx实例
    VertxOptions vertxOptions = new VertxOptions();
    vertxOptions.setAddressResolverOptions(AddressResolverConfig.getAddressResover(SSL_KEY));
    Vertx vertx = VertxUtils.getOrCreateVertxByName("registry", vertxOptions);
    HttpClientOptions httpClientOptions = createHttpClientOptions();
    clientMgr = new ClientPoolManager<>(vertx, new HttpClientPoolFactory(httpClientOptions));
    DeploymentOptions deployOptions = VertxUtils.createClientDeployOptions(this.clientMgr, ServiceRegistryConfig.INSTANCE.getWorkerPoolSize());
    try {
        VertxUtils.blockDeploy(vertx, ClientVerticle.class, deployOptions);
    } catch (InterruptedException e) {
        LOGGER.error("deploy a registry verticle failed, {}", e.getMessage());
    }
}
Also used : HttpClientPoolFactory(org.apache.servicecomb.foundation.vertx.client.http.HttpClientPoolFactory) DeploymentOptions(io.vertx.core.DeploymentOptions) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 24 with HttpClientOptions

use of io.vertx.core.http.HttpClientOptions in project incubator-servicecomb-java-chassis by apache.

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 (ServiceRegistryConfig.INSTANCE.isProxyEnable()) {
        ProxyOptions proxy = new ProxyOptions();
        proxy.setHost(ServiceRegistryConfig.INSTANCE.getProxyHost());
        proxy.setPort(ServiceRegistryConfig.INSTANCE.getProxyPort());
        proxy.setUsername(ServiceRegistryConfig.INSTANCE.getProxyUsername());
        proxy.setPassword(ServiceRegistryConfig.INSTANCE.getProxyPasswd());
        httpClientOptions.setProxyOptions(proxy);
    }
    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");
        VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions);
    }
    return httpClientOptions;
}
Also used : ProxyOptions(io.vertx.core.net.ProxyOptions) HttpVersion(io.vertx.core.http.HttpVersion) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 25 with HttpClientOptions

use of io.vertx.core.http.HttpClientOptions in project incubator-servicecomb-java-chassis by apache.

the class TestVertxTLSBuilder method testbuildHttpClientOptions_sslKey_noFactory.

@Test
public void testbuildHttpClientOptions_sslKey_noFactory() {
    HttpClientOptions clientOptions = new HttpClientOptions();
    VertxTLSBuilder.buildHttpClientOptions("notExist", clientOptions);
    Assert.assertTrue(clientOptions.isSsl());
}
Also used : HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Aggregations

HttpClientOptions (io.vertx.core.http.HttpClientOptions)101 Test (org.junit.Test)51 HttpClient (io.vertx.core.http.HttpClient)27 HttpClientRequest (io.vertx.core.http.HttpClientRequest)23 HttpServerOptions (io.vertx.core.http.HttpServerOptions)19 CountDownLatch (java.util.concurrent.CountDownLatch)15 HttpMethod (io.vertx.core.http.HttpMethod)14 SSLCustom (org.apache.servicecomb.foundation.ssl.SSLCustom)14 SSLOption (org.apache.servicecomb.foundation.ssl.SSLOption)14 HttpVersion (io.vertx.core.http.HttpVersion)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 Vertx (io.vertx.core.Vertx)11 MockUp (mockit.MockUp)11 DeploymentOptions (io.vertx.core.DeploymentOptions)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 Buffer (io.vertx.core.buffer.Buffer)9 HttpServer (io.vertx.core.http.HttpServer)8 HttpServerResponse (io.vertx.core.http.HttpServerResponse)8 VertxOptions (io.vertx.core.VertxOptions)7 VertxInternal (io.vertx.core.impl.VertxInternal)7