|
|
@ -86,10 +86,10 @@ public class HttpClientDownloader extends AbstractDownloader {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
HttpHost proxyHost = null;
|
|
|
|
HttpHost proxyHost = null;
|
|
|
|
Proxy proxy = null; //TODO
|
|
|
|
Proxy proxy = null; //TODO
|
|
|
|
if (site.getHttpProxyPool() != null && site.getHttpProxyPool().isEnable()) {
|
|
|
|
if (site != null && site.getHttpProxyPool() != null && site.getHttpProxyPool().isEnable()) {
|
|
|
|
proxy = site.getHttpProxyFromPool();
|
|
|
|
proxy = site.getHttpProxyFromPool();
|
|
|
|
proxyHost = proxy.getHttpHost();
|
|
|
|
proxyHost = proxy.getHttpHost();
|
|
|
|
} else if(site.getHttpProxy()!= null){
|
|
|
|
} else if (site != null && site.getHttpProxy() != null){
|
|
|
|
proxyHost = site.getHttpProxy();
|
|
|
|
proxyHost = site.getHttpProxy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -107,24 +107,20 @@ public class HttpClientDownloader extends AbstractDownloader {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
logger.warn("download page {} error", request.getUrl(), e);
|
|
|
|
logger.warn("download page {} error", request.getUrl(), e);
|
|
|
|
if (site.getCycleRetryTimes() > 0) {
|
|
|
|
if (site != null && site.getCycleRetryTimes() > 0) {
|
|
|
|
return addToCycleRetry(request, site);
|
|
|
|
return addToCycleRetry(request, site);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onError(request);
|
|
|
|
onError(request);
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
request.putExtra(Request.STATUS_CODE, statusCode);
|
|
|
|
|
|
|
|
if (site.getHttpProxyPool()!=null && site.getHttpProxyPool().isEnable()) {
|
|
|
|
|
|
|
|
site.returnHttpProxyToPool((HttpHost) request.getExtra(Request.PROXY), (Integer) request
|
|
|
|
|
|
|
|
.getExtra(Request.STATUS_CODE));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (httpResponse != null) {
|
|
|
|
if (httpResponse != null) {
|
|
|
|
//ensure the connection is released back to pool
|
|
|
|
//ensure the connection is released back to pool
|
|
|
|
EntityUtils.consume(httpResponse.getEntity());
|
|
|
|
EntityUtils.consumeQuietly(httpResponse.getEntity());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
request.putExtra(Request.STATUS_CODE, statusCode);
|
|
|
|
logger.warn("close response fail", e);
|
|
|
|
if (site != null && site.getHttpProxyPool() != null && site.getHttpProxyPool().isEnable()) {
|
|
|
|
|
|
|
|
site.returnHttpProxyToPool((HttpHost) request.getExtra(Request.PROXY), (Integer) request
|
|
|
|
|
|
|
|
.getExtra(Request.STATUS_CODE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -145,11 +141,15 @@ public class HttpClientDownloader extends AbstractDownloader {
|
|
|
|
requestBuilder.addHeader(headerEntry.getKey(), headerEntry.getValue());
|
|
|
|
requestBuilder.addHeader(headerEntry.getKey(), headerEntry.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
|
|
|
|
|
|
|
|
.setConnectionRequestTimeout(site.getTimeOut())
|
|
|
|
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
|
|
|
|
|
|
|
|
if (site != null) {
|
|
|
|
|
|
|
|
requestConfigBuilder.setConnectionRequestTimeout(site.getTimeOut())
|
|
|
|
.setSocketTimeout(site.getTimeOut())
|
|
|
|
.setSocketTimeout(site.getTimeOut())
|
|
|
|
.setConnectTimeout(site.getTimeOut())
|
|
|
|
.setConnectTimeout(site.getTimeOut())
|
|
|
|
.setCookieSpec(CookieSpecs.BEST_MATCH);
|
|
|
|
.setCookieSpec(CookieSpecs.BEST_MATCH);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (proxy != null) {
|
|
|
|
if (proxy != null) {
|
|
|
|
requestConfigBuilder.setProxy(proxy);
|
|
|
|
requestConfigBuilder.setProxy(proxy);
|
|
|
|
request.putExtra(Request.PROXY, proxy);
|
|
|
|
request.putExtra(Request.PROXY, proxy);
|
|
|
|