当前位置: 首页>>代码示例>>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;未经允许,请勿转载。