Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HttpURLConnection locks up on connect()  RSS feed

 
Phil Powell
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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
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.
 
Phil Powell
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Resolved:



Using NetBeans 5.5 using J2SE 1.5.0
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!