本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
});
}
示例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;
}
示例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;
}
示例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;
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}