Search in sources :

Example 66 with HttpClientOptions

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

the class GrpcTransport method createHttpClientOptions.

private HttpClientOptions createHttpClientOptions() {
    HttpClientOptions httpClientOptions = new HttpClientOptions();
    httpClientOptions.setProtocolVersion(HttpVersion.HTTP_2);
    httpClientOptions.setHttp2ClearTextUpgrade(false);
    String key = System.getProperty("store.key");
    if (key != null && !key.isEmpty()) {
        httpClientOptions.setUseAlpn(true);
        httpClientOptions.setSsl(true);
        httpClientOptions.setKeyStoreOptions(new JksOptions().setPath(System.getProperty("store.key")).setPassword(System.getProperty("store.pass")));
        httpClientOptions.setTrustAll(true);
        httpClientOptions.setVerifyHost(false);
    }
    return httpClientOptions;
}
Also used : JksOptions(io.vertx.core.net.JksOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 67 with HttpClientOptions

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

the class RestTransportClient method init.

public void init(Vertx vertx) throws Exception {
    HttpClientOptions httpClientOptions = createHttpClientOptions();
    DeploymentOptions deployOptions = VertxUtils.createClientDeployOptions(clientMgr, TransportClientConfig.getThreadCount(), TransportClientConfig.getConnectionPoolPerThread(), httpClientOptions);
    VertxUtils.blockDeploy(vertx, HttpClientVerticle.class, deployOptions);
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 68 with HttpClientOptions

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

the class AbstractClientPool method create.

public void create() {
    // 这里面是同步接口,且好像直接在事件线程中用,保险起见,先使用独立的vertx实例
    Vertx vertx = VertxUtils.getOrCreateVertxByName("registry", null);
    HttpClientOptions httpClientOptions = createHttpClientOptions();
    DeploymentOptions deployOptions = VertxUtils.createClientDeployOptions(this.clientMgr, ServiceRegistryConfig.INSTANCE.getWorkerPoolSize(), 1, httpClientOptions);
    try {
        VertxUtils.blockDeploy(vertx, HttpClientVerticle.class, deployOptions);
    } catch (InterruptedException e) {
        LOGGER.error("deploy a registry verticle failed, {}", e.getMessage());
    }
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) Vertx(io.vertx.core.Vertx) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 69 with HttpClientOptions

use of io.vertx.core.http.HttpClientOptions 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)

Example 70 with HttpClientOptions

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

the class TestServiceRegistryClientImpl method testPrivateMehtodCreateHttpClientOptions.

@Test
public void testPrivateMehtodCreateHttpClientOptions() {
    Microservice oInstance = RegistryUtils.getMicroservice();
    oClient.registerMicroservice(oInstance);
    oClient.registerMicroserviceInstance(RegistryUtils.getMicroserviceInstance());
    new MockUp<ServiceRegistryConfig>() {

        @Mock
        public HttpVersion getHttpVersion() {
            return HttpVersion.HTTP_2;
        }

        @Mock
        public boolean isSsl() {
            return true;
        }
    };
    try {
        oClient.init();
        HttpClientOptions httpClientOptions = Deencapsulation.invoke(oClient, "createHttpClientOptions");
        Assert.assertNotNull(httpClientOptions);
        Assert.assertEquals(80, httpClientOptions.getDefaultPort());
    } catch (Exception e) {
        Assert.assertNotNull(e);
    }
}
Also used : Microservice(io.servicecomb.serviceregistry.api.registry.Microservice) MockUp(mockit.MockUp) HttpClientOptions(io.vertx.core.http.HttpClientOptions) ClientException(io.servicecomb.serviceregistry.client.ClientException) 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