Bug, add null check to site in HttpClientDownloader & HttpClientGenerator
parent
e9341d0291
commit
79522f941e
|
@ -86,10 +86,10 @@ public class HttpClientDownloader extends AbstractDownloader {
|
|||
try {
|
||||
HttpHost proxyHost = null;
|
||||
Proxy proxy = null; //TODO
|
||||
if (site.getHttpProxyPool() != null && site.getHttpProxyPool().isEnable()) {
|
||||
if (site != null && site.getHttpProxyPool() != null && site.getHttpProxyPool().isEnable()) {
|
||||
proxy = site.getHttpProxyFromPool();
|
||||
proxyHost = proxy.getHttpHost();
|
||||
} else if(site.getHttpProxy()!= null){
|
||||
} else if (site != null && site.getHttpProxy() != null){
|
||||
proxyHost = site.getHttpProxy();
|
||||
}
|
||||
|
||||
|
@ -107,14 +107,14 @@ public class HttpClientDownloader extends AbstractDownloader {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
logger.warn("download page {} error", request.getUrl(), e);
|
||||
if (site.getCycleRetryTimes() > 0) {
|
||||
if (site != null && site.getCycleRetryTimes() > 0) {
|
||||
return addToCycleRetry(request, site);
|
||||
}
|
||||
onError(request);
|
||||
return null;
|
||||
} finally {
|
||||
request.putExtra(Request.STATUS_CODE, statusCode);
|
||||
if (site.getHttpProxyPool()!=null && site.getHttpProxyPool().isEnable()) {
|
||||
if (site != null && site.getHttpProxyPool() != null && site.getHttpProxyPool().isEnable()) {
|
||||
site.returnHttpProxyToPool((HttpHost) request.getExtra(Request.PROXY), (Integer) request
|
||||
.getExtra(Request.STATUS_CODE));
|
||||
}
|
||||
|
@ -145,11 +145,15 @@ public class HttpClientDownloader extends AbstractDownloader {
|
|||
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())
|
||||
.setConnectTimeout(site.getTimeOut())
|
||||
.setCookieSpec(CookieSpecs.BEST_MATCH);
|
||||
}
|
||||
|
||||
if (proxy != null) {
|
||||
requestConfigBuilder.setProxy(proxy);
|
||||
request.putExtra(Request.PROXY, proxy);
|
||||
|
|
|
@ -138,13 +138,18 @@ public class HttpClientGenerator {
|
|||
//解决post/redirect/post 302跳转问题
|
||||
httpClientBuilder.setRedirectStrategy(new CustomRedirectStrategy());
|
||||
|
||||
SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(site.getTimeOut()).setSoKeepAlive(true).setTcpNoDelay(true).build();
|
||||
SocketConfig.Builder socketConfigBuilder = SocketConfig.custom();
|
||||
socketConfigBuilder.setSoKeepAlive(true).setTcpNoDelay(true);
|
||||
if (site != null) {
|
||||
socketConfigBuilder.setSoTimeout(site.getTimeOut());
|
||||
}
|
||||
SocketConfig socketConfig = socketConfigBuilder.build();
|
||||
httpClientBuilder.setDefaultSocketConfig(socketConfig);
|
||||
connectionManager.setDefaultSocketConfig(socketConfig);
|
||||
if (site != null) {
|
||||
httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(site.getRetryTimes(), true));
|
||||
}
|
||||
generateCookie(httpClientBuilder, site);
|
||||
}
|
||||
return httpClientBuilder.build();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue