Skip to content

Commit

Permalink
Merge pull request #163 from mcqueenorama/master
Browse files Browse the repository at this point in the history
expose addAuthentication and local context to subclasses
  • Loading branch information
khmarbaise authored Jul 18, 2016
2 parents 50c2f7a + 7b8ca1f commit ea311c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -161,6 +162,7 @@ public JenkinsHttpClient(URI uri, String username, String password) {
*/
public <T extends BaseModel> T get(String path, Class<T> cls) throws IOException {
HttpGet getMethod = new HttpGet(api(path));

HttpResponse response = client.execute(getMethod, localContext);
getJenkinsVersionFromHeader(response);
try {
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ea311c6

Please sign in to comment.