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


Java HttpConnectionManagerParams.setConnectionTimeout方法代碼示例

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


在下文中一共展示了HttpConnectionManagerParams.setConnectionTimeout方法的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: executeMethod

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
private static byte[] executeMethod(HttpMethodBase method, int timeout) throws Exception {
	InputStream in = null;
	try {
		method.addRequestHeader("Connection", "close");
		HttpClient client = new HttpClient();
		HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
		params.setConnectionTimeout(timeout);
		params.setSoTimeout(timeout);
		params.setStaleCheckingEnabled(false);
		ByteArrayOutputStream baos = new ByteArrayOutputStream(BUFFER_SIZE);
		client.executeMethod(method);
		in = method.getResponseBodyAsStream();
		byte[] buffer = new byte[BUFFER_SIZE];
		int len;
		while( (len = in.read(buffer)) > 0) {
			baos.write(buffer, 0, len);
		}
		return baos.toByteArray();
	} finally {
		if (in != null) {
			in.close();
		}
	}
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:25,代碼來源:HttpClientUtil.java

示例3: initHttpClient

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
protected void initHttpClient() {
    if (MockServer.isTestMode()) {
        return;
    }
    HostConfiguration hostConfiguration = new HostConfiguration();
    hostConfiguration.setHost(diamondConfigure.getDomainNameList().get(this.domainNamePos.get()),
        diamondConfigure.getPort());

    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.closeIdleConnections(diamondConfigure.getPollingIntervalTime() * 4000);

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
    params.setMaxConnectionsPerHost(hostConfiguration, diamondConfigure.getMaxHostConnections());
    params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections());
    params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
    // 設置讀超時為1分鍾,
    // [email protected]
    params.setSoTimeout(60 * 1000);

    connectionManager.setParams(params);
    httpClient = new HttpClient(connectionManager);
    httpClient.setHostConfiguration(hostConfiguration);
}
 
開發者ID:lysu,項目名稱:diamond,代碼行數:25,代碼來源:DefaultDiamondSubscriber.java

示例4: pageExists

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
private static boolean pageExists(@NotNull String url) {
  if (new File(url).exists()) {
    return true;
  }
  final HttpClient client = new HttpClient();
  final HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
  params.setSoTimeout(5 * 1000);
  params.setConnectionTimeout(5 * 1000);

  try {
    final HeadMethod method = new HeadMethod(url);
    final int rc = client.executeMethod(method);
    if (rc == 404) {
      return false;
    }
  }
  catch (IllegalArgumentException e) {
    return false;
  }
  catch (IOException ignored) {
  }
  return true;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:24,代碼來源:PythonDocumentationProvider.java

示例5: FullTextSearchEngine

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
/**
    * @param multiThreadedHttpConnectionManager
    *                The
    * @link {@link MultiThreadedHttpConnectionManager} that the fulltext search
    *       engine will use
    * @throws FullTextSearchException
    *                 If an error occured
    */
   @Autowired
   public FullTextSearchEngine(
    @Qualifier("multiThreadedHttpConnectionManager")
    MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager)
    throws FullTextSearchException {
Assert.notNull(multiThreadedHttpConnectionManager,
	"multiThreadedHttpConnectionManager can not be null");
HttpConnectionManagerParams p = new HttpConnectionManagerParams();
p.setSoTimeout(0);
p.setConnectionTimeout(0);
multiThreadedHttpConnectionManager.setParams(p);
this.httpClient = new HttpClient(multiThreadedHttpConnectionManager);
if (this.httpClient == null) {
    throw new FullTextSearchException(
	    "Can not instanciate http client with multiThreadedHttpConnectionManager : "
		    + multiThreadedHttpConnectionManager);
}
   }
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:27,代碼來源:FullTextSearchEngine.java

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: init

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    // Create a pool of HTTP connections to use to get the favicons
    client = new HttpClient(new MultiThreadedHttpConnectionManager());
    HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
    params.setConnectionTimeout(2000);
    params.setSoTimeout(2000);
    // Load the default favicon to use when no favicon was found of a remote host
    try {
        URL resource = config.getServletContext().getResource("/images/server_16x16.gif");
        defaultBytes = getImage(resource.toString());
    }
    catch (MalformedURLException e) {
        e.printStackTrace();
    }
    // Initialize caches.
    missesCache = CacheFactory.createCache("Favicon Misses");
    hitsCache = CacheFactory.createCache("Favicon Hits");
}
 
開發者ID:igniterealtime,項目名稱:Openfire,代碼行數:21,代碼來源:FaviconServlet.java

