use of io.vertx.core.net.ProxyOptions in project vert.x by eclipse.
the class ProxyOptionsTest method testProxyOptions.
@Test
public void testProxyOptions() {
ProxyOptions options = new ProxyOptions();
assertEquals(ProxyOptions.DEFAULT_TYPE, options.getType());
assertEquals(options, options.setType(randType));
assertEquals(randType, options.getType());
assertNullPointerException(() -> options.setType(null));
assertEquals(ProxyOptions.DEFAULT_HOST, options.getHost());
assertEquals(options, options.setHost(randHost));
assertEquals(randHost, options.getHost());
assertNullPointerException(() -> options.setHost(null));
assertEquals(ProxyOptions.DEFAULT_PORT, options.getPort());
assertEquals(options, options.setPort(randPort));
assertEquals(randPort, options.getPort());
assertIllegalArgumentException(() -> options.setPort(-1));
assertIllegalArgumentException(() -> options.setPort(65536));
assertEquals(null, options.getUsername());
assertEquals(options, options.setUsername(randUsername));
assertEquals(randUsername, options.getUsername());
assertEquals(null, options.getPassword());
assertEquals(options, options.setPassword(randPassword));
assertEquals(randPassword, options.getPassword());
}
use of io.vertx.core.net.ProxyOptions in project vert.x by eclipse.
the class ProxyOptionsTest method testDefaultOptionsJson.
@Test
public void testDefaultOptionsJson() {
ProxyOptions def = new ProxyOptions();
ProxyOptions options = new ProxyOptions(new JsonObject());
assertEquals(def.getType(), options.getType());
assertEquals(def.getPort(), options.getPort());
assertEquals(def.getHost(), options.getHost());
assertEquals(def.getUsername(), options.getUsername());
assertEquals(def.getPassword(), options.getPassword());
}
use of io.vertx.core.net.ProxyOptions 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.net.ProxyOptions 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.net.ProxyOptions in project incubator-servicecomb-java-chassis by apache.
the class ConfigCenterClient method createHttpClientOptions.
private HttpClientOptions createHttpClientOptions() {
HttpClientOptions httpClientOptions = new HttpClientOptions();
if (ConfigCenterConfig.INSTANCE.isProxyEnable()) {
ProxyOptions proxy = new ProxyOptions().setHost(ConfigCenterConfig.INSTANCE.getProxyHost()).setPort(ConfigCenterConfig.INSTANCE.getProxyPort()).setUsername(ConfigCenterConfig.INSTANCE.getProxyUsername()).setPassword(ConfigCenterConfig.INSTANCE.getProxyPasswd());
httpClientOptions.setProxyOptions(proxy);
}
httpClientOptions.setConnectTimeout(CONFIG_CENTER_CONFIG.getConnectionTimeout());
if (this.memberDiscovery.getConfigServer().toLowerCase().startsWith("https")) {
LOGGER.debug("config center client performs requests over TLS");
SSLOptionFactory factory = SSLOptionFactory.createSSLOptionFactory(SSL_KEY, ConfigCenterConfig.INSTANCE.getConcurrentCompositeConfiguration());
SSLOption sslOption;
if (factory == null) {
sslOption = SSLOption.buildFromYaml(SSL_KEY, ConfigCenterConfig.INSTANCE.getConcurrentCompositeConfiguration());
} else {
sslOption = factory.createSSLOption();
}
SSLCustom sslCustom = SSLCustom.createSSLCustom(sslOption.getSslCustomClass());
VertxTLSBuilder.buildHttpClientOptions(sslOption, sslCustom, httpClientOptions);
}
return httpClientOptions;
}
Aggregations