diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java index 5a3703e5..322ecd0f 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java @@ -36,6 +36,7 @@ import org.apache.http.params.CoreConnectionPNames; import org.apache.http.params.HttpParams; import org.apache.http.protocol.BasicHttpContext; +import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,7 +62,7 @@ public class JenkinsHttpClient { private URI uri; private CloseableHttpClient client; - private BasicHttpContext localContext; + private HttpContext localContext; private HttpResponseValidator httpResponseValidator; // private HttpResponseContentExtractor contentExtractor; @@ -161,6 +162,7 @@ public JenkinsHttpClient(URI uri, String username, String password) { */ public T get(String path, Class cls) throws IOException { HttpGet getMethod = new HttpGet(api(path)); + HttpResponse response = client.execute(getMethod, localContext); getJenkinsVersionFromHeader(response); try { @@ -520,7 +522,7 @@ private void releaseConnection(HttpRequestBase httpRequestBase) { httpRequestBase.releaseConnection(); } - private static HttpClientBuilder addAuthentication(HttpClientBuilder builder, URI uri, String username, + protected static HttpClientBuilder addAuthentication(HttpClientBuilder builder, URI uri, String username, String password) { if (isNotBlank(username)) { CredentialsProvider provider = new BasicCredentialsProvider(); @@ -533,4 +535,12 @@ private static HttpClientBuilder addAuthentication(HttpClientBuilder builder, UR } return builder; } + + protected HttpContext getLocalContext() { + return localContext; + } + + protected void setLocalContext(HttpContext localContext) { + this.localContext = localContext; + } } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/PreemptiveAuth.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/PreemptiveAuth.java index d14b0dcd..ce772ca9 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/PreemptiveAuth.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/PreemptiveAuth.java @@ -21,7 +21,7 @@ import java.io.IOException; -class PreemptiveAuth implements HttpRequestInterceptor { +public class PreemptiveAuth implements HttpRequestInterceptor { @Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {