List of usage examples for org.apache.http.impl.conn DefaultRoutePlanner DefaultRoutePlanner
public DefaultRoutePlanner(final SchemePortResolver schemePortResolver)
From source file:com.okta.sdk.framework.ApiClient.java
/** * Constructor for the ApiClient./*from w w w. j a v a 2 s . c o m*/ * * Bootstraps an HTTPClient to make various requests to the Okta API. * * @param config {@link ApiClientConfiguration} */ public ApiClient(ApiClientConfiguration config) { Proxy proxy = ProxySelector.getDefault().select(URI.create(config.getBaseUrl())).iterator().next(); HttpRoutePlanner routePlanner; if (Proxy.Type.HTTP.equals(proxy.type())) { URI proxyUri = URI.create(proxy.type() + "://" + proxy.address()); HttpHost proxyHost = new HttpHost(proxyUri.getHost(), proxyUri.getPort(), proxyUri.getScheme()); routePlanner = new DefaultProxyRoutePlanner(proxyHost); } else { routePlanner = new DefaultRoutePlanner(null); } StandardHttpRequestRetryHandler requestRetryHandler = new StandardHttpRequestRetryHandler(RETRY_COUNT, true); HttpClient client = HttpClientBuilder.create().setRetryHandler(requestRetryHandler) .setUserAgent("OktaSDKJava_v" + Utils.getSdkVersion()).disableCookieManagement() .setRoutePlanner(routePlanner).build(); this.httpClient = client; this.baseUrl = config.getBaseUrl(); this.apiVersion = config.getApiVersion(); this.configuration = config; this.token = config.getApiToken(); initMarshaller(); }
From source file:com.github.caldav4j.functional.support.CalDavFixture.java
private static HttpClient configureHttpClient(final CaldavCredential credential) { // HttpClient 4 requires a Cred providers, to be added during creation of client CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(credential.user, credential.password)); // Default Host setting HttpRoutePlanner routePlanner = new DefaultRoutePlanner(DefaultSchemePortResolver.INSTANCE) { @Override/*from w w w . j a v a2 s. c o m*/ public HttpRoute determineRoute(final HttpHost target, final HttpRequest request, final HttpContext context) throws HttpException { return super.determineRoute( target != null ? target : new HttpHost(credential.host, credential.port, credential.protocol), request, context); } }; HttpClientBuilder builder = HttpClients.custom().setDefaultCredentialsProvider(credsProvider) .setRoutePlanner(routePlanner); if (credential.getProxyHost() != null) { builder.setProxy(new HttpHost(credential.getProxyHost(), (credential.getProxyPort() > 0) ? credential.getProxyPort() : 8080)); } return builder.build(); }