Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java beginner

  • 06-04-2015 7: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