示例12: init

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
@Override
public void init(ServletConfig config) throws ServletException {
       super.init(config);
       // Create a pool of HTTP connections to use to get the favicons
       client = new HttpClient(new MultiThreadedHttpConnectionManager());
       HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
       params.setConnectionTimeout(2000);
       params.setSoTimeout(2000);
       // Load the default favicon to use when no favicon was found of a remote host
       try {
           URL resource = config.getServletContext().getResource("/images/server_16x16.gif");
           defaultBytes = getImage(resource.toString());
       }
       catch (MalformedURLException e) {
           e.printStackTrace();
       }
       // Initialize caches.
       missesCache = CacheFactory.createCache("Favicon Misses");
       hitsCache = CacheFactory.createCache("Favicon Hits");
   }
 
開發者ID:coodeer,項目名稱:g3server,代碼行數:21,代碼來源:FaviconServlet.java

示例13: getHttpClient

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
@NotNull
private static HttpClient getHttpClient(@Nullable GithubAuthData.BasicAuth basicAuth) {
  final HttpClient client = new HttpClient();
  HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
  params.setConnectionTimeout(CONNECTION_TIMEOUT); //set connection timeout (how long it takes to connect to remote host)
  params.setSoTimeout(CONNECTION_TIMEOUT); //set socket timeout (how long it takes to retrieve data from remote host)

  client.getParams().setContentCharset("UTF-8");
  // Configure proxySettings if it is required
  final HttpConfigurable proxySettings = HttpConfigurable.getInstance();
  if (proxySettings.USE_HTTP_PROXY && !StringUtil.isEmptyOrSpaces(proxySettings.PROXY_HOST)) {
    client.getHostConfiguration().setProxy(proxySettings.PROXY_HOST, proxySettings.PROXY_PORT);
    if (proxySettings.PROXY_AUTHENTICATION) {
      client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxySettings.PROXY_LOGIN,
                                                                                           proxySettings.getPlainProxyPassword()));
    }
  }
  if (basicAuth != null) {
    client.getParams().setCredentialCharset("UTF-8");
    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(basicAuth.getLogin(), basicAuth.getPassword()));
  }
  return client;
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:25,代碼來源:GithubApiUtil.java

示例14: RobotsTxtParser

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
public RobotsTxtParser(int timeout, int cacheSize) {
	robotsTxtCache = ExpiringLRUMap.create(cacheSize);

	int timeToWaitForResponse = (int) (timeout * DateUtils.MILLIS_PER_SECOND);
	HttpConnectionManagerParams hmcp = new HttpConnectionManagerParams();
	hmcp.setSoTimeout(timeToWaitForResponse);
	hmcp.setConnectionTimeout(timeToWaitForResponse);
	hcm = new MultiThreadedHttpConnectionManager();
	hcm.setParams(hmcp);
	client = new HttpClient(hcm);

	String proxyHost = FWProps.getStringProperty("http.proxyHost");
	int proxyPort = FWProps.getIntegerProperty("http.proxyPort");
	if (StringUtils.isNotBlank(proxyHost) && proxyPort > 0) {
		client.getHostConfiguration().setProxy(proxyHost, proxyPort);
	}
}
 
開發者ID:mjradwin,項目名稱:fraudwall-util,代碼行數:18,代碼來源:RobotsTxtParser.java

示例15: initHttpClient

import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入方法依賴的package包/類
protected void initHttpClient() {
	if (MockServer.isTestMode()) {
		return;
	}
	HostConfiguration hostConfiguration = new HostConfiguration();
	hostConfiguration.setHost(
			diamondConfigure.getDomainNameList().get(
					this.domainNamePos.get()), diamondConfigure.getPort());

	MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
	connectionManager.closeIdleConnections(diamondConfigure
			.getPollingIntervalTime() * 4000);

	HttpConnectionManagerParams params = new HttpConnectionManagerParams();
	params.setStaleCheckingEnabled(diamondConfigure
			.isConnectionStaleCheckingEnabled());
	params.setMaxConnectionsPerHost(hostConfiguration,
			diamondConfigure.getMaxHostConnections());
	params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections());
	params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
	// ���ö���ʱΪ1����,
	// [email protected]
	params.setSoTimeout(60 * 1000);

	connectionManager.setParams(params);
	httpClient = new HttpClient(connectionManager);
	httpClient.setHostConfiguration(hostConfiguration);
}
 
開發者ID:weijiahao001,項目名稱:tb_diamond,代碼行數:29,代碼來源:DefaultDiamondSubscriber.java


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