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


Java HttpConnectionManager類代碼示例

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


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

示例1: run

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
/**
 * Closes idle connections.
 */
public synchronized void run() {
    while (!shutdown) {
        Iterator iter = connectionManagers.iterator();
        
        while (iter.hasNext()) {
            HttpConnectionManager connectionManager = (HttpConnectionManager) iter.next();
            handleCloseIdleConnections(connectionManager);
        }
        
        try {
            this.wait(timeoutInterval);
        } catch (InterruptedException e) {
        }
    }
    // clear out the connection managers now that we're shutdown
    this.connectionManagers.clear();
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:21,代碼來源:IdleConnectionTimeoutThread.java

示例2: run

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
@Override
public void run() {
	try {
		while (!shutdown) {
			synchronized (this) {
				wait(5000);
				for (HttpConnectionManager m : connMgr) {
					// Close expired connections
					// m.closeExpiredConnections();
					// Optionally, close connections
					// that have been idle longer than 30 sec
					m.closeIdleConnections(30000);
				}
			}
		}
	} catch (InterruptedException ex) {
		// terminate
	}
}
 
開發者ID:OpenSoftwareSolutions,項目名稱:PDFReporter-Studio,代碼行數:20,代碼來源:IdleConnectionMonitorThread.java

示例3: initConfigurationContext

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
private void initConfigurationContext() throws Exception {
    HttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);

    File configFile = new File(DEFAULT_AXIS2_XML);

    if (!configFile.exists()) {
        configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext();
        configurationContext.setProperty(HTTPConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST, MAX_CONNECTIONS_PER_HOST);
    } else {
        configurationContext = ConfigurationContextFactory.
                createConfigurationContextFromFileSystem(DEFAULT_CLIENT_REPO, DEFAULT_AXIS2_XML);
    }
    configurationContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
    configurationContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);

    Map<String, TransportOutDescription> transportsOut =
            configurationContext.getAxisConfiguration().getTransportsOut();

    for (TransportOutDescription transportOutDescription : transportsOut.values()) {
        if (Constants.TRANSPORT_HTTP.equals(transportOutDescription.getName()) ||
                Constants.TRANSPORT_HTTPS.equals(transportOutDescription.getName())) {
            transportOutDescription.getSender().init(configurationContext, transportOutDescription);
        }
    }
}
 
開發者ID:wso2-attic,項目名稱:carbon-identity,代碼行數:27,代碼來源:BasicAuthEntitlementServiceClient.java

示例4: getHttpClientInstance

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
/**
 * A HttpClient with basic authentication and no host or port setting. Can only be used to retrieve absolute URLs
 * 
 * @param user
 *            can be NULL
 * @param password
 *            can be NULL
 * @return HttpClient
 */
