SocketAddress addr1 = InetSocketAddress.createUnresolved("127.0.0.1",
80);
SocketAddress addr2 = new InetSocketAddress("localhost", 80);
Proxy proxy1 = new Proxy(Proxy.Type.HTTP, addr1);
// IllegalArgumentException test
try {
new Socket(proxy1);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
Proxy proxy2 = new Proxy(Proxy.Type.SOCKS, addr1);
// should not throw any exception
new Socket(proxy2);
new Socket(Proxy.NO_PROXY);
// SecurityException test
SecurityManager originalSecurityManager = System.getSecurityManager();
try {
System.setSecurityManager(new MockSecurityManager());
} catch (SecurityException e) {
System.err
.println("No permission to setSecurityManager, security related test in test_ConstructorLjava_net_Proxy_Security is ignored");
return;
}
Proxy proxy3 = new Proxy(Proxy.Type.SOCKS, addr1);
Proxy proxy4 = new Proxy(Proxy.Type.SOCKS, addr2);
try {
try {
new Socket(proxy3);
fail("should throw SecurityException");
} catch (SecurityException e) {