org.apache.http.impl.conn.DefaultSchemePortResolver Java Examples

The following examples show how to use org.apache.http.impl.conn.DefaultSchemePortResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: aws-sdk-java-v2   Author: aws   File: ApacheHttpClient.java    License: Apache License 2.0 6 votes vote down vote up
public HttpClientConnectionManager create(ApacheHttpClient.DefaultBuilder configuration,
                                          AttributeMap standardOptions) {
    ConnectionSocketFactory sslsf = getPreferredSocketFactory(configuration, standardOptions);

    PoolingHttpClientConnectionManager cm = new
            PoolingHttpClientConnectionManager(
            createSocketFactoryRegistry(sslsf),
            null,
            DefaultSchemePortResolver.INSTANCE,
            null,
            standardOptions.get(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE).toMillis(),
            TimeUnit.MILLISECONDS);

    cm.setDefaultMaxPerRoute(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS));
    cm.setMaxTotal(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS));
    cm.setDefaultSocketConfig(buildSocketConfig(standardOptions));

    return cm;
}
 
Example #2
Source Project: ibm-cos-sdk-java   Author: IBM   File: ApacheConnectionManagerFactory.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #3
Source Project: cyberduck   Author: iterate-ch   File: UDTProxyConfigurator.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public HttpClientBuilder build(final Proxy proxy, final TranscriptListener listener, final LoginCallback prompt) {
    final HttpClientBuilder builder = super.build(proxy, 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(this.proxy.getHostname(), this.proxy.getPort(), this.proxy.getProtocol().getScheme().name()),
            new DefaultSchemePortResolver()));
    return builder;
}
 
Example #4
Source Project: spring-vault   Author: spring-projects   File: ClientHttpRequestFactoryFactory.java    License: Apache License 2.0 5 votes vote down vote up
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, getTrustManagers(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());
}
 
Example #5
Source Project: lavaplayer   Author: sedmelluq   File: ExtendedConnectionOperator.java    License: Apache License 2.0 5 votes vote down vote up
public ExtendedConnectionOperator(
    Lookup<ConnectionSocketFactory> socketFactoryRegistry,
    SchemePortResolver schemePortResolver,
    DnsResolver dnsResolver
) {
  this.socketFactoryRegistry = socketFactoryRegistry;
  this.schemePortResolver = schemePortResolver != null ? schemePortResolver : DefaultSchemePortResolver.INSTANCE;
  this.dnsResolver = dnsResolver != null ? dnsResolver : SystemDefaultDnsResolver.INSTANCE;
}
 
Example #6
Source Project: lavaplayer   Author: sedmelluq   File: AbstractRoutePlanner.java    License: Apache License 2.0 5 votes vote down vote up
protected AbstractRoutePlanner(final List<IpBlock> ipBlocks, final boolean handleSearchFailure) {
  this.ipBlock = new CombinedIpBlock(ipBlocks);
  this.failingAddresses = new HashMap<>();
  this.schemePortResolver = DefaultSchemePortResolver.INSTANCE;
  this.handleSearchFailure = handleSearchFailure;
  log.info("Active RoutePlanner: {} using total of {} ips", getClass().getCanonicalName(), this.ipBlock.getSize());
}
 
Example #7
Source Project: Bastion   Author: bastion-dev   File: TestWithProxiedEmbeddedServer.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #8
Source Project: Bastion   Author: bastion-dev   File: TestWithProxiedEmbeddedServer.java    License: GNU General Public License v3.0 5 votes vote down vote up
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);
            }
        }
    };
}
 
Example #9
Source Project: Bastion   Author: bastion-dev   File: TestWithProxiedEmbeddedServer.java    License: GNU General Public License v3.0 5 votes vote down vote up
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
    );
}
 
Example #10
Source Project: vespa   Author: vespa-engine   File: VespaHttpClientBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private HttpHost resolveTarget(HttpHost host) throws HttpException {
    try {
        String originalScheme = host.getSchemeName();
        String scheme = originalScheme.equalsIgnoreCase("http") ? "https" : originalScheme;
        int port = DefaultSchemePortResolver.INSTANCE.resolve(host);
        return new HttpHost(host.getHostName(), port, scheme);
    } catch (UnsupportedSchemeException e) {
        throw new HttpException(e.getMessage(), e);
    }
}
 
Example #11
Source Project: nexus-public   Author: sonatype   File: NexusHttpRoutePlanner.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @since 2.5
 */
