当前位置: 首页>>代码示例>>Java>>正文


Java BasicHttpClientConnectionManager类代码示例

本文整理汇总了Java中org.apache.http.impl.conn.BasicHttpClientConnectionManager的典型用法代码示例。如果您正苦于以下问题:Java BasicHttpClientConnectionManager类的具体用法?Java BasicHttpClientConnectionManager怎么用?Java BasicHttpClientConnectionManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BasicHttpClientConnectionManager类属于org.apache.http.impl.conn包,在下文中一共展示了BasicHttpClientConnectionManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: constructHttpClient

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
protected CloseableHttpClient constructHttpClient() throws IOException {
  RequestConfig config = RequestConfig.custom()
                                      .setConnectTimeout(20 * 1000)
                                      .setConnectionRequestTimeout(20 * 1000)
                                      .setSocketTimeout(20 * 1000)
                                      .setMaxRedirects(20)
                                      .build();

  URL                 mmsc          = new URL(apn.getMmsc());
  CredentialsProvider credsProvider = new BasicCredentialsProvider();

  if (apn.hasAuthentication()) {
    credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()),
                                 new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
  }

  return HttpClients.custom()
                    .setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4())
                    .setRedirectStrategy(new LaxRedirectStrategy())
                    .setUserAgent(TextSecurePreferences.getMmsUserAgent(context, USER_AGENT))
                    .setConnectionManager(new BasicHttpClientConnectionManager())
                    .setDefaultRequestConfig(config)
                    .setDefaultCredentialsProvider(credsProvider)
                    .build();
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:26,代码来源:LegacyMmsConnection.java

示例2: execute

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
@Override
public boolean execute(final EnvironmentContext ctx, final InfrastructureComponent component) {
    val defaultRequestConfig = RequestConfig.custom()
            .setConnectTimeout(2000)
            .setSocketTimeout(2000)
            .setConnectionRequestTimeout(2000)
            .build();

    val httpClient = HttpClients.custom()
            .setConnectionManager(new BasicHttpClientConnectionManager())
            .setDefaultRequestConfig(defaultRequestConfig)
            .build();

    await().atMost(atMost.toMillis(), TimeUnit.MILLISECONDS).until(() -> {
        try {
            val response = httpClient.execute(new HttpGet(url));
            val result = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
            return containsText != null && result.contains(containsText);
        } catch(final Exception ignored) {
            return false;
        }
    });

    return true;
}
 
开发者ID:fabzo,项目名称:kraken,代码行数:26,代码来源:HTTPWait.java

