commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John C Cartwright" <>
Subject Commons HttpClient: HttpClient#setConnectionTimeout
Date Wed, 23 Feb 2005 19:58:46 GMT
Hello All,

I'm attempting to throw an exception when the connection cannot be 
established within 5 seconds (see code excerpt below). However when the 
target host is down (doesn't respond to ping), it takes much longer than 
5 seconds before the exception is actually thrown.

Can someone point out what I'm doing wrong?


-- john

        HttpClient client = new HttpClient();
        HttpMethod method = new GetMethod(url);
        client.setConnectionTimeout(5000);  //wait 5 seconds for response
        try {
            statusCode = client.executeMethod(method);
            String responseBody = method.getResponseBodyAsString();
        } catch (Exception e){
            log.fatal("error reading URL",e);
            throw new IllegalStateException ("Error reading URL");
        } finally {

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message