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


Java MultiThreadedHttpConnectionManager類代碼示例

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


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

示例1: HttpProtocolHandler

import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //導入依賴的package包/類
/**
 * 私有的構造方法
 */
private HttpProtocolHandler() {
    // 創建一個線程安全的HTTP連接池
    connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.getParams().setDefaultMaxConnectionsPerHost(defaultMaxConnPerHost);
    connectionManager.getParams().setMaxTotalConnections(defaultMaxTotalConn);

    IdleConnectionTimeoutThread ict = new IdleConnectionTimeoutThread();
    ict.addConnectionManager(connectionManager);
    ict.setConnectionTimeout(defaultIdleConnTimeout);

    ict.start();
}
 
開發者ID:dianbaer,項目名稱:epay,代碼行數:16,代碼來源:HttpProtocolHandler.java

示例2: HttpClientTransmitterImpl

import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //導入依賴的package包/類
public HttpClientTransmitterImpl()
{
    protocolMap = new TreeMap<String,Protocol>();
    protocolMap.put(HTTP_SCHEME_NAME, httpProtocol);
    protocolMap.put(HTTPS_SCHEME_NAME, httpsProtocol);

    httpClient = new HttpClient();
    httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager());
    httpMethodFactory = new StandardHttpMethodFactoryImpl();
    jsonErrorSerializer = new ExceptionJsonSerializer();

    // Create an HTTP Proxy Host if appropriate system properties are set
    httpProxyHost = HttpClientHelper.createProxyHost("http.proxyHost", "http.proxyPort", DEFAULT_HTTP_PORT);
    httpProxyCredentials = HttpClientHelper.createProxyCredentials("http.proxyUser", "http.proxyPassword");
    httpAuthScope = createProxyAuthScope(httpProxyHost);

    // Create an HTTPS Proxy Host if appropriate system properties are set
    httpsProxyHost = HttpClientHelper.createProxyHost("https.proxyHost", "https.proxyPort", DEFAULT_HTTPS_PORT);
    httpsProxyCredentials = HttpClientHelper.createProxyCredentials("https.proxyUser", "https.proxyPassword");
    httpsAuthScope = createProxyAuthScope(httpsProxyHost);
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:22,代碼來源:HttpClientTransmitterImpl.java

示例3: constructHttpClient

import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //導入依賴的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

示例4: getMaxConnectionsPerHost

import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //導入依賴的package包/類
/**
 * Gets the maximum number of connections to be used for a particular host config.  If
 * the value has not been specified for the given host the default value will be
 * returned.
 * 
 * @param hostConfiguration The host config.
 * @return The maximum number of connections to be used for the given host config.
 * 
 * @see #MAX_HOST_CONNECTIONS
 */
public int getMaxConnectionsPerHost(HostConfiguration hostConfiguration) {
    
    Map m = (Map) getParameter(MAX_HOST_CONNECTIONS);
    if (m == null) {
        // MAX_HOST_CONNECTIONS have not been configured, using the default value
        return MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS;
    } else {
        Integer max = (Integer) m.get(hostConfiguration);
        if (max == null && hostConfiguration != HostConfiguration.ANY_HOST_CONFIGURATION) {
            // the value has not been configured specifically for this host config,
            // use the default value
            return getMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION);
        } else {
            return (
                    max == null 
                    ? MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS 
                    : max.intValue()
                );
        }
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:32,代碼來源:HttpConnectionManagerParams.java

示例5: getInputStreamFromUrl

import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //導入依賴的package包/類
public static InputStream getInputStreamFromUrl(final String url, final String user, final String password) {

        try {
            final Pair<String, Integer> hostAndPort = validateUrl(url);
            final HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager());
            if ((user != null) && (password != null)) {
                httpclient.getParams().setAuthenticationPreemptive(true);
                final Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
                httpclient.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds);
                s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
            }
            // Execute the method.
            final GetMethod method = new GetMethod(url);
            final int statusCode = httpclient.executeMethod(method);

            if (statusCode != HttpStatus.SC_OK) {
                s_logger.error("Failed to read from URL: " + url);
                return null;
            }

            return method.getResponseBodyAsStream();
        } catch (final Exception ex) {
            s_logger.error("Failed to read from URL: " + url);
            return null;
        }
    }
 
開發者ID:MissionCriticalCloud,項目名稱:cosmic,代碼行數:27,代碼來源:UriUtils.java

示例6: getHttpClient

import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //導入依賴的package包/類
private HttpClient getHttpClient() {

        if (s_client == null) {
            final MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
            mgr.getParams().setDefaultMaxConnectionsPerHost(4);

            // TODO make it configurable
            mgr.getParams().setMaxTotalConnections(1000);

            s_client = new HttpClient(mgr);
            final HttpClientParams clientParams = new HttpClientParams();
            clientParams.setSoTimeout(ClusterServiceAdapter.ClusterMessageTimeOut.value() * 1000);

            s_client.setParams(clientParams);
        }
        return s_client;
    }
 
開發者ID:MissionCriticalCloud,項目名稱:cosmic,代碼行數:18,代碼來源:ClusterServiceServletImpl.java

示例7: DiamondSDKManagerImpl

