本文整理汇总了Java中org.apache.http.config.ConnectionConfig类的典型用法代码示例。如果您正苦于以下问题:Java ConnectionConfig类的具体用法?Java ConnectionConfig怎么用?Java ConnectionConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionConfig类属于org.apache.http.config包,在下文中一共展示了ConnectionConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHttpAsyncClient
import org.apache.http.config.ConnectionConfig; //导入依赖的package包/类
private CloseableHttpAsyncClient createHttpAsyncClient(YunpianConf conf) throws IOReactorException {
IOReactorConfig ioReactorConfig = IOReactorConfig.custom().setIoThreadCount(Runtime.getRuntime().availableProcessors())
.setConnectTimeout(conf.getConfInt(YunpianConf.HTTP_CONN_TIMEOUT, "10000"))
.setSoTimeout(conf.getConfInt(YunpianConf.HTTP_SO_TIMEOUT, "30000")).build();
ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);
PoolingNHttpClientConnectionManager connManager = new PoolingNHttpClientConnectionManager(ioReactor);
ConnectionConfig connectionConfig = ConnectionConfig.custom().setMalformedInputAction(CodingErrorAction.IGNORE)
.setUnmappableInputAction(CodingErrorAction.IGNORE)
.setCharset(Charset.forName(conf.getConf(YunpianConf.HTTP_CHARSET, YunpianConf.HTTP_CHARSET_DEFAULT))).build();
connManager.setDefaultConnectionConfig(connectionConfig);
connManager.setMaxTotal(conf.getConfInt(YunpianConf.HTTP_CONN_MAXTOTAL, "100"));
connManager.setDefaultMaxPerRoute(conf.getConfInt(YunpianConf.HTTP_CONN_MAXPERROUTE, "10"));
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setConnectionManager(connManager).build();
httpclient.start();
return httpclient;
}
示例2: getHttpClient
import org.apache.http.config.ConnectionConfig; //导入依赖的package包/类
public static CloseableHttpClient getHttpClient() {
if(httpClient==null){
synchronized (HttpPoolManager.class) {
if(httpClient==null){
System.out.println(COUNT++);
ConnectionConfig config = ConnectionConfig.custom()
.setBufferSize(4128)
.build();
httpClient = HttpClients.custom()
.setConnectionManager(cm)
.setDefaultConnectionConfig(config)
.build();
}
}
}
return httpClient;
}
示例3: getHttpClient
import org.apache.http.config.ConnectionConfig; //导入依赖的package包/类
public static CloseableHttpClient getHttpClient(HttpClientConnectionManager connectionManager, int maxConnections) {
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30000).setSocketTimeout(30000).build();
ConnectionConfig connectionConfig = ConnectionConfig.custom().setCharset(Charset.forName("UTF-8")).build();
SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true)
.setSoReuseAddress(true).build();
String userAgent = MessageFormat
.format("MyCoRe/{0} ({1}; java {2})", MCRCoreVersion.getCompleteVersion(), MCRConfiguration.instance()
.getString("MCR.NameOfProject", "undefined"), System.getProperty("java.version"));
//setup http client
return HttpClients.custom().setConnectionManager(connectionManager)
.setUserAgent(userAgent).setRetryHandler(new MCRRetryHandler(maxConnections))
.setDefaultRequestConfig(requestConfig).setDefaultConnectionConfig(connectionConfig)
.setDefaultSocketConfig(socketConfig).build();
}
示例4: ProxyClient
import org.apache.http.config.ConnectionConfig; //导入依赖的package包/类
/**
* @since 4.3
*/
public ProxyClient(
final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
final ConnectionConfig connectionConfig,
final RequestConfig requestConfig) {
super();
this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
this.connectionConfig = connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT;
this.requestConfig = requestConfig != null ? requestConfig : RequestConfig.DEFAULT;
this.httpProcessor = new ImmutableHttpProcessor(
new RequestTargetHostHC4(), new RequestClientConnControl(), new RequestUserAgentHC4());
this.requestExec = new HttpRequestExecutor();
this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
this.authenticator = new HttpAuthenticator();
this.proxyAuthState = new AuthStateHC4();
this.authSchemeRegistry = new AuthSchemeRegistry();
this.authSchemeRegistry.register(AuthSchemes.BASIC, new BasicSchemeFactoryHC4());
this.authSchemeRegistry.register(AuthSchemes.DIGEST, new DigestSchemeFactoryHC4());
this.authSchemeRegistry.register(AuthSchemes.NTLM, new NTLMSchemeFactory());
this.reuseStrategy = new DefaultConnectionReuseStrategyHC4();
}
示例5: create
import org.apache.http.config.ConnectionConfig; //导入依赖的package包/类
public ManagedHttpClientConnection create(final HttpRoute route) throws IOException {
ConnectionConfig config = null;
if (route.getProxyHost() != null) {
config = this.configData.getConnectionConfig(route.getProxyHost());
}
if (config == null) {
config = this.configData.getConnectionConfig(route.getTargetHost());
}
if (config == null) {
config = this.configData.getDefaultConnectionConfig();
}
if (config == null) {
config = ConnectionConfig.DEFAULT;
}
return this.connFactory.create(route, config);
}
示例6: ProxyClient
import org.apache.http.config.ConnectionConfig; //导入依赖的package包/类
/**
* @since 4.3
*/
public ProxyClient(
final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
final ConnectionConfig connectionConfig,
final RequestConfig requestConfig) {
super();
this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
this.connectionConfig = connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT;
this.requestConfig = requestConfig != null ? requestConfig : RequestConfig.DEFAULT;
this.httpProcessor = new ImmutableHttpProcessor(
new RequestTargetHost(), new RequestClientConnControl(), new RequestUserAgent());
this.requestExec = new HttpRequestExecutor();
this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
this.authenticator = new HttpAuthenticator();
this.proxyAuthState = new AuthState();
this.authSchemeRegistry = new AuthSchemeRegistry();
this.authSchemeRegistry.register(AuthSchemes.BASIC, new BasicSchemeFactory());
this.authSchemeRegistry.register(AuthSchemes.DIGEST, new DigestSchemeFactory());
this.authSchemeRegistry.register(AuthSchemes.NTLM, new NTLMSchemeFactory());
this.authSchemeRegistry.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory());
this.authSchemeRegistry.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory());
this.reuseStrategy = new DefaultConnectionReuseStrategy();
}
示例7: create
import org.apache.http.config.ConnectionConfig; //导入依赖的package包/类
@Override
public ManagedHttpClientConnection create(final HttpRoute route) throws IOException {
ConnectionConfig config = null;
if (route.getProxyHost() != null) {
config = this.configData.getConnectionConfig(route.getProxyHost());
}
if (config == null) {
config = this.configData.getConnectionConfig(route.getTargetHost());
}
if (config == null) {
config = this.configData.getDefaultConnectionConfig();
}
if (config == null) {
config = ConnectionConfig.DEFAULT;
}
return this.connFactory.create(route, config);
}
示例8: testLeaseReleaseNonReusable
import org.apache.http.config.ConnectionConfig; //导入依赖的package包/类
@Test
public void testLeaseReleaseNonReusable() throws Exception {
final HttpHost target = new HttpHost("localhost", 80);
final HttpRoute route = new HttpRoute(target);
Mockito.when(connFactory.create(
Mockito.eq(route), Mockito.<ConnectionConfig>any())).thenReturn(conn);
final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
final HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
Assert.assertNotNull(conn1);
Assert.assertFalse(conn1.isOpen());
mgr.releaseConnection(conn1, null, 100, TimeUnit.MILLISECONDS);
Assert.assertNull(mgr.getRoute());
Assert.assertNull(mgr.getState());
final ConnectionRequest connRequest2 = mgr.requestConnection(route, null);
final HttpClientConnection conn2 = connRequest2.get(0, TimeUnit.MILLISECONDS);
Assert.assertNotNull(conn2);
Assert.assertFalse(conn2.isOpen());
Mockito.verify(connFactory, Mockito.times(2)).create(
Mockito.eq(route), Mockito.<ConnectionConfig>any());
}
示例9: testAlreadyLeased
import org.apache.http.config.ConnectionConfig; //导入依赖的package包/类
@Test(expected=IllegalStateException.class)
public void testAlreadyLeased() throws Exception {
final HttpHost target = new HttpHost("somehost", 80);
final HttpRoute route = new HttpRoute(target);
Mockito.when(connFactory.create(
Mockito.eq(route), Mockito.<ConnectionConfig>any())).thenReturn(conn);
final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
final HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
Assert.assertNotNull(conn1);
mgr.releaseConnection(conn1, null, 100, TimeUnit.MILLISECONDS);
mgr.getConnection(route, null);
mgr.getConnection(route, null);
}
示例10: newClient
import org.apache.http.config.ConnectionConfig; //导入依赖的package包/类
public static CloseableHttpClient newClient(int timeout) {
HttpClientBuilder builder = HttpClients.custom();
builder.useSystemProperties();
builder.addInterceptorFirst(REMOVE_INCORRECT_CONTENT_ENCODING);
builder.disableAutomaticRetries();
builder.setSSLContext(SSL_CONTEXT);
builder.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
RequestConfig.Builder configBuilder = RequestConfig.custom();
configBuilder.setCookieSpec(CookieSpecs.IGNORE_COOKIES);
configBuilder.setSocketTimeout(timeout);
configBuilder.setConnectTimeout(timeout);
configBuilder.setConnectionRequestTimeout(timeout);
builder.setDefaultRequestConfig(configBuilder.build());
builder.setDefaultConnectionConfig(ConnectionConfig.custom().setCharset(Consts.ISO_8859_1).build());
return builder.build();
}
示例11: buildClient
import org.apache.http.config.ConnectionConfig; //导入依赖的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);
}
示例12: buildConnectionConfig
import org.apache.http.config.ConnectionConfig; //导入依赖的package包/类
private ConnectionConfig buildConnectionConfig(HttpClientSettings settings) {
int socketBufferSize = Math.max(settings.getSocketBufferSize()[0],
settings.getSocketBufferSize()[1]);
return socketBufferSize <= 0
? null
: ConnectionConfig.custom()
.setBufferSize(socketBufferSize)
.build();
}
示例13: FetchingThread
import org.apache.http.config.ConnectionConfig; //导入依赖的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);
}
示例14: SimpleHttpClient
import org.apache.http.config.ConnectionConfig; //导入依赖的package包/类
public SimpleHttpClient()
{
ConnectionConfig config = ConnectionConfig.DEFAULT;
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(3000)
.setConnectionRequestTimeout(3000)
.build();
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setDefaultConnectionConfig(config);
builder.setDefaultRequestConfig(requestConfig);
client = builder.build();
httpClientContext = HttpClientContext.create();
}
示例15: getConnectionConfig
import org.apache.http.config.ConnectionConfig; //导入依赖的package包/类
public static ConnectionConfig getConnectionConfig(final HttpParams params) {
final MessageConstraints messageConstraints = getMessageConstraints(params);
final String csname = (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET);
return ConnectionConfig.custom()
.setCharset(csname != null ? Charset.forName(csname) : null)
.setMessageConstraints(messageConstraints)
.build();
}