当前位置: 首页>>代码示例>>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;未经允许,请勿转载。