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