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();
}
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;
}
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());
}
}
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;
}
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());
}
Aggregations