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


Java ProxySelector.setDefault方法代碼示例

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


在下文中一共展示了ProxySelector.setDefault方法的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: 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

示例3: example2

import java.net.ProxySelector; //導入方法依賴的package包/類
public void example2() {
	ProxySearch proxySearch = new ProxySearch();

	if (PlatformUtil.getCurrentPlattform() == Platform.WIN) {
		proxySearch.addStrategy(Strategy.IE);
		proxySearch.addStrategy(Strategy.FIREFOX);
		proxySearch.addStrategy(Strategy.JAVA);
	} else if (PlatformUtil.getCurrentPlattform() == Platform.LINUX) {
		proxySearch.addStrategy(Strategy.GNOME);
		proxySearch.addStrategy(Strategy.KDE);
		proxySearch.addStrategy(Strategy.FIREFOX);
	} else {
		proxySearch.addStrategy(Strategy.OS_DEFAULT);
	}

	ProxySelector myProxySelector = proxySearch.getProxySelector();

	ProxySelector.setDefault(myProxySelector);
}
 
開發者ID:MarkusBernhardt,項目名稱:proxy-vole,代碼行數:20,代碼來源:Examples.java

示例4: doRegisterPropertyEditors

import java.net.ProxySelector; //導入方法依賴的package包/類
/** Register NB specific property editors.
     *  Allows property editor unit tests to work correctly without 
     *  initializing full NetBeans environment.
     *  @since 1.98 */
    private static final void doRegisterPropertyEditors() {
        //issue 31879
//        if (editorsRegistered) return;
//        String[] syspesp = PropertyEditorManager.getEditorSearchPath();
//        String[] nbpesp = new String[] {
//            "org.netbeans.beaninfo.editors", // NOI18N
//            "org.openide.explorer.propertysheet.editors", // NOI18N
//        };
//        String[] allpesp = new String[syspesp.length + nbpesp.length];
//        System.arraycopy(nbpesp, 0, allpesp, 0, nbpesp.length);
//        System.arraycopy(syspesp, 0, allpesp, nbpesp.length, syspesp.length);
//        PropertyEditorManager.setEditorSearchPath(allpesp);
//        PropertyEditorManager.registerEditor (java.lang.Character.TYPE, org.netbeans.beaninfo.editors.CharEditor.class);
//        PropertyEditorManager.registerEditor(String[].class, org.netbeans.beaninfo.editors.StringArrayEditor.class); 
//        // use replacement hintable/internationalizable primitive editors - issues 20376, 5278
//        PropertyEditorManager.registerEditor (Integer.TYPE, org.netbeans.beaninfo.editors.IntEditor.class);
//        PropertyEditorManager.registerEditor (Boolean.TYPE, org.netbeans.beaninfo.editors.BoolEditor.class);
        
        NodeOp.registerPropertyEditors();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                NodeOp.registerPropertyEditors();
            }
        });

        ProxySelector selector = Lookup.getDefault().lookup(ProxySelector.class);
        if (selector != null) {
            // install java.net.ProxySelector
            ProxySelector.setDefault(selector);
        }

        editorsRegistered = true;
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:39,代碼來源:CoreBridgeImpl.java

示例5: setUp