import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //導入依賴的package包/類
public DiamondSDKManagerImpl(int connection_timeout, int require_timeout) throws IllegalArgumentException {
    if (connection_timeout < 0)
        throw new IllegalArgumentException("連接超時時間設置必須大於0[單位(毫秒)]!");
    if (require_timeout < 0)
        throw new IllegalArgumentException("請求超時時間設置必須大於0[單位(毫秒)]!");
    this.connection_timeout = connection_timeout;
    this.require_timeout = require_timeout;
    int maxHostConnections = 50;
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();

    connectionManager.getParams().setDefaultMaxConnectionsPerHost(maxHostConnections);
    connectionManager.getParams().setStaleCheckingEnabled(true);
    this.client = new HttpClient(connectionManager);
    // 設置連接超時時間
    client.getHttpConnectionManager().getParams().setConnectionTimeout(this.connection_timeout);
    // 設置讀超時為1分鍾
    client.getHttpConnectionManager().getParams().setSoTimeout(60 * 1000);
    client.getParams().setContentCharset("UTF-8");
    log.info("設置連接超時時間為: " + this.connection_timeout + "毫秒");
}
 
開發者ID:lysu,項目名稱:diamond,代碼行數:21,代碼來源:DiamondSDKManagerImpl.java

示例8: initHttpClient

import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //導入依賴的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

示例9: init

import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //導入依賴的package包/類
private synchronized void init() {
	client = new HttpClient(new MultiThreadedHttpConnectionManager());
	HttpClientParams params = client.getParams();
	if (encode != null && !encode.trim().equals("")) {
		params.setParameter("http.protocol.content-charset", encode);
		params.setContentCharset(encode);
	}
	if (timeout > 0) {
		params.setSoTimeout(timeout);
	}
	if (null != proxy) {
		HostConfiguration hc = new HostConfiguration();
		hc.setProxy(proxy.getHost(), proxy.getPort());
		client.setHostConfiguration(hc);
		client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxy.getUser(), proxy.getPassword()));
	}
	initialized = true;
}
 
開發者ID:anylineorg,項目名稱:anyline,代碼行數:19,代碼來源:HttpUtil.java

示例10: processor

import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //導入依賴的package包/類
@Bean
public SAMLProcessorImpl processor() {
    HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    ArtifactResolutionProfileImpl artifactResolutionProfile = new ArtifactResolutionProfileImpl(httpClient);
    HTTPSOAP11Binding soapBinding = new HTTPSOAP11Binding(parserPool());
    artifactResolutionProfile.setProcessor(new SAMLProcessorImpl(soapBinding));

    VelocityEngine velocityEngine = VelocityFactory.getEngine();
    Collection<SAMLBinding> bindings = new ArrayList<>();
    bindings.add(new HTTPRedirectDeflateBinding(parserPool()));
    bindings.add(new HTTPPostBinding(parserPool(), velocityEngine));
    bindings.add(new HTTPArtifactBinding(parserPool(), velocityEngine, artifactResolutionProfile));
    bindings.add(new HTTPSOAP11Binding(parserPool()));
    bindings.add(new HTTPPAOS11Binding(parserPool()));
    return new SAMLProcessorImpl(bindings);
}
 
開發者ID:ulisesbocchio,項目名稱:spring-boot-security-saml-samples,代碼行數:17,代碼來源:SAMLConfig.java

示例11: FullTextSearchEngine

import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //導入依賴的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

示例12: SolrClient

import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //導入依賴的package包/類
/**
    * @param solrUrl
    *                The solr URL of the server to connect
    */
   @Autowired
   public SolrClient(@Qualifier("fulltextSearchUrl")
   String solrUrl, @Qualifier("multiThreadedHttpConnectionManager")
   MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager) {
try {
    Assert.notNull(solrUrl, "solrClient does not accept null solrUrl");
    Assert
	    .notNull(multiThreadedHttpConnectionManager,
		    "solrClient does not accept null multiThreadedHttpConnectionManager");
    this.multiThreadedHttpConnectionManager = multiThreadedHttpConnectionManager;
    this.server = new CommonsHttpSolrServer(new URL(solrUrl),
	    new HttpClient(multiThreadedHttpConnectionManager));
    this.URL = !solrUrl.endsWith("/") ? solrUrl + "/" : solrUrl ;
    logger.info("connecting to solr on " + this.URL + "...");
} catch (MalformedURLException e) {
    throw new RuntimeException("Error connecting to Solr! : "
	    + e.getMessage());
}
   }
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:24,代碼來源:SolrClient.java

示例13: testIsAlive

import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //導入依賴的package包/類
@Test
   public void testIsAlive() {
assertTrue(fullTextSearchEngine.isAlive());
FullTextSearchEngine fullTextSearchEngineTobadUrl = new FullTextSearchEngine(
	new MultiThreadedHttpConnectionManager());
IsolrClient mockSolClient = EasyMock.createMock(IsolrClient.class);
EasyMock.expect(mockSolClient.isServerAlive()).andReturn(false);
EasyMock.replay(mockSolClient);
fullTextSearchEngineTobadUrl.setSolrClient(mockSolClient);

assertFalse(fullTextSearchEngineTobadUrl.isAlive());
EasyMock.verify(mockSolClient);

FullTextSearchEngine fullTextSearchEngineWithNullSolrClient = new FullTextSearchEngine(
	new MultiThreadedHttpConnectionManager());
fullTextSearchEngineWithNullSolrClient.setSolrClient(null);
assertFalse(fullTextSearchEngineWithNullSolrClient.isAlive());
   }
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:19,代碼來源:FulltextSearchEngineTest.java

示例14: 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);
    
}
 
開發者ID:magenm,項目名稱:bsming,代碼行數:21,代碼來源:HttpClientUtil.java

示例15: initConfigurationContext

import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //導入依賴的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


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