Search in sources :

Example 26 with ProxySelector

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);
}
Also used : ProxySelector(java.net.ProxySelector) GlobalProxySelector(org.jkiss.dbeaver.runtime.net.GlobalProxySelector) GlobalProxySelector(org.jkiss.dbeaver.runtime.net.GlobalProxySelector)

Example 27 with ProxySelector

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;
}
Also used : ProxySelector(java.net.ProxySelector) Proxy(java.net.Proxy)

Example 28 with ProxySelector

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;
}
Also used : ProxySelector(java.net.ProxySelector) Proxy(java.net.Proxy) PluginResult(org.apache.cordova.PluginResult) Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) JSONArray(org.json.JSONArray) URI(java.net.URI)

Example 29 with ProxySelector

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());
}
Also used : ProxySelector(java.net.ProxySelector) RecordingProxySelector(okhttp3.internal.http.RecordingProxySelector) Proxy(java.net.Proxy) SocketAddress(java.net.SocketAddress) Address(okhttp3.Address) InetAddress(java.net.InetAddress) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) URI(java.net.URI) Test(org.junit.Test)

Example 30 with ProxySelector

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;
}
Also used : ProxySelector(java.net.ProxySelector) URI(java.net.URI)

Aggregations

ProxySelector (java.net.ProxySelector)53 URI (java.net.URI)33 Proxy (java.net.Proxy)32 InetSocketAddress (java.net.InetSocketAddress)21 IOException (java.io.IOException)19 SocketAddress (java.net.SocketAddress)13 List (java.util.List)7 InetAddress (java.net.InetAddress)6 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 HttpURLConnection (java.net.HttpURLConnection)3 URISyntaxException (java.net.URISyntaxException)3 HttpHost (org.apache.http.HttpHost)3 Test (org.junit.Test)3 ManualProxySelector (org.kse.utilities.net.ManualProxySelector)3 NoProxySelector (org.kse.utilities.net.NoProxySelector)3 PacProxySelector (org.kse.utilities.net.PacProxySelector)3 ProxyAddress (org.kse.utilities.net.ProxyAddress)3 SystemProxySelector (org.kse.utilities.net.SystemProxySelector)3 InterruptedIOException (java.io.InterruptedIOException)2