use of java.net.ProxySelector in project dbeaver by dbeaver.
the class SocksProxyImpl method setupProxyHandler.
private static void setupProxyHandler() {
if (ProxySelector.getDefault() instanceof GlobalProxySelector) {
return;
}
activateProxyService();
// Init default network settings
ProxySelector defProxySelector = GeneralUtils.adapt(DBWorkbench.getPlatform(), ProxySelector.class);
if (defProxySelector == null) {
defProxySelector = new GlobalProxySelector(ProxySelector.getDefault());
}
ProxySelector.setDefault(defProxySelector);
}
use of java.net.ProxySelector 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 (!"sun.net.spi.DefaultProxySelector".equals(sel.getClass().getName())) {
return null;
}
Iterator<Proxy> it = sel.select(uri).iterator();
if (it.hasNext()) {
return it.next();
}
return Proxy.NO_PROXY;
}
use of java.net.ProxySelector in project cordova-plugin-networkinterface by salbahra.
the class networkinterface method getHttpProxyInformation.
private boolean getHttpProxyInformation(String url, CallbackContext callbackContext) throws JSONException, URISyntaxException {
JSONArray proxiesInformation = new JSONArray();
ProxySelector defaultProxySelector = ProxySelector.getDefault();
if (defaultProxySelector != null) {
List<java.net.Proxy> proxyList = defaultProxySelector.select(new URI(url));
for (java.net.Proxy proxy : proxyList) {
if (java.net.Proxy.Type.DIRECT.equals(proxy.type())) {
break;
}
InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
if (proxyAddress != null) {
proxiesInformation.put(createProxyInformation(proxy.type(), proxyAddress.getHostString(), String.valueOf(proxyAddress.getPort())));
}
}
}
if (proxiesInformation.length() < 1) {
proxiesInformation.put(createProxyInformation(Proxy.Type.DIRECT, "none", "none"));
}
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, proxiesInformation));
return true;
}
use of java.net.ProxySelector in project okhttp by square.
the class RouteSelectorTest method proxySelectorReturnsNull.
@Test
public void proxySelectorReturnsNull() throws Exception {
ProxySelector nullProxySelector = new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
assertEquals(uriHost, uri.getHost());
return null;
}
@Override
public void connectFailed(URI uri, SocketAddress socketAddress, IOException e) {
throw new AssertionError();
}
};
Address address = new Address(uriHost, uriPort, dns, socketFactory, null, null, null, authenticator, null, protocols, connectionSpecs, nullProxySelector);
RouteSelector routeSelector = new RouteSelector(address, routeDatabase);
assertTrue(routeSelector.hasNext());
dns.set(uriHost, dns.allocate(1));
assertRoute(routeSelector.next(), address, NO_PROXY, dns.lookup(uriHost, 0), uriPort);
dns.assertRequests(uriHost);
assertFalse(routeSelector.hasNext());
}
use of java.net.ProxySelector in project platform_frameworks_base by android.
the class Proxy method getProxy.
/**
* Return the proxy object to be used for the URL given as parameter.
* @param ctx A Context used to get the settings for the proxy host.
* @param url A URL to be accessed. Used to evaluate exclusion list.
* @return Proxy (java.net) object containing the host name. If the
* user did not set a hostname it returns the default host.
* A null value means that no host is to be used.
* {@hide}
*/
public static final java.net.Proxy getProxy(Context ctx, String url) {
String host = "";
if ((url != null) && !isLocalHost(host)) {
URI uri = URI.create(url);
ProxySelector proxySelector = ProxySelector.getDefault();
List<java.net.Proxy> proxyList = proxySelector.select(uri);
if (proxyList.size() > 0) {
return proxyList.get(0);
}
}
return java.net.Proxy.NO_PROXY;
}
Aggregations