/** * Get a proxy server selector based on the JDK default proxy selector. * * @return The proxy server selector. */ public static ProxyServerSelector getJdkDefaultProxyServerSelector() { return createProxyServerSelector(ProxySelector.getDefault()); }
private static String getProxySynthesis(URI uri) { return getProxySynthesis(uri, ProxySelector.getDefault()); }
private List<Proxy> getDefaultProxies() { try { ProxySelector defaultProxySelector = ProxySelector.getDefault(); return defaultProxySelector.select(new URI(getPingUrl())); } catch (URISyntaxException e) { throw new IllegalStateException(e); } }
static void install(String hostToIgnore, int portToIgnore) { ProxySelector defaultProxySelector = ProxySelector.getDefault(); ProxySelector ignoreHostProxySelector = new IgnoreHostProxySelector(defaultProxySelector, hostToIgnore, portToIgnore); ProxySelector.setDefault(ignoreHostProxySelector); }
System.setProperty("java.net.useSystemProxies", "true"); System.out.println("detecting proxies"); List l = null; try { l = ProxySelector.getDefault().select(new URI("http://foo/bar")); } catch (URISyntaxException e) { e.printStackTrace(); } if (l != null) { for (Iterator iter = l.iterator(); iter.hasNext();) { java.net.Proxy proxy = (java.net.Proxy) iter.next(); System.out.println("proxy type: " + proxy.type()); InetSocketAddress addr = (InetSocketAddress) proxy.address(); if (addr == null) { System.out.println("No Proxy"); } else { System.out.println("proxy hostname: " + addr.getHostName()); System.setProperty("http.proxyHost", addr.getHostName()); System.out.println("proxy port: " + addr.getPort()); System.setProperty("http.proxyPort", Integer.toString(addr.getPort())); } } }
try { System.setProperty("java.net.useSystemProxies","true"); List<Proxy> l = ProxySelector.getDefault().select( new URI("http://www.yahoo.com/"));
ProxySelector selector = ProxySelector.getDefault(); StringBuilder result = new StringBuilder(); for (Proxy proxy : selector.select(destURI)) {
Loggers.get(getClass()).debug("Download: " + uri + " (" + getProxySynthesis(uri, ProxySelector.getDefault()) + ")"); HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); connection.setRequestMethod(requestMethod);
private void configureProxy(ClientConfig clientConfig, URI originalUri, String protocol) { List<Proxy> proxies = ProxySelector.getDefault().select(originalUri); for (Proxy proxy : proxies) { InetSocketAddress address = (InetSocketAddress) proxy.address(); if (address != null) { String hostname = address.getHostName(); int port = address.getPort(); clientConfig.property(ClientProperties.PROXY_URI, "http://" + hostname + ":" + port); String httpProxyUser = System.getProperty(protocol + ".proxyUser"); if (httpProxyUser != null) { clientConfig.property(ClientProperties.PROXY_USERNAME, httpProxyUser); String httpProxyPassword = System.getProperty(protocol + ".proxyPassword"); if (httpProxyPassword != null) { clientConfig.property(ClientProperties.PROXY_PASSWORD, httpProxyPassword); } } } } }
proxyList.add(proxy); } else { ProxySelector selector = ProxySelector.getDefault(); if (selector != null) { proxyList = selector.select(uri); connectInternal(); } else { ProxySelector selector = ProxySelector.getDefault(); Iterator<Proxy> iter = proxyList.iterator(); boolean connectOK = false;
public static HttpClientBuilder builder(HttpEnvironmentRepositoryProperties environmentProperties) throws GeneralSecurityException { SSLContextBuilder sslContextBuilder = new SSLContextBuilder(); HttpClientBuilder httpClientBuilder = HttpClients.custom(); if (environmentProperties.isSkipSslValidation()) { sslContextBuilder.loadTrustMaterial(null, (certificate, authType) -> true); httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier()); } if (!CollectionUtils.isEmpty(environmentProperties.getProxy())) { ProxyHostProperties httpsProxy = environmentProperties.getProxy().get(ProxyHostProperties.ProxyForScheme.HTTPS); ProxyHostProperties httpProxy = environmentProperties.getProxy().get(ProxyHostProperties.ProxyForScheme.HTTP); httpClientBuilder.setRoutePlanner(new SchemeBasedRoutePlanner(httpsProxy, httpProxy)); httpClientBuilder.setDefaultCredentialsProvider(new ProxyHostCredentialsProvider(httpProxy, httpsProxy)); } else { httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault())); httpClientBuilder.setDefaultCredentialsProvider(new SystemDefaultCredentialsProvider()); } int timeout = environmentProperties.getTimeout() * 1000; return httpClientBuilder .setSSLContext(sslContextBuilder.build()) .setDefaultRequestConfig(RequestConfig.custom() .setSocketTimeout(timeout) .setConnectTimeout(timeout) .build()); } }
public HttpClientConfig build() { // Lazily initialize if necessary, as the call can be expensive when done eagerly. if (this.sslSocketFactory == null) { this.sslSocketFactory = SSLConnectionSocketFactory.getSocketFactory(); } if(this.plainSocketFactory == null) { this.plainSocketFactory = PlainConnectionSocketFactory.getSocketFactory(); } if(this.httpRoutePlanner == null) { this.httpRoutePlanner = new SystemDefaultRoutePlanner(ProxySelector.getDefault()); } if(this.httpIOSessionStrategy == null) { this.httpIOSessionStrategy = NoopIOSessionStrategy.INSTANCE; } if(this.httpsIOSessionStrategy == null) { this.httpsIOSessionStrategy = SSLIOSessionStrategy.getSystemDefaultStrategy(); } if (preemptiveAuthSetWithoutCredentials()) { throw new IllegalArgumentException("Preemptive authentication set without credentials provider"); } return new HttpClientConfig(this); }
psel = ProxySelector.getDefault(); if (psel == null) return null;
@Test(enabled = false) public void testUseProxySelector() throws IOException, ExecutionException, TimeoutException, InterruptedException { ProxySelector originalProxySelector = ProxySelector.getDefault(); ProxySelector.setDefault(new ProxySelector() { public List<Proxy> select(URI uri) {
/** * Get a proxy server selector based on the JDK default proxy selector. * * @return The proxy server selector. */ public static ProxyServerSelector getJdkDefaultProxyServerSelector() { return createProxyServerSelector(ProxySelector.getDefault()); }
CloseableHttpClient client = HttpClients.custom() .setRoutePlanner( new SystemDefaultRoutePlanner(ProxySelector.getDefault())) .build();
public Proxy setupProxy(URL url) { List<Proxy> proxies = null; try { proxies = ProxySelector.getDefault().select(url.toURI()); } catch (URISyntaxException e) { // this can't happen } if (proxies != null) { for (Proxy proxy : proxies) { if (proxy.type().equals(Proxy.Type.HTTP)) { return proxy; } } } return null; }
/** * Create a minimal HTTP transport with default configuration values. * * @param uri * @throws NotSupportedException */ TransportHttp(URIish uri) throws NotSupportedException { super(uri); setURI(uri); http = new HttpConfig(uri); proxySelector = ProxySelector.getDefault(); sslVerify = http.isSslVerify(); }
TransportHttp(Repository local, URIish uri) throws NotSupportedException { super(local, uri); setURI(uri); http = new HttpConfig(local.getConfig(), uri); proxySelector = ProxySelector.getDefault(); sslVerify = http.isSslVerify(); }
@Test public void httpProxyThrowsServiceNotAvailableExceptionIfConfiguredWithZeroNodes() { TestResource testResource = AtlasDbHttpClients.createLiveReloadingProxyWithQuickFailoverForTesting( new MetricRegistry(), () -> ImmutableServerListConfig.builder().build(), SslSocketFactories::createTrustContext, proxyConfiguration -> ProxySelector.getDefault(), TestResource.class, UserAgents.DEFAULT_VALUE); assertThatThrownBy(testResource::getTestNumber).isInstanceOf(ServiceNotAvailableException.class); }