public URLInfo getURLInfo(URL url) {
return getURLInfo(url, 0);
}
public URLInfo getURLInfo(URL url, int timeout) {
HeadMethod head = null;
try {
head = doHead(url, timeout);
int status = head.getStatusCode();
head.releaseConnection();
if (status == HttpStatus.SC_OK) {
return new URLInfo(true, getResponseContentLength(head), getLastModified(head));
}
if (status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) {
Message.error("Your proxy requires authentication.");
} else if (String.valueOf(status).startsWith("4")) {
Message.verbose("CLIENT ERROR: " + head.getStatusText() + " url=" + url);
} else if (String.valueOf(status).startsWith("5")) {
Message.warn("SERVER ERROR: " + head.getStatusText() + " url=" + url);
}
Message.debug("HTTP response status: " + status + "=" + head.getStatusText() + " url="
+ url);
} catch (HttpException e) {
Message.error("HttpClientHandler: " + e.getMessage() + ":" + e.getReasonCode() + "="
+ e.getReason() + " url=" + url);
} catch (UnknownHostException e) {
Message.warn("Host " + e.getMessage() + " not found. url=" + url);
Message.info("You probably access the destination server through "
+ "a proxy server that is not well configured.");
} catch (IOException e) {
Message.error("HttpClientHandler: " + e.getMessage() + " url=" + url);
} catch (IllegalArgumentException e) {
// thrown by HttpClient to indicate the URL is not valid, this happens for instance
// when trying to download a dynamic version (cfr IVY-390)
} finally {
if (head != null) {
head.releaseConnection();
}
}
return UNAVAILABLE;
}