当前位置: 首页>>代码示例>>Java>>正文


Java ProxySelector.select方法代码示例

本文整理汇总了Java中java.net.ProxySelector.select方法的典型用法代码示例。如果您正苦于以下问题:Java ProxySelector.select方法的具体用法?Java ProxySelector.select怎么用?Java ProxySelector.select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.ProxySelector的用法示例。


在下文中一共展示了ProxySelector.select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: findProxy

import java.net.ProxySelector; //导入方法依赖的package包/类
/**
 * Return a proxy if exist
 * @return
 * 	null if no proxy, the InetSocketAddress else of proxy
 */
public static InetSocketAddress findProxy() {
	logger.info("detecting proxies");
	ProxySearch ps = ProxySearch.getDefaultProxySearch();
	ProxySelector myProxySelector = ps.getProxySelector(); 
	ProxySelector.setDefault(myProxySelector);


	List<Proxy> l = null;
	if(myProxySelector == null) {
       	logger.info("No Proxy");
		return null;
	}
	try {
		l = myProxySelector.select(new URI("https://graph.microsoft.com"));
	}  
	catch (URISyntaxException e) {
	    e.printStackTrace();
	}
	if (l != null) {
	    for (Iterator<Proxy> iter = l.iterator(); iter.hasNext();) {
	        java.net.Proxy proxy = (java.net.Proxy) iter.next();
	        logger.info("proxy type: " + proxy.type());

	        InetSocketAddress addr = (InetSocketAddress) proxy.address();
	        if (addr == null) {
	        	logger.info("No Proxy");
	            return null;
	        } 
	        logger.info("Hostname: " + addr.getHostName());
	        logger.info("Port : " + addr.getPort());
	        return addr;
	    }
	}
   	logger.info("No Proxy");
	return null;
}
 
开发者ID:OwaNotifier,项目名称:owa-notifier,代码行数:42,代码来源:RestfullAcessProxy.java

示例6: 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

示例7: testManualSocks

import java.net.ProxySelector; //导入方法依赖的package包/类
/*************************************************************************
 * Test method
 * 
 * @throws ProxyException
 *             on proxy detection error.
 * @throws URISyntaxException
 *             on invalid URL syntax.
 ************************************************************************/
@Test
public void testManualSocks() throws ProxyException, URISyntaxException {
	TestUtil.setTestDataFolder("ff3_manual");

	ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector();

	List<Proxy> result = ps.select(TestUtil.SOCKS_TEST_URI);
	assertEquals(TestUtil.SOCKS_TEST_PROXY, result.get(0));
}
 
开发者ID:MarkusBernhardt,项目名称:proxy-vole,代码行数:18,代码来源:FirefoxTest.java

示例8: emptyURIShouldNotRaiseNPE

import java.net.ProxySelector; //导入方法依赖的package包/类
/*************************************************************************
 * Test method.
 * 
 * @throws URISyntaxException
 *             on error parsing the URI.
 * @throws ProxyException
 *             on selector error.
 ************************************************************************/
@Test
public void emptyURIShouldNotRaiseNPE() throws URISyntaxException, ProxyException {
	ProxySearch proxySearch = ProxySearch.getDefaultProxySearch();
	ProxySelector myProxySelector = proxySearch.getProxySelector();
	if (myProxySelector != null) {
		myProxySelector.select(new URI(""));
	}
}
 
开发者ID:MarkusBernhardt,项目名称:proxy-vole,代码行数:17,代码来源:DesktopProxySearchTest.java

示例9: testNone

import java.net.ProxySelector; //导入方法依赖的package包/类
/*************************************************************************
 * Test method
 * 
 * @throws ProxyException
 *             on proxy detection error.
 ************************************************************************/
@Test
public void testNone() throws ProxyException {
	TestUtil.setTestDataFolder("gnome_none");
	ProxySelector ps = new GnomeProxySearchStrategy().getProxySelector();
	List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);

	assertEquals(Proxy.NO_PROXY, result.get(0));
}
 
开发者ID:MarkusBernhardt,项目名称:proxy-vole,代码行数:15,代码来源:GnomeProxySearchTest.java

示例10: testManualHttp

