Search in sources :

Example 1 with ProxyOptions

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());
}
Also used : ProxyOptions(io.vertx.core.net.ProxyOptions) Test(org.junit.Test)

Example 2 with ProxyOptions

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());
}
Also used : ProxyOptions(io.vertx.core.net.ProxyOptions) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 3 with ProxyOptions

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();
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) ProxyOptions(io.vertx.core.net.ProxyOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 4 with ProxyOptions

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;
}
Also used : ProxyOptions(io.vertx.core.net.ProxyOptions) HttpVersion(io.vertx.core.http.HttpVersion) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 5 with ProxyOptions

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;
}
Also used : ProxyOptions(io.vertx.core.net.ProxyOptions) SSLOptionFactory(org.apache.servicecomb.foundation.ssl.SSLOptionFactory) SSLOption(org.apache.servicecomb.foundation.ssl.SSLOption) SSLCustom(org.apache.servicecomb.foundation.ssl.SSLCustom) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Aggregations

ProxyOptions (io.vertx.core.net.ProxyOptions)28 Test (org.junit.Test)15 HttpClientOptions (io.vertx.core.http.HttpClientOptions)7 SocketAddress (io.vertx.core.net.SocketAddress)5 JsonObject (io.vertx.core.json.JsonObject)4 Handler (io.vertx.core.Handler)3 HttpClientRequest (io.vertx.core.http.HttpClientRequest)3 ProxyType (io.vertx.core.net.ProxyType)3 HttpClientSslOptions (io.gravitee.definition.model.HttpClientSslOptions)2 HttpProxy (io.gravitee.definition.model.HttpProxy)2 HttpClient (io.vertx.core.http.HttpClient)2 ContextInternal (io.vertx.core.impl.ContextInternal)2 Endpoint (io.vertx.core.net.impl.pool.Endpoint)2 SSLCustom (org.apache.servicecomb.foundation.ssl.SSLCustom)2 SSLOption (org.apache.servicecomb.foundation.ssl.SSLOption)2 SSLOptionFactory (org.apache.servicecomb.foundation.ssl.SSLOptionFactory)2 HttpHeaders (io.gravitee.common.http.HttpHeaders)1 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)1 HttpEndpoint (io.gravitee.definition.model.endpoint.HttpEndpoint)1 EndpointRule (io.gravitee.gateway.services.healthcheck.EndpointRule)1