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

The following examples show how to use org.apache.http.impl.conn.SystemDefaultRoutePlanner. 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 File: HttpClientFactory.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private HttpRoutePlanner createRoutePlanner() {
    // If http.nonProxyHosts is not set, then "localhost" is used as a default value, which prevents setting a proxy on localhost.
    if (System.getProperty("http.nonProxyHosts") == null) {
        System.setProperty("http.nonProxyHosts", "");
    }
    return new SystemDefaultRoutePlanner(ProxySelector.getDefault());
}
 
Example #2
Source File: ClientHttpRequestFactoryFactory.java    From spring-vault with 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 #3
Source File: HttpClientSupport.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
public static HttpClientBuilder builder(
		HttpEnvironmentRepositoryProperties environmentProperties)
		throws GeneralSecurityException {
	SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
	HttpClientBuilder httpClientBuilder = HttpClients.custom();

	if (environmentProperties.isSkipSslValidation()) {
		sslContextBuilder.loadTrustMaterial(null, (certificate, authType) -> true);
		httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier());
	}

	if (!CollectionUtils.isEmpty(environmentProperties.getProxy())) {
		ProxyHostProperties httpsProxy = environmentProperties.getProxy()
				.get(ProxyHostProperties.ProxyForScheme.HTTPS);
		ProxyHostProperties httpProxy = environmentProperties.getProxy()
				.get(ProxyHostProperties.ProxyForScheme.HTTP);

		httpClientBuilder
				.setRoutePlanner(new SchemeBasedRoutePlanner(httpsProxy, httpProxy));
		httpClientBuilder.setDefaultCredentialsProvider(
				new ProxyHostCredentialsProvider(httpProxy, httpsProxy));
	}
	else {
		httpClientBuilder.setRoutePlanner(
				new SystemDefaultRoutePlanner(ProxySelector.getDefault()));
		httpClientBuilder.setDefaultCredentialsProvider(
				new SystemDefaultCredentialsProvider());
	}

	int timeout = environmentProperties.getTimeout() * 1000;
	return httpClientBuilder.setSSLContext(sslContextBuilder.build())
			.setDefaultRequestConfig(RequestConfig.custom().setSocketTimeout(timeout)
					.setConnectTimeout(timeout).build());
}
 
Example #4
Source File: GoogleApacheHttpTransport.java    From google-api-java-client with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new instance of {@link ApacheHttpTransport} that uses
 * {@link GoogleUtils#getCertificateTrustStore()} for the trusted certificates.
 */
public static ApacheHttpTransport newTrustedTransport() throws GeneralSecurityException,
    IOException {
  // Set socket buffer sizes to 8192
  SocketConfig socketConfig =
      SocketConfig.custom()
          .setRcvBufSize(8192)
          .setSndBufSize(8192)
          .build();

  PoolingHttpClientConnectionManager connectionManager =
      new PoolingHttpClientConnectionManager(-1, TimeUnit.MILLISECONDS);

  // Disable the stale connection check (previously configured in the HttpConnectionParams
  connectionManager.setValidateAfterInactivity(-1);

  // Use the included trust store
  KeyStore trustStore = GoogleUtils.getCertificateTrustStore();
  SSLContext sslContext = SslUtils.getTlsSslContext();
  SslUtils.initSslContext(sslContext, trustStore, SslUtils.getPkixTrustManagerFactory());
  LayeredConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext);

  HttpClient client = HttpClientBuilder.create()
      .useSystemProperties()
      .setSSLSocketFactory(socketFactory)
      .setDefaultSocketConfig(socketConfig)
      .setMaxConnTotal(200)
      .setMaxConnPerRoute(20)
      .setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault()))
      .setConnectionManager(connectionManager)
      .disableRedirectHandling()
      .disableAutomaticRetries()
      .build();
  return new ApacheHttpTransport(client);
}
 
Example #5
Source File: VaultConfig.java    From cloudbreak with 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 #6
Source File: Http4FileProvider.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
private HttpRoutePlanner createHttpRoutePlanner(final Http4FileSystemConfigBuilder builder,
        final FileSystemOptions fileSystemOptions) {
    final HttpHost proxyHost = getProxyHttpHost(builder, fileSystemOptions);

    if (proxyHost != null) {
        return new DefaultProxyRoutePlanner(proxyHost);
    }

    return new SystemDefaultRoutePlanner(ProxySelector.getDefault());
}
 
Example #7
Source File: SettingsTmc.java    From tmc-intellij with MIT License 4 votes vote down vote up
@Override
public SystemDefaultRoutePlanner proxy() {
    // implement?
    return null;
}
 
Example #8
Source File: Settings.java    From tmc-cli with MIT License 4 votes vote down vote up
@Override
public SystemDefaultRoutePlanner proxy() {
    return null;
}
 
Example #9
Source File: HttpClientHandler.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private static HttpRoutePlanner createProxyRoutePlanner() {
    // use the standard JRE ProxySelector to get proxy information
    Message.verbose("Using JRE standard ProxySelector for configuring HTTP proxy");
    return new SystemDefaultRoutePlanner(ProxySelector.getDefault());
}
 
Example #10
Source File: ApacheHttpTransport.java    From google-http-java-client with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new Apache HTTP client builder that is used by the {@link #ApacheHttpTransport()}
 * constructor.
 *
 * <p>Settings:
 *
 * <ul>
 *   <li>The client connection manager is set to {@link PoolingHttpClientConnectionManager}.
 *   <li><The retry mechanism is turned off using {@link
 *       HttpClientBuilder#disableRedirectHandling}.
 *   <li>The route planner uses {@link SystemDefaultRoutePlanner} with {@link
 *       ProxySelector#getDefault()}, which uses the proxy settings from <a
 *       href="http://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html">system
 *       properties</a>.
 * </ul>
 *
 * @return new instance of the Apache HTTP client
 * @since 1.31
 */
public static HttpClientBuilder newDefaultHttpClientBuilder() {

  return HttpClientBuilder.create()
      .useSystemProperties()
      .setSSLSocketFactory(SSLConnectionSocketFactory.getSocketFactory())
      .setMaxConnTotal(200)
      .setMaxConnPerRoute(20)
      .setConnectionTimeToLive(-1, TimeUnit.MILLISECONDS)
      .setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault()))
      .disableRedirectHandling()
      .disableAutomaticRetries();
}