public static HttpClient getHttpClientInstance(String user, String password) {
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionParams params = connectionManager.getParams();
    // wait max 10 seconds to establish connection
    params.setConnectionTimeout(10000);
    // a read() call on the InputStream associated with this Socket
    // will block for only this amount
    params.setSoTimeout(10000);
    HttpClient c = new HttpClient(connectionManager);

    // use basic authentication if available
    if (user != null && user.length() > 0) {
        AuthScope authScope = new AuthScope(null, -1, null);
        Credentials credentials = new UsernamePasswordCredentials(user, password);
        c.getState().setCredentials(authScope, credentials);
    }
    return c;
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:28,代碼來源:HttpClientFactory.java

示例5: run

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
/**
 * Closes idle connections.
 */
public synchronized void run() {
    while (!shutdown) {
        Iterator iter = connectionManagers.iterator();
        
        while (iter.hasNext()) {
            HttpConnectionManager connectionManager = (HttpConnectionManager) iter.next();
            connectionManager.closeIdleConnections(connectionTimeout);
        }
        
        try {
            this.wait(timeoutInterval);
        } catch (InterruptedException e) {
        }
    }
    // clear out the connection managers now that we're shutdown
    this.connectionManagers.clear();
}
 
開發者ID:magneticmoon,項目名稱:httpclient3-ntml,代碼行數:21,代碼來源:IdleConnectionTimeoutThread.java

示例6: close

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
@Override
public void close()
{
   if(httpClient != null)
   {
       HttpConnectionManager connectionManager = httpClient.getHttpConnectionManager();
       if(connectionManager instanceof MultiThreadedHttpConnectionManager)
       {
           ((MultiThreadedHttpConnectionManager)connectionManager).shutdown();
       }
   }
    
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:14,代碼來源:AbstractHttpClient.java

示例7: IdleConnectionCloser

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
private IdleConnectionCloser(HttpConnectionManager httpConnectionManager)
{
    super("FastServletProxyFactory.IdleConnectionCloser");
    this.httpConnectionManager = httpConnectionManager;
    this.setName("IdleConnectionCloser");
    this.setDaemon(true);
    this.setPriority(Thread.MIN_PRIORITY);
}
 
開發者ID:goldmansachs,項目名稱:jrpip,代碼行數:9,代碼來源:FastServletProxyFactory.java

示例8: logCurrentHttpConnection

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
public static void logCurrentHttpConnection(HttpClient httpClient, HostConfiguration hostConfiguration, HttpPool poolMode) {
	if (Engine.logEngine.isInfoEnabled() && httpClient != null) {
		if (poolMode == HttpPool.no) {
			Engine.logEngine.info("(HttpUtils) Use a not pooled HTTP connection for " + hostConfiguration.getHost());
		} else {
			HttpConnectionManager httpConnectionManager = httpClient.getHttpConnectionManager();
			if (httpConnectionManager != null && httpConnectionManager instanceof MultiThreadedHttpConnectionManager) {
				MultiThreadedHttpConnectionManager mtHttpConnectionManager = (MultiThreadedHttpConnectionManager) httpConnectionManager;
				int connections = mtHttpConnectionManager.getConnectionsInPool();
				int connectionsForHost = mtHttpConnectionManager.getConnectionsInPool(hostConfiguration);
				Engine.logEngine.info("(HttpUtils) Use a " + poolMode.name() + " pool with " + connections + " HTTP connections, " + connectionsForHost + " for " + hostConfiguration.getHost() + "; Getting one ... [for instance " + httpClient.hashCode() + "]");
			}
		}
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:16,代碼來源:HttpUtils.java

示例9: removeConnectionManager

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
/**
 * Removes the connection manager from this class.  The idle connections from the connection
 * manager will no longer be automatically closed by this class.
 * 
 * @param connectionManager The connection manager to remove
 */
public synchronized void removeConnectionManager(HttpConnectionManager connectionManager) {
    if (shutdown) {
        throw new IllegalStateException("IdleConnectionTimeoutThread has been shutdown");
    }
    this.connectionManagers.remove(connectionManager);
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:13,代碼來源:IdleConnectionTimeoutThread.java

示例10: httpConnectionManager

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
/**
 * 使用獨立的連接管理器。
 * @param connectionManager 鏈接管理器
 * @return
 */
public HttpReq httpConnectionManager(HttpConnectionManager connectionManager) {
    httpConnectionManager = connectionManager;
    externalConnectionManager = true;

    return this;
}
 
開發者ID:bingoohuang,項目名稱:javacode-demo,代碼行數:12,代碼來源:HttpReq.java

示例11: RequestConnectionHttp

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
public void RequestConnectionHttp(String url, String user, String pass, int timeout) throws Exception {
    HttpClient client = new HttpClient();
    HttpConnectionManager hcm = client.getHttpConnectionManager();
    HttpConnectionManagerParams hcmParam = hcm.getParams();
    hcmParam.setConnectionTimeout(timeout + 1000);
    hcm.setParams(hcmParam);
    client.setHttpConnectionManager(hcm);
    
    if (user != null && pass != null) {
        client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, pass));
    }
    GetMethod get = new GetMethod(url);
    get.setDoAuthentication(true);

    try {
        int status = client.executeMethod(get);
        if (status != 200) {
            System.out.println(status + "\n" + get.getResponseBodyAsString());
            throw new Exception("Failed: status=" + status);
        }
        setLastcrres("OK");
    } catch (Exception e) {
    	setLastcrres(e.getMessage());
    	System.out.println("HTTP CR OOPS: " + e.getMessage() + "\n");
        throw e;
    } finally {
        get.releaseConnection();
    }
}
 
開發者ID:navisidhu,項目名稱:libreacs,代碼行數:30,代碼來源:HostsBean.java

示例12: interrupt

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
/** {@inheritDoc} */
@Override
public boolean interrupt() {
    HttpClient client = savedClient;
    if (client != null) {
        savedClient = null;
        // TODO - not sure this is the best method
        final HttpConnectionManager httpConnectionManager = client.getHttpConnectionManager();
        if (httpConnectionManager instanceof SimpleHttpConnectionManager) {// Should be true
            ((SimpleHttpConnectionManager)httpConnectionManager).shutdown();
        }
    }
    return client != null;
}
 
開發者ID:johrstrom,項目名稱:cloud-meter,代碼行數:15,代碼來源:HTTPHC3Impl.java

示例13: testHttpGetWithoutConversion

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
@Test
public void testHttpGetWithoutConversion() throws Exception {

    // This is needed as by default there are 2 parallel
    // connections to some host and there is nothing that
    // closes the http connection here.
    // Need to set the httpConnectionManager 
    HttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
    httpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(5);
    context.getComponent("http", HttpComponent.class).setHttpConnectionManager(httpConnectionManager);
   

    String endpointName = "seda:withoutConversion?concurrentConsumers=5";
    sendMessagesTo(endpointName, 5);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:16,代碼來源:MultiThreadedHttpGetTest.java

示例14: HttpEndpoint

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
public HttpEndpoint(String endPointURI, HttpComponent component, URI httpURI, HttpClientParams clientParams,
                    HttpConnectionManager httpConnectionManager, HttpClientConfigurer clientConfigurer) throws URISyntaxException {
    super(endPointURI, component, httpURI);
    this.clientParams = clientParams;
    this.httpClientConfigurer = clientConfigurer;
    this.httpConnectionManager = httpConnectionManager;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:8,代碼來源:HttpEndpoint.java

示例15: OAuthTokenValidationStubFactory

import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
public OAuthTokenValidationStubFactory(String url, String adminUsername, String adminPassword,
                                       Properties properties) {
    this.validateUrl(url);
    this.url = url;

    this.validateCredentials(adminUsername, adminPassword);
    this.basicAuthHeader = new String(Base64.encodeBase64((adminUsername + ":" + adminPassword).getBytes()));

    HttpConnectionManager connectionManager = this.createConnectionManager(properties);
    this.httpClient = new HttpClient(connectionManager);
}
 
開發者ID:wso2,項目名稱:carbon-device-mgt,代碼行數:12,代碼來源:OAuthTokenValidationStubFactory.java


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