use of java.net.Proxy in project jdk8u_jdk by JetBrains.
the class B6737819 method main.
public static void main(String[] args) throws Exception {
System.setProperty("http.proxyHost", "myproxy");
System.setProperty("http.proxyPort", "8080");
ProxySelector sel = ProxySelector.getDefault();
java.util.List<Proxy> l;
// from going through the HTTP proxy
for (String s : uris) {
l = sel.select(new URI(s));
if (l.size() == 1 && l.get(0).type() != Proxy.Type.DIRECT) {
throw new RuntimeException("ProxySelector returned the wrong proxy for " + s);
}
}
// Let's override the default nonProxyHosts and make sure we now get a
// HTTP proxy
System.setProperty("http.nonProxyHosts", "");
for (String s : uris) {
l = sel.select(new URI(s));
if (l.size() == 1 && l.get(0).type() != Proxy.Type.HTTP) {
throw new RuntimeException("ProxySelector returned the wrong proxy for " + s);
}
}
}
use of java.net.Proxy in project android_frameworks_base by DirtyUnicorns.
the class PacProxySelector method parseResponse.
private static List<Proxy> parseResponse(String response) {
String[] split = response.split(";");
List<Proxy> ret = Lists.newArrayList();
for (String s : split) {
String trimmed = s.trim();
if (trimmed.equals("DIRECT")) {
ret.add(java.net.Proxy.NO_PROXY);
} else if (trimmed.startsWith(PROXY)) {
Proxy proxy = proxyFromHostPort(Type.HTTP, trimmed.substring(PROXY.length()));
if (proxy != null) {
ret.add(proxy);
}
} else if (trimmed.startsWith(SOCKS)) {
Proxy proxy = proxyFromHostPort(Type.SOCKS, trimmed.substring(SOCKS.length()));
if (proxy != null) {
ret.add(proxy);
}
}
}
if (ret.size() == 0) {
ret.add(java.net.Proxy.NO_PROXY);
}
return ret;
}
use of java.net.Proxy in project CzechIdMng by bcvsolutions.
the class RestTemplateConfig method httpRequestFactory.
@Bean
public ClientHttpRequestFactory httpRequestFactory(HttpClient httpClient) {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
Proxy proxy = getHttpProxy();
if (proxy != null) {
requestFactory.setProxy(proxy);
}
return requestFactory;
}
use of java.net.Proxy in project cxf by apache.
the class Address method chooseProxy.
private static Proxy chooseProxy(URI uri) {
ProxySelector sel = java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<ProxySelector>() {
@Override
public ProxySelector run() {
return ProxySelector.getDefault();
}
});
if (sel == null) {
return Proxy.NO_PROXY;
}
// detect usage of user-defined proxy and avoid optimizations in that case
if (!sel.getClass().getName().equals("sun.net.spi.DefaultProxySelector")) {
return null;
}
Iterator<Proxy> it = sel.select(uri).iterator();
if (it.hasNext()) {
return it.next();
}
return Proxy.NO_PROXY;
}
use of java.net.Proxy in project tomee by apache.
the class HttpResolver method resolve.
@Override
public InputStream resolve(final String location) {
try {
final URL url = new URL(location);
for (final Proxy proxy : ProxySelector.getDefault().select(url.toURI())) {
try {
final URLConnection urlConnection = url.openConnection(proxy);
urlConnection.setConnectTimeout(CONNECT_TIMEOUT);
return urlConnection.getInputStream();
} catch (final IOException e) {
// ignored
}
}
} catch (final MalformedURLException | URISyntaxException e) {
// no-op
}
return null;
}
Aggregations