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