Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java beginner

  • 06-04-2015 08:59PM
    #1
    Registered Users, Registered Users 2 Posts: 1,192 ✭✭✭


    I attending a foundation level course for Java and am working on a networking assignment.

    The brief, at a high level, is to take a given URL and identify all links specified in the html. For each of those links, check if they're still valid, or broken.

    I've hit a problem on one of the links, www.irishurls.com. When I access this with Chrome, it returns an error
    The server at www.irishurls.com can't be found, because the DNS lookup failed.
    .

    My code is ;
    HttpURLConnection c = (HttpURLConnection) url.openConnection();
    c.setConnectTimeout(3000);
    c.setReadTimeout(3000);
    System.out.println(c.getResponseCode());
    

    When I run the code, in Eclipse, the console display just 'hangs' for this URL, i.e. the print statement is not shown in the console display, nor are any subsequent print statements. I assume this is because I do not have the correct handling in place for whatever is the outcome of the openConnection() command.

    Any suggestions ? FWIW the Timeout settings were added more in desperation than design.

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 339 ✭✭duffman85


    Are you sure this is the correct address and not just an example?

    It's hanging because DNS can't resolve www.irishurls.com to an IP address.

    This is what I got when I checked irishurls.com
    # nslookup irishurls.com
    Server:		192.168.192.1
    Address:	192.168.192.1#53
    
    Non-authoritative answer:
    Name:	irishurls.com.net
    Address: 74.221.212.214
    Name:	irishurls.com.net
    Address: 106.186.123.143
    Name:	irishurls.com.net
    Address: 199.167.196.149
    
    

    handy article explaining DNS http://www.diaryofaninja.com/blog/2012/03/03/devops-dns-for-developers-ndash-now-therersquos-no-excuse-not-to-know


  • Registered Users, Registered Users 2 Posts: 1,192 ✭✭✭TarfHead


    Thanks
    Yes, that is the correct address and my code should be able to handle the response, or lack of response, and move on to the next link. Mu difficulty is that I do not know what state/condition/etc. to check for.


  • Registered Users, Registered Users 2 Posts: 1,192 ✭✭✭TarfHead


    Turns out I had the try/catch specified incorrectly - should have had a catch specified for UnknownHostException.

    Thanks


Advertisement