Reputation: 4547
I have created a Java Swing application. Some users can't connect to the internet when activating the application, checking program updates, etc. because they are using a Proxy.
I have been reading about the interesting ProxySelector Class. It is very nice, but i have some questions about it please :
Will this class detect all types of Proxies that can be used(HTTP, HTTPS, FTP, SOCK,...) ?
If the Proxy used needs authentication, will this class get its information automatically ?
I have written code to get the Proxy settings used. Now i need to test this but i do not have a proxy, so i was going to set a proxy like the instructions here, but is there a faster method ? Can i use Public Proxies to test this like hidemyass.com ?
Upvotes: 2
Views: 2250
Reputation: 47608
I can't answer all your questions, but here some of them:
1.I belive that it will use the proxy selector for HTTP, HTTPS ans SOCKS. AFAIK, FTP is not natively supported by the JVM.
2.For Authentication, you can use the following code:
Authenticator.setDefault(new Authenticator() {
private URL previous;
int count = 0;
@Override
protected PasswordAuthentication getPasswordAuthentication() {
try {
if (previous == getRequestingURL())
count++;
if (previous != getRequestingURL()) {
count = 0;
} else {
if (count<3) {
// Ask for login/passwd to the user
} else {
// Throw a RuntimeException to prevent locking the account
throw new TooManyFailedAttemptException();
}
return new PasswordAuthentication("login", "password".toCharArray());
}
} finally {
previous = getRequestingURL();
}
}
});
3.I guess that any public proxy is ok. I am not really sure on how you are going to ensure that your code is actually using it. Personally I set up a Squid proxy which is not that hard and there you can really trace your calls.
Upvotes: 3