|
|
|
@ -50,13 +50,17 @@ public class HttpClientPool {
|
|
|
|
|
|
|
|
|
|
private HttpClient generateClient(Site site) {
|
|
|
|
|
HttpParams params = new BasicHttpParams();
|
|
|
|
|
if (site != null && site.getUserAgent() != null) {
|
|
|
|
|
params.setParameter(CoreProtocolPNames.USER_AGENT, site.getUserAgent());
|
|
|
|
|
}
|
|
|
|
|
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 1000);
|
|
|
|
|
params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 2000);
|
|
|
|
|
|
|
|
|
|
HttpProtocolParamBean paramsBean = new HttpProtocolParamBean(params);
|
|
|
|
|
paramsBean.setVersion(HttpVersion.HTTP_1_1);
|
|
|
|
|
if (site != null && site.getCharset() != null) {
|
|
|
|
|
paramsBean.setContentCharset(site.getCharset());
|
|
|
|
|
}
|
|
|
|
|
paramsBean.setUseExpectContinue(false);
|
|
|
|
|
|
|
|
|
|
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
|
|
|
@ -67,7 +71,9 @@ public class HttpClientPool {
|
|
|
|
|
connectionManager.setMaxTotal(poolSize);
|
|
|
|
|
connectionManager.setDefaultMaxPerRoute(100);
|
|
|
|
|
DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager, params);
|
|
|
|
|
if (site != null) {
|
|
|
|
|
generateCookie(httpClient, site);
|
|
|
|
|
}
|
|
|
|
|
httpClient.getParams().setIntParameter("http.socket.timeout", 60000);
|
|
|
|
|
httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
|
|
|
|
|
return httpClient;
|
|
|
|
@ -75,11 +81,13 @@ public class HttpClientPool {
|
|
|
|
|
|
|
|
|
|
private void generateCookie(DefaultHttpClient httpClient, Site site) {
|
|
|
|
|
CookieStore cookieStore = new BasicCookieStore();
|
|
|
|
|
if (site.getCookies() != null) {
|
|
|
|
|
for (Map.Entry<String, String> cookieEntry : site.getCookies().entrySet()) {
|
|
|
|
|
BasicClientCookie cookie = new BasicClientCookie(cookieEntry.getKey(), cookieEntry.getValue());
|
|
|
|
|
cookie.setDomain(site.getDomain());
|
|
|
|
|
cookieStore.addCookie(cookie);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
httpClient.setCookieStore(cookieStore);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|