public NexusHttpRoutePlanner(final Map<String, HttpHost> proxies,
                             @Nullable final Pattern nonProxyHostsPattern)
{
  super(DefaultSchemePortResolver.INSTANCE);
  this.proxies = checkNotNull(proxies);
  this.nonProxyHostPattern = nonProxyHostsPattern;
}
 
Example #12
Source Project: wildfly-core   Author: wildfly   File: SSLTruststoreUtil.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public static HttpClient getHttpClientWithSSL(File keyStoreFile, String keyStorePassword, String keyStoreProvider,
        File trustStoreFile, String trustStorePassword, String trustStoreProvider) {

    try {
        KeyStore trustStore = KeyStore.getInstance(trustStoreProvider);
        try (FileInputStream fis = new FileInputStream(trustStoreFile)) {
            trustStore.load(fis, trustStorePassword.toCharArray());
        }
        SSLContextBuilder sslContextBuilder = SSLContexts.custom()
                .setProtocol("TLS")
                .loadTrustMaterial(trustStore, null);
        if (keyStoreFile != null) {
            KeyStore keyStore = KeyStore.getInstance(keyStoreProvider);
            try (FileInputStream fis = new FileInputStream(keyStoreFile)) {
                keyStore.load(fis, keyStorePassword.toCharArray());
            }
            sslContextBuilder.loadKeyMaterial(keyStore, keyStorePassword.toCharArray(), null);
        }
        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();
    }
}
 
Example #13
Source Project: cloudbreak   Author: hortonworks   File: VaultConfig.java    License: Apache License 2.0 5 votes vote down vote up
private ClientHttpRequestFactory usingHttpComponents(ClientOptions options, SslConfiguration sslConfiguration)
        throws GeneralSecurityException, IOException {
    HttpClientBuilder httpClientBuilder = HttpClients.custom();

    httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(
            DefaultSchemePortResolver.INSTANCE, ProxySelector.getDefault()));

    if (isNoneEmpty(httpsProxyUser, httpsProxyPassword)) {
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(httpsProxyUser, httpsProxyPassword);
        CredentialsProvider provider = new BasicCredentialsProvider();
        provider.setCredentials(AuthScope.ANY, credentials);
        httpClientBuilder.setDefaultCredentialsProvider(provider);
    }

    if (hasSslConfiguration(sslConfiguration)) {
        SSLContext sslContext = getSSLContext(sslConfiguration,
                getTrustManagers(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);

    httpClientBuilder.setRedirectStrategy(new LaxRedirectStrategy());
    return new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build());
}
 
Example #14
Source Project: quarkus   Author: quarkusio   File: Substitute_RestClient.java    License: Apache License 2.0 4 votes vote down vote up
public NoSerializationBasicAuthCache(final SchemePortResolver schemePortResolver) {
    this.map = new ConcurrentHashMap<>();
    this.schemePortResolver = schemePortResolver != null ? schemePortResolver
            : DefaultSchemePortResolver.INSTANCE;
}
 
Example #15
Source Project: aws-sdk-java-v2   Author: aws   File: SdkProxyRoutePlanner.java    License: Apache License 2.0 4 votes vote down vote up
public SdkProxyRoutePlanner(String proxyHost, int proxyPort, String proxyProtocol, Set<String> nonProxyHosts) {
    super(DefaultSchemePortResolver.INSTANCE);
    proxy = new HttpHost(proxyHost, proxyPort, proxyProtocol);
    this.hostPatterns = nonProxyHosts;
}
 
Example #16
Source Project: ibm-cos-sdk-java   Author: IBM   File: SdkProxyRoutePlanner.java    License: Apache License 2.0 4 votes vote down vote up
public SdkProxyRoutePlanner(String proxyHost, int proxyPort, String nonProxyHosts) {
    super(DefaultSchemePortResolver.INSTANCE);
    proxy = new HttpHost(proxyHost, proxyPort);
    parseNonProxyHosts(nonProxyHosts);
}
 
Example #17
Source Project: bintray-client-java   Author: bintray   File: HttpClientConfigurator.java    License: Apache License 2.0 4 votes vote down vote up
public DefaultHostRoutePlanner(String defaultHost) {
    super(DefaultSchemePortResolver.INSTANCE);
    this.defaultHost = new HttpHost(defaultHost);
}
 
Example #18
Source Project: keycloak   Author: keycloak   File: ProxyMappingsAwareRoutePlanner.java    License: Apache License 2.0 4 votes vote down vote up
public ProxyMappingsAwareRoutePlanner(ProxyMappings proxyMappings) {
  super(DefaultSchemePortResolver.INSTANCE);
  this.proxyMappings = proxyMappings;
}