}
}
}
final SSLContext sslContext = getSslContext(config);
final HttpClientBuilder clientBuilder = HttpClientBuilder.create();
clientBuilder.setConnectionManager(getConnectionManager(config, sslContext));
clientBuilder.setSslcontext(sslContext);
final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
int connectTimeout = 0;
int socketTimeout = 0;
boolean ignoreCookies = false;
if (config != null) {
connectTimeout = ClientProperties.getValue(config.getProperties(), ClientProperties.CONNECT_TIMEOUT, 0);
socketTimeout = ClientProperties.getValue(config.getProperties(), ClientProperties.READ_TIMEOUT, 0);
ignoreCookies = PropertiesHelper.isProperty(config.getProperties(), ApacheClientProperties.DISABLE_COOKIES);
final Object credentialsProvider = config.getProperty(ApacheClientProperties.CREDENTIALS_PROVIDER);
if (credentialsProvider != null && (credentialsProvider instanceof CredentialsProvider)) {
clientBuilder.setDefaultCredentialsProvider((CredentialsProvider) credentialsProvider);
}
final Object proxyUri;
proxyUri = config.getProperty(ClientProperties.PROXY_URI);
if (proxyUri != null) {
final URI u = getProxyUri(proxyUri);
final HttpHost proxy = new HttpHost(u.getHost(), u.getPort(), u.getScheme());
final String userName;
userName = ClientProperties.getValue(config.getProperties(), ClientProperties.PROXY_USERNAME, String.class);
if (userName != null) {
final String password;
password = ClientProperties.getValue(config.getProperties(), ClientProperties.PROXY_PASSWORD, String.class);
if (password != null) {
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(u.getHost(), u.getPort()),
new UsernamePasswordCredentials(userName, password)
);
clientBuilder.setDefaultCredentialsProvider(credsProvider);
}
}
clientBuilder.setProxy(proxy);
}
final Boolean preemptiveBasicAuthProperty = (Boolean) config.getProperties()
.get(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION);
this.preemptiveBasicAuth = (preemptiveBasicAuthProperty != null) ? preemptiveBasicAuthProperty : false;
} else {
this.preemptiveBasicAuth = false;
}
if (reqConfig != null) {
final RequestConfig.Builder reqConfigBuilder = RequestConfig.copy((RequestConfig) reqConfig);
if (connectTimeout > 0) {
reqConfigBuilder.setConnectTimeout(connectTimeout);
}
if (socketTimeout > 0) {
reqConfigBuilder.setSocketTimeout(socketTimeout);
}
if (ignoreCookies) {
reqConfigBuilder.setCookieSpec(CookieSpecs.IGNORE_COOKIES);
}
requestConfig = reqConfigBuilder.build();
} else {
requestConfigBuilder.setConnectTimeout(connectTimeout);
requestConfigBuilder.setSocketTimeout(socketTimeout);
if (ignoreCookies) {
requestConfigBuilder.setCookieSpec(CookieSpecs.IGNORE_COOKIES);
}
requestConfig = requestConfigBuilder.build();
}
if (requestConfig.getCookieSpec() == null || !requestConfig.getCookieSpec().equals(CookieSpecs.IGNORE_COOKIES)) {
this.cookieStore = new BasicCookieStore();
clientBuilder.setDefaultCookieStore(cookieStore);
} else {
this.cookieStore = null;
}
clientBuilder.setDefaultRequestConfig(requestConfig);
this.client = clientBuilder.build();
}