/** * @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(); }
/** * @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(); }
@Before public void setUp() throws Exception { reactor = new NioReactor(); crusher = TcpCrusherBuilder.builder() .withReactor(reactor) .withBindAddress("127.0.0.1", CRUSHER_PORT) .withConnectAddress(REMOTE_HOST, REMOTE_PORT) .buildAndOpen(); DnsResolver dnsResolver = new SystemDefaultDnsResolver() { @Override public InetAddress[] resolve(final String host) throws UnknownHostException { if (host.equalsIgnoreCase(REMOTE_HOST)) { return new InetAddress[] { InetAddress.getByAddress(new byte[] {127, 0, 0, 1}) }; } else { return super.resolve(host); } } }; HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> httpConnectionFactory = new ManagedHttpClientConnectionFactory(); Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.INSTANCE) .build(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager( socketFactoryRegistry, httpConnectionFactory, dnsResolver); http = HttpClients.createMinimal(connectionManager); }
public BasicHttpClientConnectionManager( final Lookup<ConnectionSocketFactory> socketFactoryRegistry, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver) { super(); this.connectionOperator = new HttpClientConnectionOperator( socketFactoryRegistry, schemePortResolver, dnsResolver); this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE; this.expiry = Long.MAX_VALUE; this.socketConfig = SocketConfig.DEFAULT; this.connConfig = ConnectionConfig.DEFAULT; this.isShutdown = new AtomicBoolean(false); }
public PoolingHttpClientConnectionManager( final Registry<ConnectionSocketFactory> socketFactoryRegistry, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver, final long timeToLive, final TimeUnit tunit) { super(); this.configData = new ConfigData(); this.pool = new CPool( new InternalConnectionFactory(this.configData, connFactory), 2, 20, timeToLive, tunit); this.connectionOperator = new HttpClientConnectionOperator( socketFactoryRegistry, schemePortResolver, dnsResolver); this.isShutDown = new AtomicBoolean(false); }
InternalConnectionFactory( final ConfigData configData, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory) { super(); this.configData = configData != null ? configData : new ConfigData(); this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE; }
public BasicHttpClientConnectionManager( final Lookup<ConnectionSocketFactory> socketFactoryRegistry, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver) { this( new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schemePortResolver, dnsResolver), connFactory ); }
/** * @since 4.4 */ public BasicHttpClientConnectionManager( final HttpClientConnectionOperator httpClientConnectionOperator, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory) { super(); this.connectionOperator = Args.notNull(httpClientConnectionOperator, "Connection operator"); this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE; this.expiry = Long.MAX_VALUE; this.socketConfig = SocketConfig.DEFAULT; this.connConfig = ConnectionConfig.DEFAULT; this.isShutdown = new AtomicBoolean(false); }
public PoolingHttpClientConnectionManager( final Registry<ConnectionSocketFactory> socketFactoryRegistry, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver, final long timeToLive, final TimeUnit tunit) { this( new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schemePortResolver, dnsResolver), connFactory, timeToLive, tunit ); }
/** * @since 4.4 */ public PoolingHttpClientConnectionManager( final HttpClientConnectionOperator httpClientConnectionOperator, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final long timeToLive, final TimeUnit tunit) { super(); this.configData = new ConfigData(); this.pool = new CPool(new InternalConnectionFactory( this.configData, connFactory), 2, 20, timeToLive, tunit); this.pool.setValidateAfterInactivity(2000); this.connectionOperator = Args.notNull(httpClientConnectionOperator, "HttpClientConnectionOperator"); this.isShutDown = new AtomicBoolean(false); }
@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); }
public BasicHttpClientConnectionManager( final Lookup<ConnectionSocketFactory> socketFactoryRegistry, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory) { this(socketFactoryRegistry, connFactory, null, null); }
public PoolingHttpClientConnectionManager( final Registry<ConnectionSocketFactory> socketFactoryRegistry, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory) { this(socketFactoryRegistry, connFactory, null); }
public PoolingHttpClientConnectionManager( final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory) { this(getDefaultRegistry(), connFactory, null); }
public PoolingHttpClientConnectionManager( final Registry<ConnectionSocketFactory> socketFactoryRegistry, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final DnsResolver dnsResolver) { this(socketFactoryRegistry, connFactory, null, dnsResolver, -1, TimeUnit.MILLISECONDS); }