use of java.net.Proxy in project robovm by robovm.
the class FtpURLConnection method connect.
/**
* Establishes the connection to the resource specified by this
* <code>URL</code>
*
* @see #connected
* @see java.io.IOException
* @see URLStreamHandler
*/
@Override
public void connect() throws IOException {
// Use system-wide ProxySelect to select proxy list,
// then try to connect via elements in the proxy list.
List<Proxy> proxyList = null;
if (proxy != null) {
proxyList = new ArrayList<Proxy>(1);
proxyList.add(proxy);
} else {
ProxySelector selector = ProxySelector.getDefault();
if (selector != null) {
proxyList = selector.select(uri);
}
}
if (proxyList == null) {
currentProxy = null;
connectInternal();
} else {
ProxySelector selector = ProxySelector.getDefault();
Iterator<Proxy> iter = proxyList.iterator();
boolean connectOK = false;
String failureReason = "";
while (iter.hasNext() && !connectOK) {
currentProxy = iter.next();
try {
connectInternal();
connectOK = true;
} catch (IOException ioe) {
failureReason = ioe.getLocalizedMessage();
// should be invoked.
if (selector != null && Proxy.NO_PROXY != currentProxy) {
selector.connectFailed(uri, currentProxy.address(), ioe);
}
}
}
if (!connectOK) {
throw new IOException("Unable to connect to server: " + failureReason);
}
}
}
use of java.net.Proxy in project robovm by robovm.
the class OldSocketTest method test_ConstructorLjava_net_Proxy_Exception.
public void test_ConstructorLjava_net_Proxy_Exception() {
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);
try {
new Socket((Proxy) null);
fail("IllegalArgumentException was not thrown.");
} catch (IllegalArgumentException iae) {
//expected
}
}
use of java.net.Proxy in project robovm by robovm.
the class OldProxyTest method test_address.
public void test_address() {
Proxy proxy = new Proxy(Proxy.Type.SOCKS, address);
assertEquals(address, proxy.address());
try {
new Proxy(Proxy.Type.SOCKS, null);
fail("IllegalArgumentException was thrown.");
} catch (IllegalArgumentException iae) {
//expected
}
}
use of java.net.Proxy in project robovm by robovm.
the class OldProxyTest method test_type.
public void test_type() {
Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
assertEquals(Proxy.Type.HTTP, proxy.type());
proxy = new Proxy(Proxy.Type.SOCKS, address);
assertEquals(Proxy.Type.SOCKS, proxy.type());
proxy = Proxy.NO_PROXY;
assertEquals(Proxy.Type.DIRECT, proxy.type());
}
use of java.net.Proxy in project robovm by robovm.
the class HttpsURLConnectionTest method testProxyConnection.
/**
* Tests HTTPS connection process made through the proxy server.
*/
public void testProxyConnection() throws Throwable {
// setting up the properties pointing to the key/trust stores
setUpStoreProperties();
// create the SSLServerSocket which will be used by server side
ServerSocket ss = new ServerSocket(0);
// create the HostnameVerifier to check that Hostname verification
// is done
TestHostnameVerifier hnv = new TestHostnameVerifier();
HttpsURLConnection.setDefaultHostnameVerifier(hnv);
// create HttpsURLConnection to be tested
URL url = new URL("https://requested.host:55556/requested.data");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", ss.getLocalPort())));
connection.setSSLSocketFactory(getContext().getSocketFactory());
// perform the interaction between the peers and check the results
SSLSocket peerSocket = (SSLSocket) doInteraction(connection, ss);
checkConnectionStateParameters(connection, peerSocket);
// should silently exit
connection.connect();
}
Aggregations