use of java.net.Proxy in project jdk8u_jdk by JetBrains.
the class SecurityPolicy method test6578647.
static void test6578647() throws Exception {
BufferedReader reader;
java.net.Authenticator.setDefault(new KnowAllAuthenticator());
reader = new BufferedReader(new InputStreamReader(webUrl.openConnection().getInputStream()));
if (!reader.readLine().equals(CONTENT)) {
throw new RuntimeException("Bad content");
}
reader = new BufferedReader(new InputStreamReader(proxyUrl.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_HOST, proxyPort))).getInputStream()));
if (!reader.readLine().equals(CONTENT)) {
throw new RuntimeException("Bad content");
}
}
use of java.net.Proxy in project jdk8u_jdk by JetBrains.
the class B6737819 method main.
public static void main(String[] args) throws Exception {
System.setProperty("http.proxyHost", "myproxy");
System.setProperty("http.proxyPort", "8080");
ProxySelector sel = ProxySelector.getDefault();
java.util.List<Proxy> l;
// from going through the HTTP proxy
for (String s : uris) {
l = sel.select(new URI(s));
if (l.size() == 1 && l.get(0).type() != Proxy.Type.DIRECT) {
throw new RuntimeException("ProxySelector returned the wrong proxy for " + s);
}
}
// Let's override the default nonProxyHosts and make sure we now get a
// HTTP proxy
System.setProperty("http.nonProxyHosts", "");
for (String s : uris) {
l = sel.select(new URI(s));
if (l.size() == 1 && l.get(0).type() != Proxy.Type.HTTP) {
throw new RuntimeException("ProxySelector returned the wrong proxy for " + s);
}
}
}
use of java.net.Proxy in project android_frameworks_base by AOSPA.
the class PacProxySelector method parseResponse.
private static List<Proxy> parseResponse(String response) {
String[] split = response.split(";");
List<Proxy> ret = Lists.newArrayList();
for (String s : split) {
String trimmed = s.trim();
if (trimmed.equals("DIRECT")) {
ret.add(java.net.Proxy.NO_PROXY);
} else if (trimmed.startsWith(PROXY)) {
Proxy proxy = proxyFromHostPort(Type.HTTP, trimmed.substring(PROXY.length()));
if (proxy != null) {
ret.add(proxy);
}
} else if (trimmed.startsWith(SOCKS)) {
Proxy proxy = proxyFromHostPort(Type.SOCKS, trimmed.substring(SOCKS.length()));
if (proxy != null) {
ret.add(proxy);
}
}
}
if (ret.size() == 0) {
ret.add(java.net.Proxy.NO_PROXY);
}
return ret;
}
use of java.net.Proxy in project yyl_example by Relucent.
the class HttpProxy method main.
public static void main(String[] args) {
try {
URL url = new URL("http://www.baidu.com");
// 创建代理服务器
InetSocketAddress addr = new InetSocketAddress("10.14.38.235", 9090);
// Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr); // Socket 代理
// http 代理
Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
// 如果我们知道代理server的名字, 可以直接使用
// 结束
URLConnection conn = url.openConnection(proxy);
InputStream in = conn.getInputStream();
// InputStream in = url.openStream();
String s = toString(in);
System.out.println(s);
} catch (Exception e) {
e.printStackTrace();
}
}
use of java.net.Proxy in project android_frameworks_base by ResurrectionRemix.
the class PacProxySelector method parseResponse.
private static List<Proxy> parseResponse(String response) {
String[] split = response.split(";");
List<Proxy> ret = Lists.newArrayList();
for (String s : split) {
String trimmed = s.trim();
if (trimmed.equals("DIRECT")) {
ret.add(java.net.Proxy.NO_PROXY);
} else if (trimmed.startsWith(PROXY)) {
Proxy proxy = proxyFromHostPort(Type.HTTP, trimmed.substring(PROXY.length()));
if (proxy != null) {
ret.add(proxy);
}
} else if (trimmed.startsWith(SOCKS)) {
Proxy proxy = proxyFromHostPort(Type.SOCKS, trimmed.substring(SOCKS.length()));
if (proxy != null) {
ret.add(proxy);
}
}
}
if (ret.size() == 0) {
ret.add(java.net.Proxy.NO_PROXY);
}
return ret;
}
Aggregations