當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpConnectionManagerParams.setDefaultMaxConnectionsPerHost方法代碼示例

本文整理匯總了Java中org.apache.commons.httpclient.params.HttpConnectionManagerParams.setDefaultMaxConnectionsPerHost方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpConnectionManagerParams.setDefaultMaxConnectionsPerHost方法的具體用法?Java HttpConnectionManagerParams.setDefaultMaxConnectionsPerHost怎麽用?Java HttpConnectionManagerParams.setDefaultMaxConnectionsPerHost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.httpclient.params.HttpConnectionManagerParams的用法示例。


在下文中一共展示了HttpConnectionManagerParams.setDefaultMaxConnectionsPerHost方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: constructHttpClient

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
protected HttpClient constructHttpClient()
{
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpClient httpClient = new HttpClient(connectionManager);
    HttpClientParams params = httpClient.getParams();
    params.setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true);
    params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, true);
    if (socketTimeout != null) 
    {
        params.setSoTimeout(socketTimeout);
    }
    HttpConnectionManagerParams connectionManagerParams = httpClient.getHttpConnectionManager().getParams();
    connectionManagerParams.setMaxTotalConnections(maxTotalConnections);
    connectionManagerParams.setDefaultMaxConnectionsPerHost(maxHostConnections);
    connectionManagerParams.setConnectionTimeout(connectionTimeout);

    return httpClient;
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:19,代碼來源:HttpClientFactory.java

示例2: init

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的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);
    
}
 
開發者ID:magenm,項目名稱:bsming,代碼行數:21,代碼來源:HttpClientUtil.java

示例3: HttpClient

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的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);
        }
    }
}
 
開發者ID:jpbirdy,項目名稱:WordsDetection,代碼行數:27,代碼來源:HttpClient.java

示例4: HttpClient

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
public HttpClient(int maxConPerHost, int conTimeOutMs, int soTimeOutMs,
			int maxSize) {
		
//		MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
		SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager(true);
		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);
	}
 
開發者ID:dehuinet,項目名稱:minxing_java_sdk,代碼行數:18,代碼來源:HttpClient.java

示例5: loadProxyConfig

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
/**
 * Load proxy configuration when proxy config has changed
 */
private void loadProxyConfig(){
	connectionManager = new MultiThreadedHttpConnectionManager();
	HttpConnectionManagerParams params = new HttpConnectionManagerParams();

	params.setSoTimeout(proxyConfig.getSoTimeout());
	params.setConnectionTimeout(proxyConfig.getConnectionTimeout());
	params.setMaxTotalConnections(proxyConfig.getMaxTotalConnections());
	params.setDefaultMaxConnectionsPerHost(proxyConfig
			.getDefaultMaxConnectionsPerHost());

	connectionManager.setParams(params);
	httpClient = new HttpClient(connectionManager);
	
	configureCallbacks();
}
 
開發者ID:geosolutions-it,項目名稱:OpenSDI-Manager2,代碼行數:19,代碼來源:ProxyServiceImpl.java

示例6: setConfiguration

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
/**
 * Define client configuration
 * @param httpClient instance to configure
 */
private static void setConfiguration(final HttpClient httpClient) {
    final HttpConnectionManagerParams httpParams = httpClient.getHttpConnectionManager().getParams();
    // define connect timeout:
    httpParams.setConnectionTimeout(NetworkSettings.DEFAULT_CONNECT_TIMEOUT);
    // define read timeout:
    httpParams.setSoTimeout(NetworkSettings.DEFAULT_SOCKET_READ_TIMEOUT);

    // define connection parameters:
    httpParams.setMaxTotalConnections(NetworkSettings.DEFAULT_MAX_TOTAL_CONNECTIONS);
    httpParams.setDefaultMaxConnectionsPerHost(NetworkSettings.DEFAULT_MAX_HOST_CONNECTIONS);

    // set content-encoding to UTF-8 instead of default ISO-8859
    final HttpClientParams httpClientParams = httpClient.getParams();
    // define timeout value for allocation of connections from the pool
    httpClientParams.setConnectionManagerTimeout(NetworkSettings.DEFAULT_CONNECT_TIMEOUT);
    // encoding to UTF-8
    httpClientParams.setParameter(HttpClientParams.HTTP_CONTENT_CHARSET, "UTF-8");
    // avoid retries (3 by default):
    httpClientParams.setParameter(HttpMethodParams.RETRY_HANDLER, _httpNoRetryHandler);
    
    // Customize the user agent:
    httpClientParams.setParameter(HttpMethodParams.USER_AGENT, System.getProperty(NetworkSettings.PROPERTY_USER_AGENT));
}
 
開發者ID:JMMC-OpenDev,項目名稱:jMCS,代碼行數:28,代碼來源:Http.java

示例7: connectionParams

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
/**
 * Init the parameter settings for the http client
 */
private HttpConnectionManagerParams connectionParams() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(readMaxHostConnectionSetting());
    params.setMaxTotalConnections(readMaxTotalConnectionSetting());
    return params;

}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:11,代碼來源:ProxyFilter.java

