Search in sources :

Example 66 with Proxy

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

Example 67 with Proxy

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

Example 68 with Proxy

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;
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) Proxy(java.net.Proxy) Bean(org.springframework.context.annotation.Bean)

Example 69 with Proxy

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

Example 70 with 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;
}
Also used : Proxy(java.net.Proxy) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Aggregations

Proxy (java.net.Proxy)146 InetSocketAddress (java.net.InetSocketAddress)78 URL (java.net.URL)51 IOException (java.io.IOException)38 URI (java.net.URI)23 Test (org.junit.Test)22 HttpURLConnection (java.net.HttpURLConnection)21 ProxySelector (java.net.ProxySelector)21 SocketAddress (java.net.SocketAddress)20 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)14 URISyntaxException (java.net.URISyntaxException)12 ServerSocket (java.net.ServerSocket)10 Socket (java.net.Socket)9 PasswordAuthentication (java.net.PasswordAuthentication)8 URLConnection (java.net.URLConnection)7 HttpHost (org.apache.http.HttpHost)7 InterruptedIOException (java.io.InterruptedIOException)6 SSLServerSocket (javax.net.ssl.SSLServerSocket)6 InputStream (java.io.InputStream)5 List (java.util.List)5