本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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;
}
示例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");
}
示例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);
}
示例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;
}
示例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()) {
}
}
示例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
}
}
示例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);
}
}
示例11: example1
import java.net.ProxySelector; //导入方法依赖的package包/类
public void example1() {
ProxySearch proxySearch = ProxySearch.getDefaultProxySearch();
ProxySelector myProxySelector = proxySearch.getProxySelector();
ProxySelector.setDefault(myProxySelector);
}
示例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);
}
示例13: tearDown
import java.net.ProxySelector; //导入方法依赖的package包/类
@Override
public void tearDown() {
ProxySelector.setDefault(defaultPS);
}
示例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", "");
}
示例15: tearDown
import java.net.ProxySelector; //导入方法依赖的package包/类
@Override
protected void tearDown() throws Exception {
super.tearDown();
ProxySelector.setDefault(defaultPS);
}