示例8: Stubs

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
public Stubs(ConfigurationContext ctx, String bbUrl) throws AxisFault
{
	this.ctx = ctx;
	this.bbUrl = bbUrl;

	/*
	 * Must use deprecated class of setting up security because the SOAP
	 * response doesn't include a security header. Using the deprecated
	 * OutflowConfiguration class we can specify that the security
	 * header is only for the outgoing SOAP message.
	 */
	ofc = new OutflowConfiguration();
	ofc.setActionItems("UsernameToken Timestamp");
	ofc.setUser("session");
	ofc.setPasswordType("PasswordText");

	final MultiThreadedHttpConnectionManager conMan = new MultiThreadedHttpConnectionManager();
	final HttpConnectionManagerParams params = new HttpConnectionManagerParams();
	params.setMaxTotalConnections(1000);
	params.setDefaultMaxConnectionsPerHost(100);
	params.setSoTimeout(60000);
	params.setConnectionTimeout(30000);
	conMan.setParams(params);

	httpClient = new HttpClient(conMan);
	final HttpClientParams clientParams = httpClient.getParams();
	clientParams.setAuthenticationPreemptive(false);
	clientParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
	ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);

	contextWebservice = new ContextWSStub(ctx, PathUtils.filePath(bbUrl, "webapps/ws/services/Context.WS"));
	initStub(contextWebservice);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:34,代碼來源:BlackboardConnectorServiceImpl.java

示例9: buildClient

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
/**
 * Builds an HTTP client with the given settings. Settings are NOT reset to their default values after a client has
 * been created.
 * 
 * @return the created client.
 */
public HttpClient buildClient() {
    if (httpsProtocolSocketFactory != null) {
        Protocol.registerProtocol("https", new Protocol("https", httpsProtocolSocketFactory, 443));
    }

    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setAuthenticationPreemptive(isPreemptiveAuthentication());
    clientParams.setContentCharset(getContentCharSet());
    clientParams.setParameter(HttpClientParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(
            connectionRetryAttempts, false));

    HttpConnectionManagerParams connMgrParams = new HttpConnectionManagerParams();
    connMgrParams.setConnectionTimeout(getConnectionTimeout());
    connMgrParams.setDefaultMaxConnectionsPerHost(getMaxConnectionsPerHost());
    connMgrParams.setMaxTotalConnections(getMaxTotalConnections());
    connMgrParams.setReceiveBufferSize(getReceiveBufferSize());
    connMgrParams.setSendBufferSize(getSendBufferSize());
    connMgrParams.setTcpNoDelay(isTcpNoDelay());

    MultiThreadedHttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager();
    connMgr.setParams(connMgrParams);

    HttpClient httpClient = new HttpClient(clientParams, connMgr);

    if (proxyHost != null) {
        HostConfiguration hostConfig = new HostConfiguration();
        hostConfig.setProxy(proxyHost, proxyPort);
        httpClient.setHostConfiguration(hostConfig);

        if (proxyUsername != null) {
            AuthScope proxyAuthScope = new AuthScope(proxyHost, proxyPort);
            UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUsername,
                    proxyPassword);
            httpClient.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
        }
    }

    return httpClient;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:46,代碼來源:HttpClientBuilder.java

示例10: initialize

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的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);

}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:16,代碼來源:Client.java

示例11: HttpClient

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的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);
		}
	}
}
 
開發者ID:seagrape,項目名稱:kekoa,代碼行數:31,代碼來源:HttpClient.java

示例12: Client

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的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);
}
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:18,代碼來源:Client.java

示例13: createConnectionManager

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
/**
 * Creates an instance of MultiThreadedHttpConnectionManager using HttpClient 3.x APIs
 *
 * @param properties Properties to configure MultiThreadedHttpConnectionManager
 * @return An instance of properly configured MultiThreadedHttpConnectionManager
 */
private HttpConnectionManager createConnectionManager(Properties properties) {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    if (properties == null || properties.isEmpty()) {
        throw new IllegalArgumentException("Parameters required to initialize HttpClient instances " +
                "associated with OAuth token validation service stub are not provided");
    }
    String maxConnectionsPerHostParam = properties.getProperty("MaxConnectionsPerHost");
    if (maxConnectionsPerHostParam == null || maxConnectionsPerHostParam.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("MaxConnectionsPerHost parameter is not explicitly defined. Therefore, the default, " +
                    "which is 2, will be used");
        }
    } else {
        params.setDefaultMaxConnectionsPerHost(Integer.parseInt(maxConnectionsPerHostParam));
    }

    String maxTotalConnectionsParam = properties.getProperty("MaxTotalConnections");
    if (maxTotalConnectionsParam == null || maxTotalConnectionsParam.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("MaxTotalConnections parameter is not explicitly defined. Therefore, the default, " +
                    "which is 10, will be used");
        }
    } else {
        params.setMaxTotalConnections(Integer.parseInt(maxTotalConnectionsParam));
    }
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return connectionManager;
}
 
開發者ID:wso2,項目名稱:carbon-device-mgt,代碼行數:36,代碼來源:OAuthTokenValidationStubFactory.java

示例14: createHttpClient

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的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;
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:31,代碼來源:BenchmarkHttpClient3Test.java

示例15: Client

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的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);
}
 
開發者ID:lifeng5042,項目名稱:RStore,代碼行數:17,代碼來源:Client.java


注:本文中的org.apache.commons.httpclient.params.HttpConnectionManagerParams.setDefaultMaxConnectionsPerHost方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。