示例3: createHttpClient

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
protected CloseableHttpClient createHttpClient(Map<String, Object> parameters)
{
	HttpClientBuilder clientBuilder = HttpClients.custom();
	
	// single connection
	BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager();
	clientBuilder.setConnectionManager(connManager);
	
	// ignore cookies for now
	RequestConfig requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
	clientBuilder.setDefaultRequestConfig(requestConfig);
	
	setAuthentication(parameters, clientBuilder);
	
	CloseableHttpClient client = clientBuilder.build();
	return client;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:18,代码来源:HttpDataService.java

示例4: ProcessConnection

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
public ProcessConnection(ProcessDirector director, PhantomJSProcess process)
{
	this.process = process;
	
	HttpClientBuilder clientBuilder = HttpClients.custom();
	
	// single connection
	BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager();
	clientBuilder.setConnectionManager(connManager);
	
	RequestConfig requestConfig = RequestConfig.custom()
			// ignore cookies for now
			.setCookieSpec(CookieSpecs.IGNORE_COOKIES)
			.setSocketTimeout(director.getRequestTimeout()).build();
	clientBuilder.setDefaultRequestConfig(requestConfig);
	
	this.httpClient = clientBuilder.build();
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:19,代码来源:ProcessConnection.java

示例5: constructHttpClient

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
protected CloseableHttpClient constructHttpClient()
    throws IOException {
  RequestConfig config = RequestConfig.custom()
                                      .setConnectTimeout(20 * 1000)
                                      .setConnectionRequestTimeout(20 * 1000)
                                      .setSocketTimeout(20 * 1000)
                                      .setMaxRedirects(20)
                                      .build();

  URL mmsc = new URL(apn.getMmsc());
  CredentialsProvider credsProvider = new BasicCredentialsProvider();

  if (apn.hasAuthentication()) {
    credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()),
                                 new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
  }

  return HttpClients.custom()
                    .setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4())
                    .setRedirectStrategy(new LaxRedirectStrategy())
                    .setUserAgent("Android-Mms/2.0")
                    .setConnectionManager(new BasicHttpClientConnectionManager())
                    .setDefaultRequestConfig(config)
                    .setDefaultCredentialsProvider(credsProvider)
                    .build();
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:27,代码来源:MmsConnection.java

示例6: SimpleHttpClient

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
public SimpleHttpClient(final SSLContext sslContext, final int listenPort, final boolean useCompression) {
    HttpClientBuilder builder = HttpClientBuilder.create();
    if (!useCompression) {
        builder.disableContentCompression();
    }
    if (sslContext != null) {
        SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(
                sslContext,
                SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        builder.setSSLSocketFactory(sslConnectionFactory);

        Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("https", sslConnectionFactory)
                .build();
        builder.setConnectionManager(new BasicHttpClientConnectionManager(registry));
        scheme = "https";
    } else {
        scheme = "http";
    }
    this.delegate = builder.build();
    this.listenPort = listenPort;
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:23,代码来源:SimpleHttpClient.java

示例7: performLogoutOnServiceProviders

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
public void performLogoutOnServiceProviders(String idpSessionId) {
    List<String> serviceProviderLogoutUrls = idpConfig.getServiceProviderLogoutUrls();

    asyncServiceLogoutExecutor.submit(() -> {
        HttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager();
        HttpClient client = HttpClientBuilder.create()
                .setConnectionManager(connectionManager)
                .setRetryHandler(new DefaultHttpRequestRetryHandler(3, true))
                .build();

        try {
            for (String serviceProviderLogoutUrl : serviceProviderLogoutUrls) {
                callLoggedOutServiceUrl(client, serviceProviderLogoutUrl, idpSessionId);
            }
        } catch (Throwable ex) {
            log.error("Unable to perform logout on IDP services for session {}", idpSessionId, ex);
        } finally {
            connectionManager.shutdown();
        }
    });
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:22,代码来源:IdpServiceLogoutCallbackInvoker.java

示例8: createClient

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
public HttpCon createClient() throws Exception {
	ArrayList<Header> defheaders = new ArrayList<Header>();
	defheaders.add(new BasicHeader("X-Csrf-Token", "1"));

	BasicHttpClientConnectionManager bhcm = new BasicHttpClientConnectionManager(
			cfgMgr.getHttpClientSocketRegistry());

	RequestConfig rc = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).setRedirectsEnabled(false)
			.build();

	CloseableHttpClient http = HttpClients.custom()
			                  .setConnectionManager(bhcm)
			                  .setDefaultHeaders(defheaders)
			                  .setDefaultRequestConfig(rc)
			                  .build();

	HttpCon con = new HttpCon();
	con.setBcm(bhcm);
	con.setHttp(http);

	return con;

}
 
开发者ID:TremoloSecurity,项目名称:OpenUnison,代码行数:24,代码来源:OpenShiftTarget.java

示例9: createClient

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
public HttpCon createClient() throws Exception {
	ArrayList<Header> defheaders = new ArrayList<Header>();
	

	BasicHttpClientConnectionManager bhcm = new BasicHttpClientConnectionManager(
			cfgMgr.getHttpClientSocketRegistry());

	RequestConfig rc = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).setRedirectsEnabled(false)
			.build();

	CloseableHttpClient http = HttpClients.custom()
			                  .setConnectionManager(bhcm)
			                  .setDefaultHeaders(defheaders)
			                  .setDefaultRequestConfig(rc)
			                  .build();

	HttpCon con = new HttpCon();
	con.setBcm(bhcm);
	con.setHttp(http);

	return con;

}
 
开发者ID:TremoloSecurity,项目名称:OpenUnison,代码行数:24,代码来源:KeystoneProvisioningTarget.java

示例10: createClient

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
/**
 * This code sets up the httpclient to accept any SSL certificate. The 
 * SSL certificate generated by the instructions above is not correctly
 * signed, so we need ignore the problem. 
 * This code should not, under any circumstances, be allowed anywhere 
 * the production code. 
 * @return
 */
private CloseableHttpClient createClient () {
    try {
        HttpClientBuilder builder = HttpClientBuilder.create();
        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(null, new TrustManager[]{getTrustManager()}, null);
        SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(ctx, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        builder.setSSLSocketFactory(scsf);
        Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("https", scsf)
                .build();

        HttpClientConnectionManager ccm = new BasicHttpClientConnectionManager(registry);

        builder.setConnectionManager(ccm);
        return builder.build();
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:29,代码来源:HttpMonitorVerifySSLIT.java

示例11: createConnectionManager

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
protected HttpClientConnectionManager createConnectionManager() {
    if (httpClientConfig.isMultiThreaded()) {
        log.debug("Multi-threaded http connection manager created");
        final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
        final Integer maxTotal = httpClientConfig.getMaxTotalConnection();
        if (maxTotal != null) {
            cm.setMaxTotal(maxTotal);
        }
        final Integer defaultMaxPerRoute = httpClientConfig.getDefaultMaxTotalConnectionPerRoute();
        if (defaultMaxPerRoute != null) {
            cm.setDefaultMaxPerRoute(defaultMaxPerRoute);
        }
        final Map<HttpRoute, Integer> maxPerRoute = httpClientConfig.getMaxTotalConnectionPerRoute();
        for (final HttpRoute route : maxPerRoute.keySet()) {
            cm.setMaxPerRoute(route, maxPerRoute.get(route));
        }
        return cm;
    }
    log.debug("Default http connection is created without multi threaded option");
    return new BasicHttpClientConnectionManager();
}
 
开发者ID:petalmd,项目名称:armor,代码行数:22,代码来源:HeaderAwareJestClientFactory.java

示例12: constructHttpClient

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
protected CloseableHttpClient constructHttpClient() throws IOException {
  RequestConfig config = RequestConfig.custom()
                                      .setConnectTimeout(20 * 1000)
                                      .setConnectionRequestTimeout(20 * 1000)
                                      .setSocketTimeout(20 * 1000)
                                      .setMaxRedirects(20)
                                      .build();

  URL                 mmsc          = new URL(apn.getMmsc());
  CredentialsProvider credsProvider = new BasicCredentialsProvider();

  if (apn.hasAuthentication()) {
    credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()),
                                 new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
  }

  return HttpClients.custom()
                    .setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4())
                    .setRedirectStrategy(new LaxRedirectStrategy())
                    .setUserAgent(SilencePreferences.getMmsUserAgent(context, USER_AGENT))
                    .setConnectionManager(new BasicHttpClientConnectionManager())
                    .setDefaultRequestConfig(config)
                    .setDefaultCredentialsProvider(credsProvider)
                    .build();
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:26,代码来源:LegacyMmsConnection.java

示例13: httpClient

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
@Bean(destroyMethod = "close")
    public CloseableHttpClient httpClient() {
        // cache.itb.ac.id is not very reliable with pooling connection, better dedicated connection per recognition
//        final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
//        cm.setMaxTotal(200);
//        cm.setDefaultMaxPerRoute(20);
//        cm.setValidateAfterInactivity(100);
        final BasicHttpClientConnectionManager basicCm = new BasicHttpClientConnectionManager();
        return HttpClients.custom().useSystemProperties().setConnectionManager(basicCm)
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setConnectTimeout(10000)
                        .setSocketTimeout(10000)
                        .setConnectionRequestTimeout(10000)
                        .build())
                .build();
    }
 
开发者ID:lumenrobot,项目名称:speech-recognition,代码行数:17,代码来源:SpeechRecognitionApp.java

示例14: constructHttpClient

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
protected CloseableHttpClient constructHttpClient()
    throws IOException {
  RequestConfig config = RequestConfig.custom()
                                      .setConnectTimeout(20 * 1000)
                                      .setConnectionRequestTimeout(20 * 1000)
                                      .setSocketTimeout(20 * 1000)
                                      .setMaxRedirects(20)
                                      .build();

  return HttpClients.custom()
                    .setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4())
                    .setRedirectStrategy(new LaxRedirectStrategy())
                    .setUserAgent("Android-Mms/2.0")
                    .setConnectionManager(new BasicHttpClientConnectionManager())
                    .setDefaultRequestConfig(config)
                    .build();
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:18,代码来源:MmsConnection.java

示例15: FetchingThread

import org.apache.http.impl.conn.BasicHttpClientConnectionManager; //导入依赖的package包/类
/** Creates a new fetching thread.
 *
 * @param frontier a reference to the {@link Frontier}.
 * @param index  the index of this thread (only for logging purposes).
 */
public FetchingThread(final Frontier frontier, final int index) throws NoSuchAlgorithmException, IllegalArgumentException, IOException {
	setName(this.getClass().getSimpleName() + '-' + index);
	setPriority(Thread.MIN_PRIORITY); // Low priority; there will be thousands of this guys around.
	this.frontier = frontier;

	final BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManagerWithAlternateDNS(frontier.rc.dnsResolver);
	connManager.closeIdleConnections(0, TimeUnit.MILLISECONDS);
	connManager.setConnectionConfig(ConnectionConfig.custom().setBufferSize(8 * 1024).build()); // TODO: make this configurable

	cookieStore = new BasicCookieStore();

	BasicHeader[] headers = {
		new BasicHeader("From", frontier.rc.userAgentFrom),
		new BasicHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.95,text/*;q=0.9,*/*;q=0.8")
	};

	httpClient = HttpClients.custom()
			.setSSLContext(frontier.rc.acceptAllCertificates ? TRUST_ALL_CERTIFICATES_SSL_CONTEXT : TRUST_SELF_SIGNED_SSL_CONTEXT)
			.setConnectionManager(connManager)
			.setConnectionReuseStrategy(frontier.rc.keepAliveTime == 0 ? NoConnectionReuseStrategy.INSTANCE : DefaultConnectionReuseStrategy.INSTANCE)
			.setUserAgent(frontier.rc.userAgent)
			.setDefaultCookieStore(cookieStore)
			.setDefaultHeaders(ObjectArrayList.wrap(headers))
			.build();
  		fetchData = new FetchData(frontier.rc);
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:32,代码来源:FetchingThread.java


注:本文中的org.apache.http.impl.conn.BasicHttpClientConnectionManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。