import java.net.ProxySelector; //导入方法依赖的package包/类
/*************************************************************************
 * Test method
 * 
 * @throws ProxyException
 *             on proxy detection error.
 * @throws URISyntaxException
 *             on invalid URL syntax.
 ************************************************************************/
@Test
public void testManualHttp() throws ProxyException, URISyntaxException {
	TestUtil.setTestDataFolder("gnome_manual");

	ProxySelector ps = new GnomeProxySearchStrategy().getProxySelector();

	List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
	assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0));
}
 
开发者ID:MarkusBernhardt,项目名称:proxy-vole,代码行数:18,代码来源:GnomeProxySearchTest.java

示例11: testManualFtp

import java.net.ProxySelector; //导入方法依赖的package包/类
/*************************************************************************
 * Test method
 * 
 * @throws ProxyException
 *             on proxy detection error.
 * @throws URISyntaxException
 *             on invalid URL syntax.
 ************************************************************************/
@Test
public void testManualFtp() throws ProxyException, URISyntaxException {
	TestUtil.setTestDataFolder("ff3_manual");

	ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector();

	List<Proxy> result = ps.select(TestUtil.FTP_TEST_URI);
	assertEquals(TestUtil.FTP_TEST_PROXY, result.get(0));
}
 
开发者ID:MarkusBernhardt,项目名称:proxy-vole,代码行数:18,代码来源:FirefoxTest.java

示例12: testWhiteList

import java.net.ProxySelector; //导入方法依赖的package包/类
/*************************************************************************
 * Test method
 * 
 * @throws ProxyException
 *             on proxy detection error.
 * @throws URISyntaxException
 *             on invalid URL syntax.
 ************************************************************************/
@Test
public void testWhiteList() throws ProxyException, URISyntaxException {
	TestUtil.setTestDataFolder("ff3_white_list");

	ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector();

	List<Proxy> result = ps.select(TestUtil.NO_PROXY_TEST_URI);
	assertEquals(Proxy.NO_PROXY, result.get(0));
}
 
开发者ID:MarkusBernhardt,项目名称:proxy-vole,代码行数:18,代码来源:FirefoxTest.java

示例13: testPac

import java.net.ProxySelector; //导入方法依赖的package包/类
/*************************************************************************
 * Test method
 * 
 * @throws ProxyException
 *             on proxy detection error.
 * @throws URISyntaxException
 *             on invalid URL syntax.
 ************************************************************************/
@Test
public void testPac() throws ProxyException, URISyntaxException {
	TestUtil.setTestDataFolder("gnome_pac_script");

	ProxySelector ps = new GnomeProxySearchStrategy().getProxySelector();

	List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
	assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0));
}
 
开发者ID:MarkusBernhardt,项目名称:proxy-vole,代码行数:18,代码来源:GnomeProxySearchTest.java

示例14: testWhiteList

import java.net.ProxySelector; //导入方法依赖的package包/类
/*************************************************************************
 * Test method
 * 
 * @throws ProxyException
 *             on proxy detection error.
 * @throws URISyntaxException
 *             on invalid URL syntax.
 ************************************************************************/
@Test
public void testWhiteList() throws ProxyException, URISyntaxException {
	TestUtil.setTestDataFolder("gnome_white_list");

	ProxySelector ps = new GnomeProxySearchStrategy().getProxySelector();

	List<Proxy> result = ps.select(TestUtil.NO_PROXY_TEST_URI);
	assertEquals(Proxy.NO_PROXY, result.get(0));
}
 
开发者ID:MarkusBernhardt,项目名称:proxy-vole,代码行数:18,代码来源:GnomeProxySearchTest.java

示例15: testFixedProxy2

import java.net.ProxySelector; //导入方法依赖的package包/类
/*************************************************************************
 * Test method
 ************************************************************************/
@Test
public void testFixedProxy2() {
	ProxySelector ps = new FixedProxySelector(TestUtil.HTTP_TEST_PROXY);

	List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
	assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0));
}
 
开发者ID:MarkusBernhardt,项目名称:proxy-vole,代码行数:11,代码来源:FixedProxyTest.java


注:本文中的java.net.ProxySelector.select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。