How to find out if the internet connection is not available from your j2ee web app, since some portions of our UI will not work properly if an internet connection is not available. So instead of failing with a bad exception, I would like to fail gracefully.
Share
The only universal way to test if “the internet” is working is to attempt to retrieve the resource you want. Anything else potentially can give you misleading or unhelpful results under certain circumstances.
For instance, if you use some site that is “nearly always available” as a proxy for the internet working … it might be down or inaccessible when the site you really want to talk to is up and accessible. Or vice versa. In the former case, your application might conclude that “the internet” is unavailable and not even try to access the site you want to access. In the latter case, your application’s diagnosis that “the internet” is available is immaterial to accessing the site it really needs to talk to.