當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。