io.vertx.core.net.ProxyType Java Examples

The following examples show how to use io.vertx.core.net.ProxyType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmqpPropertiesConverter.java    From vertx-spring-boot with Apache License 2.0 6 votes vote down vote up
private void mapClientOptionsBase(AmqpProperties from, AmqpClientOptions to) {
    to.setConnectTimeout(from.getConnectTimeout());
    to.setTrustAll(from.isTrustAll());
    to.setMetricsName(from.getMetricsName());
    to.setLocalAddress(from.getLocalAddress());

    if (from.getProxy().isEnabled()) {
        ProxyOptions proxyOptions = new ProxyOptions()
            .setHost(from.getProxy().getHost())
            .setPort(from.getProxy().getPort())
            .setUsername(from.getProxy().getUsername())
            .setPassword(from.getProxy().getPassword())
            .setType(ProxyType.valueOf(from.getProxy().getType().name()));

        to.setProxyOptions(proxyOptions);
    }
}
 
Example #2
Source File: MailProxyTest.java    From vertx-mail-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetUpProxy(TestContext context) throws Exception {
  this.testContext = context;
  MailConfig mailConfig = configLogin().setProxyOptions(new ProxyOptions().setType(ProxyType.SOCKS5).setPort(11080));
  proxy = new SocksProxy(null);
  proxy.start(vertx);
  Async async = testContext.async();
  MailClient client = MailClient.createShared(vertx, mailConfig);
  client.sendMail(exampleMessage(), r -> {
    if (r.succeeded()) {
      assertEquals("localhost:1587", proxy.getLastUri());
      async.complete();
    } else {
      log.debug("Failed to send mail", r.cause());
      testContext.fail(r.cause());
    }
  });
}
 
Example #3
Source File: MailProxyTest.java    From vertx-mail-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetUpProxyAuth(TestContext context) throws Exception {
  this.testContext = context;
  MailConfig mailConfig = configLogin().setProxyOptions(new ProxyOptions()
    .setType(ProxyType.SOCKS5)
    .setPort(11080)
    .setUsername("proxyUser")
    .setPassword("proxyUser")
  );
  proxy = new SocksProxy("proxyUser");
  proxy.start(vertx);
  Async async = testContext.async();
  MailClient client = MailClient.createShared(vertx, mailConfig);
  client.sendMail(exampleMessage(), r -> {
    if (r.succeeded()) {
      assertEquals("localhost:1587", proxy.getLastUri());
      async.complete();
    } else {
      log.debug("Failed to send mail", r.cause());
      testContext.fail(r.cause());
    }
  });
}
 
Example #4
Source File: WebClientsConfiguration.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
private WebClient createWebClient(Vertx vertx, URL url) {

        final int port = url.getPort() != -1 ? url.getPort() : (HTTPS_SCHEME.equals(url.getProtocol()) ? 443 : 80);

        WebClientOptions options = new WebClientOptions()
                .setDefaultPort(port)
                .setDefaultHost(url.getHost())
                .setKeepAlive(true)
                .setMaxPoolSize(10)
                .setTcpKeepAlive(true)
                .setConnectTimeout(httpClientTimeout)
                .setSsl(url.getProtocol().equals(HTTPS_SCHEME));

        if (this.isProxyConfigured) {
            ProxyOptions proxyOptions = new ProxyOptions();
            proxyOptions.setType(ProxyType.valueOf(httpClientProxyType));
            if (HTTPS_SCHEME.equals(url.getProtocol())) {
                proxyOptions.setHost(httpClientProxyHttpsHost);
                proxyOptions.setPort(httpClientProxyHttpsPort);
                proxyOptions.setUsername(httpClientProxyHttpsUsername);
                proxyOptions.setPassword(httpClientProxyHttpsPassword);
            } else {
                proxyOptions.setHost(httpClientProxyHttpHost);
                proxyOptions.setPort(httpClientProxyHttpPort);
                proxyOptions.setUsername(httpClientProxyHttpUsername);
                proxyOptions.setPassword(httpClientProxyHttpPassword);
            }
            options.setProxyOptions(proxyOptions);
        }

        return WebClient.create(vertx, options);
    }
 
Example #5
Source File: HttpClientServiceImpl.java    From gravitee-management-rest-api with Apache License 2.0 5 votes vote down vote up
private HttpClient getHttpClient(String uriScheme, Boolean useSystemProxy) {
    boolean ssl = HTTPS_SCHEME.equalsIgnoreCase(uriScheme);

    final HttpClientOptions options = new HttpClientOptions()
            .setSsl(ssl)
            .setTrustAll(true)
            .setMaxPoolSize(1)
            .setKeepAlive(false)
            .setTcpKeepAlive(false)
            .setConnectTimeout(httpClientTimeout);
    
    if ((useSystemProxy != null && useSystemProxy == Boolean.TRUE) || (useSystemProxy == null && this.isProxyConfigured)) {
        ProxyOptions proxyOptions = new ProxyOptions();
        proxyOptions.setType(ProxyType.valueOf(httpClientProxyType));
        if (HTTPS_SCHEME.equals(uriScheme)) {
            proxyOptions.setHost(httpClientProxyHttpsHost);
            proxyOptions.setPort(httpClientProxyHttpsPort);
            proxyOptions.setUsername(httpClientProxyHttpsUsername);
            proxyOptions.setPassword(httpClientProxyHttpsPassword);
        } else {
            proxyOptions.setHost(httpClientProxyHttpHost);
            proxyOptions.setPort(httpClientProxyHttpPort);
            proxyOptions.setUsername(httpClientProxyHttpUsername);
            proxyOptions.setPassword(httpClientProxyHttpPassword);
        }
        options.setProxyOptions(proxyOptions);
    }
    
    return vertx.createHttpClient(options);
}
 
Example #6
Source File: VertxPluginRegistry.java    From apiman with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param vertx          the vertx
 * @param vxEngineConfig the engine config
 * @param config         the plugin config
 */
public VertxPluginRegistry(Vertx vertx, VertxEngineConfig vxEngineConfig, Map<String, String> config) {

    super(config);

    this.vertx = vertx;

    //Get HTTPS Proxy settings (useful for local dev tests and corporate CI)
    String sslProxyHost = System.getProperty("https.proxyHost", "none");
    Integer sslProxyPort = Integer.valueOf(System.getProperty("https.proxyPort", "443"));
    sslNoProxy = System.getProperty("https.nonProxyHosts", "none");

    //Set HTTPS proxy if defined
    if (!"none".equalsIgnoreCase(sslProxyHost)) {
        sslProxy = new ProxyOptions();
        sslProxy.setHost(sslProxyHost);
        sslProxy.setPort(sslProxyPort);
        sslProxy.setType(ProxyType.HTTP);
    }

    //Get HTTP Proxy settings (useful for local dev tests and corporate CI)
    String proxyHost = System.getProperty("http.proxyHost", "none");
    Integer proxyPort = Integer.valueOf(System.getProperty("http.proxyPort", "80"));
    noProxy = System.getProperty("http.nonProxyHosts", "none");

    //Set HTTPS proxy if defined
    if (!"none".equalsIgnoreCase(proxyHost)) {
        proxy = new ProxyOptions();
        proxy.setHost(proxyHost);
        proxy.setPort(proxyPort);
        proxy.setType(ProxyType.HTTP);
    }
}