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