use of org.platformlayer.ops.helpers.CurlRequest in project platformlayer by platformlayer.
the class HttpProxyHelper method chooseProxy.
private String chooseProxy(OpsTarget target, List<String> proxies) {
String bestProxy = null;
TimeSpan bestTime = null;
for (String proxy : proxies) {
// {
// // We choose the fastest proxy that gives us a 200 response
// String url = proxy + "acng-report.html";
// CurlRequest request = new CurlRequest(url);
// request.setTimeout(5);
// try {
// CurlResult result = request.executeRequest(target);
// if (result.getHttpResult() != 200) {
// log.info("Unexpected response code while testing proxy: " + proxy + ". Code=" + result.getHttpResult());
// continue;
// }
// TimeSpan timeTotal = result.getTimeTotal();
// if (bestTime == null || timeTotal.isLessThan(bestTime)) {
// bestProxy = proxy;
// bestTime = timeTotal;
// }
// } catch (ProcessExecutionException e) {
// log.info("Error while testing proxy: " + proxy, e);
// }
// }
{
// We choose the fastest proxy that gives us a 200 response
String url = "http://ftp.debian.org/debian/dists/stable/Release.gpg";
CurlRequest request = new CurlRequest(url);
request.proxy = proxy;
request.timeout = TimeSpan.FIVE_SECONDS;
try {
CurlResult result = request.executeRequest(target);
if (result.getHttpResult() != 200) {
log.info("Unexpected response code while testing proxy: " + proxy + ". Code=" + result.getHttpResult());
continue;
}
TimeSpan timeTotal = result.getTimeTotal();
if (bestTime == null || timeTotal.isLessThan(bestTime)) {
bestProxy = proxy;
bestTime = timeTotal;
}
} catch (OpsException e) {
log.info("Error while testing proxy: " + proxy, e);
}
}
}
return bestProxy;
}
Aggregations