當前位置: 首頁>>代碼示例>>Java>>正文


Java ProxySelector.getDefault方法代碼示例

本文整理匯總了Java中java.net.ProxySelector.getDefault方法的典型用法代碼示例。如果您正苦於以下問題:Java ProxySelector.getDefault方法的具體用法?Java ProxySelector.getDefault怎麽用?Java ProxySelector.getDefault使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.ProxySelector的用法示例。


在下文中一共展示了ProxySelector.getDefault方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: copyWithDefaults

import java.net.ProxySelector; //導入方法依賴的package包/類
OkHttpClient copyWithDefaults() {
    OkHttpClient result = new OkHttpClient(this);
    if (result.proxySelector == null) {
        result.proxySelector = ProxySelector.getDefault();
    }
    if (result.cookieHandler == null) {
        result.cookieHandler = CookieHandler.getDefault();
    }
    if (result.socketFactory == null) {
        result.socketFactory = SocketFactory.getDefault();
    }
    if (result.sslSocketFactory == null) {
        result.sslSocketFactory = getDefaultSSLSocketFactory();
    }
    if (result.hostnameVerifier == null) {
        result.hostnameVerifier = OkHostnameVerifier.INSTANCE;
    }
    if (result.certificatePinner == null) {
        result.certificatePinner = CertificatePinner.DEFAULT;
    }
    if (result.authenticator == null) {
        result.authenticator = AuthenticatorAdapter.INSTANCE;
    }
    if (result.connectionPool == null) {
        result.connectionPool = ConnectionPool.getDefault();
    }
    if (result.protocols == null) {
        result.protocols = DEFAULT_PROTOCOLS;
    }
    if (result.connectionSpecs == null) {
        result.connectionSpecs = DEFAULT_CONNECTION_SPECS;
    }
    if (result.dns == null) {
        result.dns = Dns.SYSTEM;
    }
    return result;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:38,代碼來源:OkHttpClient.java

示例2: copyWithDefaults

import java.net.ProxySelector; //導入方法依賴的package包/類
/**
 * Returns a shallow copy of this OkHttpClient that uses the system-wide default for
 * each field that hasn't been explicitly configured.
 */
private OkHttpClient copyWithDefaults() {
  OkHttpClient result = new OkHttpClient(this);
  result.proxy = proxy;
  result.proxySelector = proxySelector != null ? proxySelector : ProxySelector.getDefault();
  result.cookieHandler = cookieHandler != null ? cookieHandler : CookieHandler.getDefault();
  result.responseCache = responseCache != null ? responseCache : ResponseCache.getDefault();
  result.sslSocketFactory = sslSocketFactory != null
      ? sslSocketFactory
      : HttpsURLConnection.getDefaultSSLSocketFactory();
  result.hostnameVerifier = hostnameVerifier != null
      ? hostnameVerifier
      : OkHostnameVerifier.INSTANCE;
  result.authenticator = authenticator != null
      ? authenticator
      : HttpAuthenticator.SYSTEM_DEFAULT;
  result.connectionPool = connectionPool != null ? connectionPool : ConnectionPool.getDefault();
  result.followProtocolRedirects = followProtocolRedirects;
  result.transports = transports != null ? transports : DEFAULT_TRANSPORTS;
  result.connectTimeout = connectTimeout;
  result.readTimeout = readTimeout;
  return result;
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:27,代碼來源:OkHttpClient.java

示例3: setUp

import java.net.ProxySelector; //導入方法依賴的package包/類
@Override
protected void setUp() throws Exception {
    super.setUp();
    System.setProperty("netbeans.user", getWorkDir().getAbsolutePath());
    
    // reset
    Method m = MylynSupport.class.getDeclaredMethod("reset", new Class[0]);
    m.setAccessible(true);
    m.invoke(MylynSupport.class);
            
    Field f = Bugzilla.class.getDeclaredField("instance");
    f.setAccessible(true);
    f.set(Bugzilla.class, null);
    
    brc = Bugzilla.getInstance().getRepositoryConnector();
    
    WebUtil.init();
    
    if (defaultPS == null) {
        defaultPS = ProxySelector.getDefault();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:ExceptionHandlerTest.java

示例4: testIgnoring

import java.net.ProxySelector; //導入方法依賴的package包/類
@Test // https://github.com/danikula/AndroidVideoCache/issues/28
public void testIgnoring() throws Exception {
    InetSocketAddress proxyAddress = new InetSocketAddress("proxy.com", 80);
    Proxy systemProxy = new Proxy(Proxy.Type.HTTP, proxyAddress);
    ProxySelector mockedProxySelector = Mockito.mock(ProxySelector.class);
    when(mockedProxySelector.select(Mockito.<URI>any())).thenReturn(Lists.newArrayList(systemProxy));
    ProxySelector.setDefault(mockedProxySelector);

    IgnoreHostProxySelector.install("localhost", 42);

    ProxySelector proxySelector = ProxySelector.getDefault();
    List<Proxy> githubProxies = proxySelector.select(new URI("http://github.com"));
    assertThat(githubProxies).hasSize(1);
    assertThat(githubProxies.get(0).address()).isEqualTo(proxyAddress);

    List<Proxy> localhostProxies = proxySelector.select(new URI("http://localhost:42"));
    assertThat(localhostProxies).hasSize(1);
    assertThat(localhostProxies.get(0)).isEqualTo(Proxy.NO_PROXY);

    List<Proxy> localhostPort69Proxies = proxySelector.select(new URI("http://localhost:69"));
    assertThat(localhostPort69Proxies).hasSize(1);
    assertThat(localhostPort69Proxies.get(0).address()).isEqualTo(proxyAddress);
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:24,代碼來源:ProxySelectorTest.java

示例5: main

import java.net.ProxySelector; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    System.setProperty("java.net.useSystemProxies", "true");
    final ProxySelector ps = ProxySelector.getDefault();
    final URI uri = new URI("http://ubuntu.com");
    Thread[] threads = new Thread[NUM_THREADS];

    for (int i = 0; i < NUM_THREADS; i++) {
        threads[i] = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    ps.select(uri);
                } catch (Exception x) {
                    throw new RuntimeException(x);
                }
            }
        });
    }
    for (int i = 0; i < NUM_THREADS; i++) {
        threads[i].start();
    }
    for (int i = 0; i < NUM_THREADS; i++) {
        threads[i].join();
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:MultiThreadedSystemProxies.java

示例6: getProxy

import java.net.ProxySelector; //導入方法依賴的package包/類
private static Proxy getProxy() {
	List<Proxy> l = null;
	try {
		final ProxySelector def = ProxySelector.getDefault();
		l = def.select(new URI("http://foo/bar"));
		ProxySelector.setDefault(null);
	} catch (final Exception e) {

	}
	if (l != null) {
		for (final Iterator<Proxy> iter = l.iterator(); iter.hasNext();) {
			final java.net.Proxy proxy = iter.next();
			return proxy;
		}
	}
	return null;
}
 
開發者ID:leolewis,項目名稱:openvisualtraceroute,代碼行數:18,代碼來源:Env.java

示例7: setUp

import java.net.ProxySelector; //導入方法依賴的package包/類
protected void setUp() throws Exception {
    super.setUp();
    System.setProperty("netbeans.user", System.getProperty("data.root.dir") + "/cache");
    
    if (defaultPS == null) {
        defaultPS = ProxySelector.getDefault();
    }
    
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:SvnConfigFilesTest.java

示例8: setUp

import java.net.ProxySelector; //導入方法依賴的package包/類
@Override
protected void setUp () throws Exception {
    super.setUp ();
    System.setProperty ("netbeans.system_http_proxy", SYSTEM_PROXY_HOST + ":" + SYSTEM_PROXY_PORT);
    System.setProperty ("netbeans.system_socks_proxy", SYSTEM_PROXY_HOST + ":" + SYSTEM_PROXY_PORT);
    System.setProperty ("netbeans.system_http_non_proxy_hosts", "*.other.org");
    System.setProperty ("http.nonProxyHosts", "*.netbeans.org");
    selector = ProxySelector.getDefault ();
    proxyPreferences  = NbPreferences.root ().node ("/org/netbeans/core");
    proxyPreferences.addPreferenceChangeListener (new PreferenceChangeListener () {
        public void preferenceChange (PreferenceChangeEvent arg0) {
            isWaiting = false;
        }
    });
    proxyPreferences.put ("proxyHttpHost", USER_PROXY_HOST);
    proxyPreferences.put ("proxyHttpPort", USER_PROXY_PORT);
    proxyPreferences.put ("proxySocksHost", USER_PROXY_HOST);
    proxyPreferences.put ("proxySocksPort", USER_PROXY_PORT);
    while (isWaiting);
    isWaiting = true;
    TO_LOCALHOST = new URI ("http://localhost");
    TO_LOCAL_DOMAIN_1 = new URI ("http://core.netbeans.org");
    TO_LOCAL_DOMAIN_2 = new URI ("http://core.other.org");
    TO_EXTERNAL = new URI ("http://worldwide.net");
    
    SOCKS_TO_LOCALHOST = new URI ("socket://localhost:8041");
    SOCKS_TO_LOCAL_DOMAIN_1 = new URI ("socket://core.netbeans.org");
    SOCKS_TO_LOCAL_DOMAIN_2 = new URI ("socket://core.other.org");
    SOCKS_TO_EXTERNAL = new URI ("socket://worldwide.net");
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:NonProxyHostsTest.java

示例9: getDefaultProxies

import java.net.ProxySelector; //導入方法依賴的package包/類
private List<Proxy> getDefaultProxies() {
    try {
        ProxySelector defaultProxySelector = ProxySelector.getDefault();
        return defaultProxySelector.select(new URI(getPingUrl()));
    } catch (URISyntaxException e) {
        throw new IllegalStateException(e);
    }
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:9,代碼來源:Pinger.java

示例10: main

import java.net.ProxySelector; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    System.setProperty("http.proxyHost", "myproxy");
    System.setProperty("http.proxyPort", "8080");
    System.setProperty("http.nonProxyHosts", "host1.*");
    ProxySelector sel = ProxySelector.getDefault();
    java.util.List<Proxy> l = sel.select(new URI("http://HOST1.sun.com/"));
    if (l.get(0) != Proxy.NO_PROXY) {
        throw new RuntimeException("ProxySelector returned the wrong proxy");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:11,代碼來源:B6563259.java

示例11: determineProxy

import java.net.ProxySelector; //導入方法依賴的package包/類
/**
 * Determines a proxy for the given target.
 *
 * @param target    the planned target, never {@code null}
 * @param request   the request to be sent, never {@code null}
 * @param context   the context, or {@code null}
 *
 * @return  the proxy to use, or {@code null} for a direct route
 *
 * @throws HttpException
 *         in case of system proxy settings that cannot be handled
 */
protected HttpHost determineProxy(final HttpHost    target,
                                  final HttpRequest request,
                                  final HttpContext context)
    throws HttpException {

    // the proxy selector can be 'unset', so we better deal with null here
    ProxySelector psel = this.proxySelector;
    if (psel == null) {
        psel = ProxySelector.getDefault();
    }
    if (psel == null) {
        return null;
    }

    URI targetURI = null;
    try {
        targetURI = new URI(target.toURI());
    } catch (final URISyntaxException usx) {
        throw new HttpException
            ("Cannot convert host to URI: " + target, usx);
    }
    final List<Proxy> proxies = psel.select(targetURI);

    final Proxy p = chooseProxy(proxies, target, request, context);

    HttpHost result = null;
    if (p.type() == Proxy.Type.HTTP) {
        // convert the socket address to an HttpHost
        if (!(p.address() instanceof InetSocketAddress)) {
            throw new HttpException
                ("Unable to handle non-Inet proxy address: "+p.address());
        }
        final InetSocketAddress isa = (InetSocketAddress) p.address();
        // assume default scheme (http)
        result = new HttpHost(getHost(isa), isa.getPort());
    }

    return result;
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:52,代碼來源:ProxySelectorRoutePlanner.java

示例12: findProxyServer

import java.net.ProxySelector; //導入方法依賴的package包/類
/**
 * Finds the host of the proxy server that was configured as part of the
 * JVM settings.
 *
 * @return proxy server as {@link HttpHost}, if no proxy then null
 */
protected HttpHost findProxyServer() {
    final ProxySelector proxySelector = ProxySelector.getDefault();
    List<Proxy> proxies = proxySelector.select(URI.create(config.getCloudAPIURL()));

    if (!proxies.isEmpty()) {
        /* The Apache HTTP Client doesn't understand the concept of multiple
         * proxies, so we use only the first one returned. */
        final Proxy proxy = proxies.get(0);

        switch (proxy.type()) {
            case DIRECT:
                return null;
            case SOCKS:
                throw new ConfigurationException("SOCKS proxies are unsupported");
            default:
                // do nothing and fall through
        }

        if (proxy.address() instanceof InetSocketAddress) {
            InetSocketAddress sa = (InetSocketAddress) proxy.address();

            return new HttpHost(sa.getHostName(), sa.getPort());
        } else {
            String msg = String.format(
                    "Expecting proxy to be instance of InetSocketAddress. "
                    + " Actually: %s", proxy.address());
            throw new ConfigurationException(msg);
        }
    } else {
        return null;
    }
}
 
開發者ID:joyent,項目名稱:java-triton,代碼行數:39,代碼來源:CloudApiConnectionFactory.java

示例13: newAddress

import java.net.ProxySelector; //導入方法依賴的package包/類
private Address newAddress(String name) {
  return new Address(name, 1, Dns.SYSTEM, SocketFactory.getDefault(), null, null, null,
      new RecordingOkAuthenticator("password"), null, Collections.<Protocol>emptyList(),
      Collections.<ConnectionSpec>emptyList(),
      ProxySelector.getDefault());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:7,代碼來源:ConnectionPoolTest.java

示例14: install

import java.net.ProxySelector; //導入方法依賴的package包/類
static void install(String hostToIgnore, int portToIgnore) {
    ProxySelector defaultProxySelector = ProxySelector.getDefault();
    ProxySelector ignoreHostProxySelector = new IgnoreHostProxySelector(defaultProxySelector, hostToIgnore, portToIgnore);
    ProxySelector.setDefault(ignoreHostProxySelector);
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:6,代碼來源:IgnoreHostProxySelector.java

示例15: createHttpRoutePlanner

import java.net.ProxySelector; //導入方法依賴的package包/類
@Override
protected HttpRoutePlanner createHttpRoutePlanner() {
    return new ProxySelectorRoutePlanner(getConnectionManager().getSchemeRegistry(),
            ProxySelector.getDefault());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:6,代碼來源:SystemDefaultHttpClient.java


注:本文中的java.net.ProxySelector.getDefault方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。