This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

HttpURLConnection locks up on connect()  RSS feed

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks
Phil
 
Author and ninkuma
Marshal
Posts: 66789
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use UBB code tags (read this) when posting code to preserve the formatting.

Also, as this really has nothing to do with JSP per se, it's been moved to the Internet Protocols forum as a more appropriate location.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!