Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose addAuthentication and local context to subclasses #163

Merged
merged 3 commits into from
Jul 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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