protected ClientHttpResponse doExecute(final HttpRequestBase httpMethod) throws IOException {
return requestFactory.execute(httpMethod, new Function<HttpClientBuilder, Void>() {
@Nullable
@Override
public Void apply(@Nonnull HttpClientBuilder input) {
final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
if (credentials != null) {
final URI uri = httpMethod.getURI();
HttpHost hh = new HttpHost(
uri.getHost(),
uri.getPort(),
uri.getScheme());
credentialsProvider.setCredentials(new AuthScope(hh), credentials);
// Preemptive authentication
if (isPreemptiveBasicAuth()) {
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(hh, basicAuth);
// Add AuthCache to the execution context
httpClientContext = HttpClientContext.create();
httpClientContext.setCredentialsProvider(credentialsProvider);
httpClientContext.setAuthCache(authCache);
} else {
input.setDefaultCredentialsProvider(credentialsProvider);
}
} else {
input.setDefaultCredentialsProvider(credentialsProvider);
}
if (useProxy) {
final HttpHost proxy = new HttpHost(proxyHost, proxyPort);
input.setProxy(proxy);
if (proxyCredentials != null) {
credentialsProvider.setCredentials(new AuthScope(proxy), proxyCredentials);
}
}
input.setRedirectStrategy(new LaxRedirectStrategy());
return null;
}