import java.net.ProxySelector; //導入方法依賴的package包/類
@Override
protected void setUp() throws Exception {
    MY_PS.called = 0;
    selector = Lookup.getDefault().lookup(ProxySelector.class);
    if (selector != null) {
        // install java.net.ProxySelector
        ProxySelector.setDefault(selector);
    }
    TO_LOCALHOST = new URI("http://localhost");
    TO_NB = new URI("http://netbeans.org");
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:CanProxyToLocalhostTest.java

示例6: installExternalSystemProxy

import java.net.ProxySelector; //導入方法依賴的package包/類
public static void installExternalSystemProxy() {
    // see proxies list at http://proxylist.hidemyass.com/
    Proxy systemProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("162.8.230.7", 11180));
    ProxySelector mockedProxySelector = Mockito.mock(ProxySelector.class);
    when(mockedProxySelector.select(Mockito.<URI>any())).thenReturn(Lists.newArrayList(systemProxy));
    ProxySelector.setDefault(mockedProxySelector);
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:8,代碼來源:ProxyCacheTestUtils.java

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

示例8: main

import java.net.ProxySelector; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    ProxySelector.setDefault(new HTTPProxySelector());
    try (ServerSocket ss = new ServerSocket(0);
         Socket s1 = new Socket(ss.getInetAddress(), ss.getLocalPort());
         Socket s2 = ss.accept()) {
    }

   ProxySelector.setDefault(new NullHTTPProxySelector());
    try (ServerSocket ss = new ServerSocket(0);
         Socket s1 = new Socket(ss.getInetAddress(), ss.getLocalPort());
         Socket s2 = ss.accept()) {
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:BadProxySelector.java

示例9: main

import java.net.ProxySelector; //導入方法依賴的package包/類
public static void main(String args[]) throws MalformedURLException {
    ProxySelector.setDefault(new NoProxyTestSelector());

    URL url = URI.create("http://127.0.0.1/").toURL();
    URLConnection connection;
    try {
        connection = url.openConnection(Proxy.NO_PROXY);
        connection.connect();
    } catch (IOException ignore) {
        //ignore
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:NoProxyTest.java

示例10: testUrl

import java.net.ProxySelector; //導入方法依賴的package包/類
/*************************************************************************
 * Test the given URL with the given Proxy Search.
 ************************************************************************/

protected void testUrl() {
	try {
		if (this.urlField.getText().trim().length() == 0) {
			ProxyTester.this.logArea.append("ERROR\tPlease enter an URL first.\n");
			return;
		}

		this.logArea.setText("");

		Strategy pss = (Strategy) this.modes.getSelectedItem();
		ProxySearch ps = new ProxySearch();
		ps.addStrategy(pss);
		ProxySelector psel = ps.getProxySelector();
		if (psel == null) {
			ProxyTester.this.logArea.append("ERROR\tNo proxy settings available for this mode.\n");
			return;
		}
		ProxySelector.setDefault(psel);

		URL url = new URL(this.urlField.getText().trim());
		List<Proxy> result = psel.select(url.toURI());
		if (result == null || result.size() == 0) {
			ProxyTester.this.logArea.append("INFO\tNo proxy found for this url.\n");
			return;
		}

		ProxyTester.this.logArea.append("INFO\tProxy Settings found using " + pss + " strategy.\n");
		ProxyTester.this.logArea.append("INFO\tProxy used for URL is: " + result.get(0) + "\n");

	} catch (Exception e) {
		JOptionPane.showMessageDialog(this, "Error:" + e.getMessage(), "Error checking URL.",
		        JOptionPane.ERROR_MESSAGE);
	}

}
 
開發者ID:MarkusBernhardt,項目名稱:proxy-vole,代碼行數:40,代碼來源:ProxyTester.java

示例11: example1

import java.net.ProxySelector; //導入方法依賴的package包/類
public void example1() {
	ProxySearch proxySearch = ProxySearch.getDefaultProxySearch();
	ProxySelector myProxySelector = proxySearch.getProxySelector();

	ProxySelector.setDefault(myProxySelector);
}
 
開發者ID:MarkusBernhardt,項目名稱:proxy-vole,代碼行數:7,代碼來源:Examples.java

示例12: tearDown

import java.net.ProxySelector; //導入方法依賴的package包/類
@After public void tearDown() throws Exception {
  ProxySelector.setDefault(DEFAULT_PROXY_SELECTOR);
  CookieManager.setDefault(DEFAULT_COOKIE_HANDLER);
  ResponseCache.setDefault(DEFAULT_RESPONSE_CACHE);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:6,代碼來源:OkHttpClientTest.java

示例13: tearDown

import java.net.ProxySelector; //導入方法依賴的package包/類
@Override
public void tearDown() {
    ProxySelector.setDefault(defaultPS);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:5,代碼來源:NetworkSettingsTest.java

示例14: tearDown

import java.net.ProxySelector; //導入方法依賴的package包/類
protected void tearDown() throws Exception {
    super.tearDown();
    ProxySelector.setDefault(defaultPS);
    System.setProperty("netbeans.t9y.svn.user.config.path", "");
    System.setProperty("netbeans.t9y.svn.nb.config.path", "");
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:7,代碼來源:SvnConfigFilesTest.java

示例15: tearDown

import java.net.ProxySelector; //導入方法依賴的package包/類
@Override
protected void tearDown() throws Exception {
    super.tearDown();
    ProxySelector.setDefault(defaultPS);         
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:6,代碼來源:ExceptionHandlerTest.java


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