Search in sources :

Example 6 with ProxyOptions

use of io.vertx.core.net.ProxyOptions in project NetDiscovery by fengzhizi715.

the class VertxDownloader method initWebClientOptions.

private WebClientOptions initWebClientOptions(Request request) {
    WebClientOptions options = new WebClientOptions();
    options.setKeepAlive(true).setReuseAddress(true).setFollowRedirects(true);
    if (Preconditions.isNotBlank(request.getUserAgent())) {
        options.setUserAgent(request.getUserAgent());
    }
    if (Preconditions.isNotBlank(request.getProxy())) {
        ProxyOptions proxyOptions = new ProxyOptions();
        proxyOptions.setHost(request.getProxy().getIp());
        proxyOptions.setPort(request.getProxy().getPort());
        options.setProxyOptions(proxyOptions);
    }
    if (Preconditions.isNotBlank(request.getHeader())) {
        header = request.getHeader();
    }
    return options;
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) ProxyOptions(io.vertx.core.net.ProxyOptions)

Example 7 with ProxyOptions

use of io.vertx.core.net.ProxyOptions in project gravitee-gateway by gravitee-io.

the class VertxHttpClient method doStart.

@Override
protected void doStart() throws Exception {
    // TODO: Prepare HttpClientOptions according to the endpoint to improve performance when creating a new
    // instance of the Vertx client
    httpClientOptions = new HttpClientOptions();
    httpClientOptions.setPipelining(endpoint.getHttpClientOptions().isPipelining());
    httpClientOptions.setKeepAlive(endpoint.getHttpClientOptions().isKeepAlive());
    httpClientOptions.setIdleTimeout((int) (endpoint.getHttpClientOptions().getIdleTimeout() / 1000));
    httpClientOptions.setConnectTimeout((int) endpoint.getHttpClientOptions().getConnectTimeout());
    httpClientOptions.setUsePooledBuffers(true);
    httpClientOptions.setMaxPoolSize(endpoint.getHttpClientOptions().getMaxConcurrentConnections());
    httpClientOptions.setTryUseCompression(endpoint.getHttpClientOptions().isUseCompression());
    // Configure proxy
    HttpProxy proxy = endpoint.getHttpProxy();
    if (proxy != null && proxy.isEnabled()) {
        ProxyOptions proxyOptions = new ProxyOptions();
        proxyOptions.setHost(proxy.getHost());
        proxyOptions.setPort(proxy.getPort());
        proxyOptions.setUsername(proxy.getUsername());
        proxyOptions.setPassword(proxy.getPassword());
        proxyOptions.setType(ProxyType.valueOf(proxy.getType().name()));
        httpClientOptions.setProxyOptions(proxyOptions);
    }
    URI target = URI.create(endpoint.getTarget());
    // Configure SSL
    HttpClientSslOptions sslOptions = endpoint.getHttpClientSslOptions();
    if (sslOptions != null && sslOptions.isEnabled()) {
        httpClientOptions.setSsl(sslOptions.isEnabled()).setVerifyHost(sslOptions.isHostnameVerifier()).setTrustAll(sslOptions.isTrustAll());
        if (sslOptions.getPem() != null && !sslOptions.getPem().isEmpty()) {
            httpClientOptions.setPemTrustOptions(new PemTrustOptions().addCertValue(io.vertx.core.buffer.Buffer.buffer(sslOptions.getPem())));
        }
    } else if (HTTPS_SCHEME.equalsIgnoreCase(target.getScheme())) {
        // SSL is not configured but the endpoint scheme is HTTPS so let's enable the SSL on Vert.x HTTP client
        // automatically
        httpClientOptions.setSsl(true).setTrustAll(true);
    }
    printHttpClientConfiguration(httpClientOptions);
}
Also used : HttpProxy(io.gravitee.definition.model.HttpProxy) ProxyOptions(io.vertx.core.net.ProxyOptions) HttpClientSslOptions(io.gravitee.definition.model.HttpClientSslOptions) URI(java.net.URI) PemTrustOptions(io.vertx.core.net.PemTrustOptions)

Example 8 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 9 with ProxyOptions

use of io.vertx.core.net.ProxyOptions in project vert.x by eclipse.

the class ProxyOptionsTest method testOptionsJson.

@Test
public void testOptionsJson() {
    JsonObject json = new JsonObject();
    json.put("type", randType.toString()).put("host", randHost).put("port", randPort).put("username", randUsername).put("password", randPassword);
    ProxyOptions options = new ProxyOptions(json);
    assertEquals(randType, options.getType());
    assertEquals(randPort, options.getPort());
    assertEquals(randHost, options.getHost());
    assertEquals(randUsername, options.getUsername());
    assertEquals(randPassword, options.getPassword());
}
Also used : ProxyOptions(io.vertx.core.net.ProxyOptions) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 10 with ProxyOptions

use of io.vertx.core.net.ProxyOptions in project vert.x by eclipse.

the class NetClientImpl method connect.

private void connect(SocketAddress remoteAddress, String serverName, Promise<NetSocket> connectHandler, ContextInternal ctx) {
    SocketAddress peerAddress = remoteAddress;
    String peerHost = peerAddress.host();
    if (peerHost != null && peerHost.endsWith(".")) {
        peerAddress = SocketAddress.inetSocketAddress(peerAddress.port(), peerHost.substring(0, peerHost.length() - 1));
    }
    ProxyOptions proxyOptions = options.getProxyOptions();
    if (proxyFilter != null) {
        if (!proxyFilter.test(remoteAddress)) {
            proxyOptions = null;
        }
    }
    connectInternal(proxyOptions, remoteAddress, peerAddress, serverName, options.isSsl(), options.isUseAlpn(), true, connectHandler, ctx, options.getReconnectAttempts());
}
Also used : ProxyOptions(io.vertx.core.net.ProxyOptions) SocketAddress(io.vertx.core.net.SocketAddress)

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