本文整理汇总了Java中org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.getParams方法的典型用法代码示例。如果您正苦于以下问题:Java MultiThreadedHttpConnectionManager.getParams方法的具体用法?Java MultiThreadedHttpConnectionManager.getParams怎么用?Java MultiThreadedHttpConnectionManager.getParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.MultiThreadedHttpConnectionManager
的用法示例。
在下文中一共展示了MultiThreadedHttpConnectionManager.getParams方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入方法依赖的package包/类
/**
*
* @throws Exception .
*/
private void init() throws Exception {
httpClientManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = httpClientManager.getParams();
params.setStaleCheckingEnabled(true);
params.setMaxTotalConnections(1000);
params.setDefaultMaxConnectionsPerHost(500);
params.setConnectionTimeout(2000);
params.setSoTimeout(3000);
/** 设置从连接池中获取连接超时。*/
HttpClientParams clientParams = new HttpClientParams();
clientParams.setConnectionManagerTimeout(1000);
httpClient = new HttpClient(clientParams, httpClientManager);
}
示例2: initialize
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入方法依赖的package包/类
private void initialize(Cluster cluster, boolean sslEnabled) {
this.cluster = cluster;
this.sslEnabled = sslEnabled;
MultiThreadedHttpConnectionManager manager =
new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams managerParams = manager.getParams();
managerParams.setConnectionTimeout(2000); // 2 s
managerParams.setDefaultMaxConnectionsPerHost(10);
managerParams.setMaxTotalConnections(100);
extraHeaders = new ConcurrentHashMap<String, String>();
this.httpClient = new HttpClient(manager);
HttpClientParams clientParams = httpClient.getParams();
clientParams.setVersion(HttpVersion.HTTP_1_1);
}
示例3: HttpClient
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入方法依赖的package包/类
public HttpClient(int maxConPerHost, int conTimeOutMs, int soTimeOutMs,
int maxSize) {
connectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = connectionManager.getParams();
params.setDefaultMaxConnectionsPerHost(maxConPerHost);
params.setConnectionTimeout(conTimeOutMs);
params.setSoTimeout(soTimeOutMs);
HttpClientParams clientParams = new HttpClientParams();
// 忽略cookie 避免 Cookie rejected 警告
clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
client = new org.apache.commons.httpclient.HttpClient(clientParams,
connectionManager);
Protocol myhttps = new Protocol("https", new MySSLSocketFactory(), 443);
Protocol.registerProtocol("https", myhttps);
this.maxSize = maxSize;
// 支持proxy
if (proxyHost != null && !proxyHost.equals("")) {
client.getHostConfiguration().setProxy(proxyHost, proxyPort);
client.getParams().setAuthenticationPreemptive(true);
if (proxyAuthUser != null && !proxyAuthUser.equals("")) {
client.getState().setProxyCredentials(
AuthScope.ANY,
new UsernamePasswordCredentials(proxyAuthUser,
proxyAuthPassword));
log("Proxy AuthUser: " + proxyAuthUser);
log("Proxy AuthPassword: " + proxyAuthPassword);
}
}
}
示例4: Client
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入方法依赖的package包/类
/**
* Constructor
* @param cluster the cluster definition
*/
public Client(Cluster cluster) {
this.cluster = cluster;
MultiThreadedHttpConnectionManager manager =
new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams managerParams = manager.getParams();
managerParams.setConnectionTimeout(2000); // 2 s
managerParams.setDefaultMaxConnectionsPerHost(10);
managerParams.setMaxTotalConnections(100);
extraHeaders = new ConcurrentHashMap<String, String>();
this.httpClient = new HttpClient(manager);
HttpClientParams clientParams = httpClient.getParams();
clientParams.setVersion(HttpVersion.HTTP_1_1);
}
示例5: createHttpClient
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入方法依赖的package包/类
public static HttpClient createHttpClient() {
HttpClient result = null;
try {
result = new HttpClient();
// 使用多緒HttpClient
MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams managerParams = httpConnectionManager
.getParams();
managerParams.setDefaultMaxConnectionsPerHost(100);
managerParams.setMaxTotalConnections(200);
// 連線超時
managerParams.setConnectionTimeout(5 * 1000);
// 讀取超時
managerParams.setSoTimeout(5 * 1000);
//
result.setHttpConnectionManager(httpConnectionManager);
//
HttpClientParams params = result.getParams();
// http.protocol.content-charset
params.setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
// 失敗 retry 3 次
params.setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
} catch (Exception ex) {
ex.printStackTrace();
}
return result;
}
示例6: Client
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入方法依赖的package包/类
/**
* Constructor
* @param cluster the cluster definition
*/
public Client(Cluster cluster) {
this.cluster = cluster;
MultiThreadedHttpConnectionManager manager =
new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams managerParams = manager.getParams();
managerParams.setConnectionTimeout(2000); // 2 s
managerParams.setDefaultMaxConnectionsPerHost(10);
managerParams.setMaxTotalConnections(100);
this.httpClient = new HttpClient(manager);
HttpClientParams clientParams = httpClient.getParams();
clientParams.setVersion(HttpVersion.HTTP_1_1);
}
示例7: MultithreadedDownloader
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入方法依赖的package包/类
MultithreadedDownloader(int threads) {
this.threads = threads;
MultiThreadedHttpConnectionManager conMgr = new MultiThreadedHttpConnectionManager();
HostConfiguration hc = new HostConfiguration();
HttpConnectionManagerParams params = conMgr.getParams();
params.setMaxConnectionsPerHost(hc, 10);
httpClient = new HttpClient(conMgr);
httpClient.setHostConfiguration(hc);
}
示例8: setUp
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
super.setUp();
MultiThreadedHttpConnectionManager connManag = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams managParams = connManag.getParams();
managParams.setConnectionTimeout(10000); // 1
managParams.setSoTimeout(10000); //2
client = new HttpClient(connManag);
client.getParams().setParameter("http.connection-manager.timeout", new Long(10000)); //3
}
示例9: HttpClient
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入方法依赖的package包/类
public HttpClient(int maxConPerHost, int conTimeOutMs, int soTimeOutMs,
int maxSize) {
connectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = connectionManager.getParams();
params.setDefaultMaxConnectionsPerHost(maxConPerHost);
params.setConnectionTimeout(conTimeOutMs);
params.setSoTimeout(soTimeOutMs);
HttpClientParams clientParams = new HttpClientParams();
clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
client = new org.apache.commons.httpclient.HttpClient(clientParams, connectionManager);
Protocol myhttps = new Protocol("https", new MySSLSocketFactory(), 443);
Protocol.registerProtocol("https", myhttps);
}