當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。