public HttpClientConnectionManager create(ApacheSdkHttpClientFactory configuration, AttributeMap standardOptions) { ConnectionSocketFactory sslsf = getPreferredSocketFactory(standardOptions); final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager( createSocketFactoryRegistry(sslsf), null, DefaultSchemePortResolver.INSTANCE, null, configuration.connectionTimeToLive().orElse(Defaults.CONNECTION_POOL_TTL).toMillis(), TimeUnit.MILLISECONDS); cm.setDefaultMaxPerRoute(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS)); cm.setMaxTotal(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS)); cm.setDefaultSocketConfig(buildSocketConfig(standardOptions)); return cm; }
@Override public HttpClientConnectionManager create(final HttpClientSettings settings) { ConnectionSocketFactory sslsf = getPreferredSocketFactory(settings); final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager( createSocketFactoryRegistry(sslsf), null, DefaultSchemePortResolver.INSTANCE, new DelegatingDnsResolver(settings.getDnsResolver()), settings.getConnectionPoolTTL(), TimeUnit.MILLISECONDS); cm.setValidateAfterInactivity(settings.getValidateAfterInactivityMillis()); cm.setDefaultMaxPerRoute(settings.getMaxConnections()); cm.setMaxTotal(settings.getMaxConnections()); cm.setDefaultSocketConfig(buildSocketConfig(settings)); cm.setDefaultConnectionConfig(buildConnectionConfig(settings)); return cm; }
@Override public HttpClientBuilder build(final TranscriptListener listener, final LoginCallback prompt) { final HttpClientBuilder builder = super.build(listener, prompt); // Add filter to inject custom headers to authenticate with proxy builder.setRequestExecutor( new CustomHeaderHttpRequestExecutor(headers) ); // Set proxy router planer builder.setRoutePlanner(new DefaultProxyRoutePlanner( new HttpHost(proxy.getHostname(), proxy.getPort(), proxy.getProtocol().getScheme().name()), new DefaultSchemePortResolver())); return builder; }
static ClientHttpRequestFactory usingHttpComponents(ClientOptions options, SslConfiguration sslConfiguration) throws GeneralSecurityException, IOException { HttpClientBuilder httpClientBuilder = HttpClients.custom(); httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner( DefaultSchemePortResolver.INSTANCE, ProxySelector.getDefault())); if (hasSslConfiguration(sslConfiguration)) { SSLContext sslContext = getSSLContext(sslConfiguration); SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory( sslContext); httpClientBuilder.setSSLSocketFactory(sslSocketFactory); httpClientBuilder.setSSLContext(sslContext); } RequestConfig requestConfig = RequestConfig .custom() // .setConnectTimeout( Math.toIntExact(options.getConnectionTimeout().toMillis())) // .setSocketTimeout( Math.toIntExact(options.getReadTimeout().toMillis())) // .setAuthenticationEnabled(true) // .build(); httpClientBuilder.setDefaultRequestConfig(requestConfig); // Support redirects httpClientBuilder.setRedirectStrategy(new LaxRedirectStrategy()); return new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build()); }
/** * Default constructor. * * @since 4.3 */ public BasicAuthCache(final SchemePortResolver schemePortResolver) { super(); this.map = new HashMap<HttpHost, AuthScheme>(); this.schemePortResolver = schemePortResolver != null ? schemePortResolver : DefaultSchemePortResolver.INSTANCE; }
@BeforeClass public static void setupProxying() { DnsResolver dnsResolver = prepareProxiedDnsResolver(); DefaultSchemePortResolver schemePortResolver = prepareSchemePortResolver(); BasicHttpClientConnectionManager connManager = prepareConnectionManager(dnsResolver, schemePortResolver); HttpClient httpClient = prepareHttpClient(connManager); originalHttpClient = (HttpClient) Options.getOption(Option.HTTPCLIENT); Unirest.setHttpClient(httpClient); }
private static DefaultSchemePortResolver prepareSchemePortResolver() { return new DefaultSchemePortResolver() { @Override public int resolve(HttpHost host) throws UnsupportedSchemeException { if (host.getHostName().equalsIgnoreCase("sushi-shop.test")) { return 9876; } else { return super.resolve(host); } } }; }
private static BasicHttpClientConnectionManager prepareConnectionManager(DnsResolver dnsResolver, DefaultSchemePortResolver schemePortResolver) { return new BasicHttpClientConnectionManager( RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", SSLConnectionSocketFactory.getSocketFactory()) .build(), null, schemePortResolver, dnsResolver ); }
/** * Default constructor. * * @since 4.3 */ public BasicAuthCache(final SchemePortResolver schemePortResolver) { super(); this.map = new ConcurrentHashMap<HttpHost, byte[]>(); this.schemePortResolver = schemePortResolver != null ? schemePortResolver : DefaultSchemePortResolver.INSTANCE; }
/** * @since 2.5 */ public NexusHttpRoutePlanner(final Map<String, HttpHost> proxies, @Nullable final Pattern nonProxyHostsPattern) { super(DefaultSchemePortResolver.INSTANCE); this.proxies = checkNotNull(proxies); this.nonProxyHostPattern = nonProxyHostsPattern; }
public static HttpClient getHttpClientWithSSL(File keyStoreFile, String keyStorePassword, File trustStoreFile, String trustStorePassword) { try { SSLContextBuilder sslContextBuilder = SSLContexts.custom() .useProtocol("TLS") .loadTrustMaterial(trustStoreFile, trustStorePassword.toCharArray()); if (keyStoreFile != null) { sslContextBuilder.loadKeyMaterial(keyStoreFile, keyStorePassword.toCharArray(), keyStorePassword.toCharArray()); } SSLContext sslContext = sslContextBuilder.build(); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", socketFactory) .build(); return HttpClientBuilder.create() .setSSLSocketFactory(socketFactory) //.setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) .setConnectionManager(new PoolingHttpClientConnectionManager(registry)) .setSchemePortResolver(new DefaultSchemePortResolver()) .build(); } catch (Exception e) { LOGGER.error("Creating HttpClient with customized SSL failed. We are returning the default one instead.", e); return HttpClients.createDefault(); } }
static ClientHttpRequestFactory usingHttpComponents(ClientOptions options, SslConfiguration sslConfiguration) throws GeneralSecurityException, IOException { HttpClientBuilder httpClientBuilder = HttpClients.custom(); httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner( DefaultSchemePortResolver.INSTANCE, ProxySelector.getDefault())); if (hasSslConfiguration(sslConfiguration)) { SSLContext sslContext = getSSLContext(sslConfiguration); SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory( sslContext); httpClientBuilder.setSSLSocketFactory(sslSocketFactory); httpClientBuilder.setSslcontext(sslContext); } RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(options.getConnectionTimeout()) .setSocketTimeout(options.getReadTimeout()) .setAuthenticationEnabled(true) .build(); httpClientBuilder.setDefaultRequestConfig(requestConfig); // Support redirects httpClientBuilder.setRedirectStrategy(new LaxRedirectStrategy()); // Fix weird problem `ProtocolException: Content-Length header already present` from `org.apache.http.protocol.RequestContent` httpClientBuilder.addInterceptorFirst(new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { if (request instanceof HttpEntityEnclosingRequest) { request.removeHeaders(HTTP.TRANSFER_ENCODING); request.removeHeaders(HTTP.CONTENT_LEN); } } }); return new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build()); }
public SdkProxyRoutePlanner(String proxyHost, int proxyPort, Set<String> nonProxyHosts) { super(DefaultSchemePortResolver.INSTANCE); proxy = new HttpHost(proxyHost, proxyPort); this.hostPatterns = nonProxyHosts; }
public SdkProxyRoutePlanner(String proxyHost, int proxyPort, String nonProxyHosts) { super(DefaultSchemePortResolver.INSTANCE); proxy = new HttpHost(proxyHost, proxyPort); parseNonProxyHosts(nonProxyHosts); }
public DefaultHostRoutePlanner(String defaultHost) { super(DefaultSchemePortResolver.INSTANCE); this.defaultHost = new HttpHost(defaultHost); }
public ApacheHttpClientEdgeGridRoutePlanner(ClientCredential clientCredential) { super(DefaultSchemePortResolver.INSTANCE); this.binding = new ApacheHttpClientEdgeGridRequestSigner(clientCredential); }
public ApacheHttpClientEdgeGridRoutePlanner(ClientCredentialProvider clientCredentialProvider) { super(DefaultSchemePortResolver.INSTANCE); this.binding = new ApacheHttpClientEdgeGridRequestSigner(clientCredentialProvider); }