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


Java PoolingHttpClientConnectionManager.setValidateAfterInactivity方法代碼示例

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


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

示例1: DefaultConnector

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
/**
 * 
 */
public DefaultConnector() {
	final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
	cm.closeIdleConnections(120, TimeUnit.SECONDS);

	// would be nice to set this from outside -> keep alive
	final SocketConfig sConfig = SocketConfig.custom().setSoKeepAlive(true).setSoTimeout(Context.SOCKET_TO).build();
	cm.setDefaultSocketConfig(sConfig);

	cm.setMaxTotal(150);
	cm.setDefaultMaxPerRoute(150);
	cm.setValidateAfterInactivity(0);

	final HttpRequestRetryHandler rh = new DefaultHttpRequestRetryHandler(3, true);
	httpClient = HttpClients.custom().setRetryHandler(rh).setConnectionManager(cm).build();
}
 
開發者ID:ad-tech-group,項目名稱:openssp,代碼行數:19,代碼來源:DefaultConnector.java

示例2: create

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
@Override
public HttpClientConnectionManager create(final HttpClientSettings settings) {
    ConnectionSocketFactory sslsf = getPreferredSocketFactory(settings);

    final PoolingHttpClientConnectionManager cm = new
            PoolingHttpClientConnectionManager(
            createSocketFactoryRegistry(sslsf),
            null,
            DefaultSchemePortResolver.INSTANCE,
            new DelegatingDnsResolver(settings.getDnsResolver()),
            settings.getConnectionPoolTTL(),
            TimeUnit.MILLISECONDS);

    cm.setValidateAfterInactivity(settings.getValidateAfterInactivityMillis());
    cm.setDefaultMaxPerRoute(settings.getMaxConnections());
    cm.setMaxTotal(settings.getMaxConnections());
    cm.setDefaultSocketConfig(buildSocketConfig(settings));
    cm.setDefaultConnectionConfig(buildConnectionConfig(settings));

    return cm;
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:22,代碼來源:ApacheConnectionManagerFactory.java

示例3: createConnectionManager

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
public PoolingHttpClientConnectionManager createConnectionManager(final Registry<ConnectionSocketFactory> registry) {
    if(log.isDebugEnabled()) {
        log.debug(String.format("Setup connection pool with registry %s", registry));
    }
    final PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(registry);
    manager.setMaxTotal(preferences.getInteger("http.connections.total"));
    manager.setDefaultMaxPerRoute(preferences.getInteger("http.connections.route"));
    manager.setValidateAfterInactivity(5000);
    return manager;
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:11,代碼來源:HttpConnectionPoolBuilder.java

示例4: getConnectionManager

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
public static PoolingHttpClientConnectionManager getConnectionManager(int maxConnections) {
    //configure connection manager
    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
    connectionManager.setDefaultMaxPerRoute(maxConnections);
    connectionManager.setMaxTotal(maxConnections);
    connectionManager.setValidateAfterInactivity(30000);
    return connectionManager;
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:9,代碼來源:MCRHttpUtils.java

示例5: init

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
@Create
public void init() {
	if (this.umaMetadataConfiguration != null) {

		if (applicationConfiguration.isRptConnectionPoolUseConnectionPooling()) {

			// For more information about PoolingHttpClientConnectionManager, please see:
			// http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/index.html?org/apache/http/impl/conn/PoolingHttpClientConnectionManager.html

			log.info("##### Initializing custom ClientExecutor...");
			PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
			connectionManager.setMaxTotal(applicationConfiguration.getRptConnectionPoolMaxTotal());
			connectionManager.setDefaultMaxPerRoute(applicationConfiguration.getRptConnectionPoolDefaultMaxPerRoute());
			connectionManager.setValidateAfterInactivity(applicationConfiguration.getRptConnectionPoolValidateAfterInactivity() * 1000);
			CloseableHttpClient client = HttpClients.custom()
				.setKeepAliveStrategy(connectionKeepAliveStrategy)
				.setConnectionManager(connectionManager)
				.build();
			ClientExecutor clientExecutor = new ApacheHttpClient4Executor(client);
			log.info("##### Initializing custom ClientExecutor DONE");

			this.resourceSetPermissionRegistrationService = UmaClientFactory.instance().createResourceSetPermissionRegistrationService(this.umaMetadataConfiguration, clientExecutor);
			this.rptStatusService = UmaClientFactory.instance().createRptStatusService(this.umaMetadataConfiguration, clientExecutor);

		} else {

			this.resourceSetPermissionRegistrationService = UmaClientFactory.instance().createResourceSetPermissionRegistrationService(this.umaMetadataConfiguration);
			this.rptStatusService = UmaClientFactory.instance().createRptStatusService(this.umaMetadataConfiguration);
		}
	}
}
 
開發者ID:AgarwalNeha1,項目名稱:gluu,代碼行數:32,代碼來源:UmaProtectionService.java

示例6: buildHttpClient

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
/**
 * Build a HTTP client based on the current properties.
 *
 * @return the built HTTP client
 */
private CloseableHttpClient buildHttpClient() {
    try {

        final ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
        final LayeredConnectionSocketFactory sslsf = this.sslSocketFactory;

        final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("http", plainsf)
                .register("https", sslsf)
                .build();

        final PoolingHttpClientConnectionManager connMgmr = new PoolingHttpClientConnectionManager(registry);
        connMgmr.setMaxTotal(this.maxPooledConnections);
        connMgmr.setDefaultMaxPerRoute(this.maxConnectionsPerRoute);
        connMgmr.setValidateAfterInactivity(DEFAULT_TIMEOUT);

        final HttpHost httpHost = new HttpHost(InetAddress.getLocalHost());
        final HttpRoute httpRoute = new HttpRoute(httpHost);
        connMgmr.setMaxPerRoute(httpRoute, MAX_CONNECTIONS_PER_ROUTE);

        final RequestConfig requestConfig = RequestConfig.custom()
                .setSocketTimeout(this.readTimeout)
                .setConnectTimeout(this.connectionTimeout)
                .setConnectionRequestTimeout(this.connectionTimeout)
                .setCircularRedirectsAllowed(this.circularRedirectsAllowed)
                .setRedirectsEnabled(this.redirectsEnabled)
                .setAuthenticationEnabled(this.authenticationEnabled)
                .build();


        final HttpClientBuilder builder = HttpClients.custom()
                .setConnectionManager(connMgmr)
                .setDefaultRequestConfig(requestConfig)
                .setSSLSocketFactory(sslsf)
                .setSSLHostnameVerifier(this.hostnameVerifier)
                .setRedirectStrategy(this.redirectionStrategy)
                .setDefaultCredentialsProvider(this.credentialsProvider)
                .setDefaultCookieStore(this.cookieStore)
                .setConnectionReuseStrategy(this.connectionReuseStrategy)
                .setConnectionBackoffStrategy(this.connectionBackoffStrategy)
                .setServiceUnavailableRetryStrategy(this.serviceUnavailableRetryStrategy)
                .setProxyAuthenticationStrategy(this.proxyAuthenticationStrategy)
                .setDefaultHeaders(this.defaultHeaders)
                .useSystemProperties();

        return builder.build();

    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:58,代碼來源:SimpleHttpClientFactoryBean.java

示例7: buildHttpClient

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
/**
 * Build a HTTP client based on the current properties.
 *
 * @return the built HTTP client
 */
private CloseableHttpClient buildHttpClient() {
    try {

        final ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
        final LayeredConnectionSocketFactory sslsf = this.sslSocketFactory;

        final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("http", plainsf)
                .register("https", sslsf)
                .build();

        final PoolingHttpClientConnectionManager connMgmr = new PoolingHttpClientConnectionManager(registry);
        connMgmr.setMaxTotal(this.maxPooledConnections);
        connMgmr.setDefaultMaxPerRoute(this.maxConnectionsPerRoute);
        connMgmr.setValidateAfterInactivity(DEFAULT_TIMEOUT);

        final HttpHost httpHost = new HttpHost(InetAddress.getLocalHost());
        final HttpRoute httpRoute = new HttpRoute(httpHost);
        connMgmr.setMaxPerRoute(httpRoute, MAX_CONNECTIONS_PER_ROUTE);

        final RequestConfig requestConfig = RequestConfig.custom()
                .setSocketTimeout(this.readTimeout)
                .setConnectTimeout(Long.valueOf(this.connectionTimeout).intValue())
                .setConnectionRequestTimeout(Long.valueOf(this.connectionTimeout).intValue())
                .setCircularRedirectsAllowed(this.circularRedirectsAllowed)
                .setRedirectsEnabled(this.redirectsEnabled)
                .setAuthenticationEnabled(this.authenticationEnabled)
                .build();


        final HttpClientBuilder builder = HttpClients.custom()
                .setConnectionManager(connMgmr)
                .setDefaultRequestConfig(requestConfig)
                .setSSLSocketFactory(sslsf)
                .setSSLHostnameVerifier(this.hostnameVerifier)
                .setRedirectStrategy(this.redirectionStrategy)
                .setDefaultCredentialsProvider(this.credentialsProvider)
                .setDefaultCookieStore(this.cookieStore)
                .setConnectionReuseStrategy(this.connectionReuseStrategy)
                .setConnectionBackoffStrategy(this.connectionBackoffStrategy)
                .setServiceUnavailableRetryStrategy(this.serviceUnavailableRetryStrategy)
                .setProxyAuthenticationStrategy(this.proxyAuthenticationStrategy)
                .setDefaultHeaders(this.defaultHeaders)
                .useSystemProperties();

        return builder.build();

    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw Throwables.propagate(e);
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:58,代碼來源:SimpleHttpClientFactoryBean.java

示例8: buildClient

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
@Override
protected ExecREST buildClient(RESTPool pool) throws IOException {
    SSLContext sslContext;
    try {
        sslContext = SSLContext.getDefault();
    } catch (NoSuchAlgorithmException e) {
        throw new IOException(e);
    }

    Registry<ConnectionSocketFactory> socketRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", PlainConnectionSocketFactory.INSTANCE)
            .register("https", new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE))
            .build();

    //TODO buffers size
    SocketConfig socketConfig = SocketConfig.custom()
            .setSoTimeout(new Long(pool.getSocketTimeout()).intValue())
            .setTcpNoDelay(true)
            .setSoKeepAlive(true)
            .setSoReuseAddress(true)
            .build();

    ConnectionConfig connectionConfig = ConnectionConfig.custom()
            .setCharset(StandardCharsets.UTF_8)
            .setMalformedInputAction(CodingErrorAction.IGNORE)
            .setUnmappableInputAction(CodingErrorAction.IGNORE)
            .build();

    HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory = new ManagedHttpClientConnectionFactory(
            new DefaultHttpRequestWriterFactory(),
            new DefaultHttpResponseParserFactory()
    );

    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectionRequestTimeout(new Long(pool.getMaxPoolWait()).intValue())
            .setConnectTimeout(new Long(pool.getConnectionTimeout()).intValue())
            .setExpectContinueEnabled(pool.expectContinue())
            .build();


    PoolingHttpClientConnectionManager ccm = new PoolingHttpClientConnectionManager(socketRegistry, connFactory);

    ccm.setMaxTotal(pool.getMaxTotal());
    ccm.setDefaultMaxPerRoute(pool.getMaxPerRoute());
    ccm.setDefaultSocketConfig(socketConfig);
    ccm.setDefaultConnectionConfig(connectionConfig);
    ccm.setValidateAfterInactivity(pool.getValidationOnInactivity());

    HttpClientBuilder builder = HttpClients.custom()
            .setConnectionManager(ccm)
            .setDefaultRequestConfig(requestConfig)
            .disableAutomaticRetries()
            .setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE)
            .disableCookieManagement()
            .disableContentCompression();

    addProxy(pool, builder);

    handleRedirects(pool, builder);

    CloseableHttpClient servClient = builder.build();

    IdleConnectionEvictor evictor = new IdleConnectionEvictor(ccm, pool.getEvictorSleep(), TimeUnit.MILLISECONDS, pool.getMaxIdleTime(), TimeUnit.MILLISECONDS);

    HTTPCClientMonitor monitor = pool.hasConnectionMetrics() ? new HTTPCSyncClientMonitor(pool.getName(), ccm) : null;

    return new HTTPCClient(servClient, evictor, monitor);
}
 
開發者ID:mercadolibre,項目名稱:java-restclient,代碼行數:69,代碼來源:HTTPCBuilder.java

示例9: getClientBuilder

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
@SneakyThrows
private HttpClientBuilder getClientBuilder() {

	RegistryBuilder<ConnectionSocketFactory> csf = RegistryBuilder.<ConnectionSocketFactory> create();

	KeyManager[] keyStoreManagers = null;
	if (cmd.get("keystore") != null) {
		KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());

		KeyStore keyStore = KeyStore.getInstance("jks");

		// System.out.printf("keystore=%s
		// keystorePassword=%s%n",map.get("keystore"),
		// map.get("keystorePassword"));
		keyStore.load(new FileInputStream(cmd.get("keystore")), null);
		kmf.init(keyStore, cmd.get("keystorePassword").toCharArray());
		keyStoreManagers = kmf.getKeyManagers();
	}

	TrustManager[] trustStoreManagers = null;
	if (cmd.get("truststore") != null) {
		TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());

		KeyStore trustStore = KeyStore.getInstance("jks");
		// System.out.printf("truststore=%s
		// truststorePassword=%s%n",map.get("truststore"),
		// map.get("truststorePassword"));

		trustStore.load(new FileInputStream(cmd.get("truststore")), null);
		tmf.init(trustStore);
		trustStoreManagers = tmf.getTrustManagers();
	}

	SSLContext sslContext = SSLContext.getInstance("TLS");
	sslContext.init(keyStoreManagers, trustStoreManagers, null);

	SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(sslContext, new HostnameVerifier() {
		public boolean verify(String arg0, SSLSession arg1) {
			return true;
		}
	});
	csf.register("https", scsf);
	csf.register("http", PlainConnectionSocketFactory.getSocketFactory());

	PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(csf.build());

	int maxPerRoute = 2 * Integer.valueOf(cmd.getOrDefault("pa", "" + Runtime.getRuntime().availableProcessors()));

	connManager.setDefaultMaxPerRoute(maxPerRoute);
	connManager.setValidateAfterInactivity(-1);

	// connManager.
	HttpClientBuilder builder = HttpClientBuilder.create();

	builder.setConnectionManager(connManager);
	return builder;
}
 
開發者ID:Auraya,項目名稱:armorvox-client,代碼行數:58,代碼來源:ClientHandlerV5.java


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