Paulo Levi wrote:
But it's completely unintuitive! I can't know if i need to bother the user about proxy configuration before trying with no proxy, but trying to use that disallows the use of any other.

Trying to wrap Proxy.NO_PROXY to circumvent that, even if technically possible, just makes the code fail in the next line.

if (p.type() != Proxy.Type.SOCKS)
            throw new SocketException("Unknown proxy type : " + p.type());

I'm doing this because it's the natural way to create the behavior i want, only bugging the user for the proxy if needed. If you have another idea that doesn't involve bogus requests to google.com <http://google.com> or other "know assumed forever" sites i'd like to hear it.

The most likely way to tell that you're behind a firewall is to catch NoRouteToHostException which is thrown when trying to connect to an address that can't be reached. As it is hinted in its javadoc: http://java.sun.com/javase/6/docs/api/java/net/NoRouteToHostException.html However, firewalls vary in nature, so there is no unique way to detect them. For instance in some cases you won't even be able to resolve the URL hostname because the internal DNS won't resolve external addresses. There is a reason web browsers don't auto-detect you're behind a firewall....

Your best bet, I think, is to attempt a direct connection while catching both NoRouteToHostException and UnknownHostException. If either of these happen, assuming you're certain of your host name, chances are you are behind a firewall.
begin:vcard
fn:Jean-Christophe Collet
n:Collet;Jean-Christophe
org:Sun Microsystems
adr:;;2 rue de Jargonnant;Geneva;;1207;Switzerland
email;internet:jean-christophe.col...@sun.com
title:Staff Engineer
x-mozilla-html:FALSE
version:2.1
end:vcard

Reply via email to