List of usage examples for java.net Proxy equals
public final boolean equals(Object obj)
From source file:jp.go.nict.langrid.management.logic.service.HttpClientUtil.java
/** * //from ww w . ja v a 2 s .co m * */ public static HttpClient createHttpClientWithHostConfig(URL url) { HttpClient client = new HttpClient(); int port = url.getPort(); if (port == -1) { port = url.getDefaultPort(); if (port == -1) { port = 80; } } if ((url.getProtocol().equalsIgnoreCase("https")) && (sslSocketFactory != null)) { Protocol https = new Protocol("https", (ProtocolSocketFactory) new SSLSocketFactorySSLProtocolSocketFactory(sslSocketFactory), port); client.getHostConfiguration().setHost(url.getHost(), url.getPort(), https); } else { Protocol http = new Protocol("http", new SocketFactoryProtocolSocketFactory(SocketFactory.getDefault()), port); client.getHostConfiguration().setHost(url.getHost(), url.getPort(), http); } try { List<Proxy> proxies = ProxySelector.getDefault().select(url.toURI()); for (Proxy p : proxies) { if (p.equals(Proxy.NO_PROXY)) continue; if (!p.type().equals(Proxy.Type.HTTP)) continue; InetSocketAddress addr = (InetSocketAddress) p.address(); client.getHostConfiguration().setProxy(addr.getHostName(), addr.getPort()); break; } } catch (URISyntaxException e) { e.printStackTrace(); } return client; }
From source file:jp.go.nict.langrid.servicesupervisor.invocationprocessor.executor.intragrid.HttpClientUtil.java
/** * /*from w w w . j av a 2 s . c om*/ * */ public static HttpClient createHttpClientWithHostConfig(URL url) { HttpClient client = new HttpClient(); int port = url.getPort(); if (port == -1) { port = url.getDefaultPort(); if (port == -1) { port = 80; } } if ((url.getProtocol().equalsIgnoreCase("https")) && (sslSocketFactory != null)) { Protocol https = new Protocol("https", (ProtocolSocketFactory) new SSLSocketFactorySSLProtocolSocketFactory(sslSocketFactory), port); client.getHostConfiguration().setHost(url.getHost(), url.getPort(), https); } else { Protocol http = new Protocol("http", new SocketFactoryProtocolSocketFactory(SocketFactory.getDefault()), port); client.getHostConfiguration().setHost(url.getHost(), url.getPort(), http); } try { List<Proxy> proxies = ProxySelector.getDefault().select(url.toURI()); for (Proxy p : proxies) { if (p.equals(Proxy.NO_PROXY)) continue; if (!p.type().equals(Proxy.Type.HTTP)) continue; InetSocketAddress addr = (InetSocketAddress) p.address(); client.getHostConfiguration().setProxy(addr.getHostName(), addr.getPort()); client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials("", "")); break; } } catch (URISyntaxException e) { e.printStackTrace(); } return client; }
From source file:hudson.plugins.ec2.EC2Cloud.java
/*** * Connect to an EC2 instance.//from w ww . j a v a 2 s . c om * @return {@link AmazonEC2} client */ public synchronized static AmazonEC2 connect(String accessId, Secret secretKey, URL endpoint) { awsCredentials = new BasicAWSCredentials(accessId, Secret.toString(secretKey)); ClientConfiguration config = new ClientConfiguration(); ProxyConfiguration proxyConfig = Jenkins.getInstance().proxy; Proxy proxy = proxyConfig == null ? Proxy.NO_PROXY : proxyConfig.createProxy(endpoint.getHost()); if (!proxy.equals(Proxy.NO_PROXY) && proxy.address() instanceof InetSocketAddress) { InetSocketAddress address = (InetSocketAddress) proxy.address(); config.setProxyHost(address.getHostName()); config.setProxyPort(address.getPort()); if (null != proxyConfig.getUserName()) { config.setProxyUsername(proxyConfig.getUserName()); config.setProxyPassword(proxyConfig.getPassword()); } } AmazonEC2 client = new AmazonEC2Client(awsCredentials, config); client.setEndpoint(endpoint.toString()); return client; }
From source file:org.mapfish.print.config.Config.java
/** * Get or create the http client to be used to fetch all the map data. *//*from ww w . j av a 2s .c om*/ public HttpClient getHttpClient(URI uri) { MultiThreadedHttpConnectionManager connectionManager = getConnectionManager(); HttpClient httpClient = new HttpClient(connectionManager); // httpclient is a bit pesky about loading everything in memory... // disabling the warnings. Logger.getLogger(HttpMethodBase.class).setLevel(Level.ERROR); // configure proxies for URI ProxySelector selector = ProxySelector.getDefault(); List<Proxy> proxyList = selector.select(uri); Proxy proxy = proxyList.get(0); if (!proxy.equals(Proxy.NO_PROXY)) { InetSocketAddress socketAddress = (InetSocketAddress) proxy.address(); String hostName = socketAddress.getHostName(); int port = socketAddress.getPort(); httpClient.getHostConfiguration().setProxy(hostName, port); } for (SecurityStrategy sec : security) if (sec.matches(uri)) { sec.configure(uri, httpClient); break; } return httpClient; }