aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorS.Nishio <nishio@densan-labs.net>2015-01-20 09:34:16 +0900
committerS.Nishio <nishio@densan-labs.net>2015-01-20 09:34:16 +0900
commit2642492472675411049571ccc1140b9bb02dc46c (patch)
tree44ebf55dce48a136350df67c901d4e57fad878af
parentae02c2bea7fe4a072003738b0f90684c30d32076 (diff)
parent12604bc22402fdc41a0eef463af6c53463de26da (diff)
downloadbbprb-2642492472675411049571ccc1140b9bb02dc46c.tar.gz
Merge pull request #32 from mgrebenets/mgrebenets/support-proxy
Add support for proxy configuration
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BitbucketApiClient.java29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BitbucketApiClient.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BitbucketApiClient.java
index af43408..5906f4c 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BitbucketApiClient.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/BitbucketApiClient.java
@@ -14,6 +14,9 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
+import jenkins.model.Jenkins;
+import hudson.ProxyConfiguration;
+
/**
* Created by nishio
*/
@@ -76,8 +79,28 @@ public class BitbucketApiClient {
return null;
}
- private String getRequest(String path) {
+ private HttpClient getHttpClient() {
HttpClient client = new HttpClient();
+ if (Jenkins.getInstance() != null) {
+ ProxyConfiguration proxy = Jenkins.getInstance().proxy;
+ logger.info("Jenins proxy: " + proxy.name + ":" + proxy.port);
+ if (proxy != null) {
+ client.getHostConfiguration().setProxy(proxy.name, proxy.port);
+ String username = proxy.getUserName();
+ String password = proxy.getPassword();
+ // Consider it to be passed if username specified. Sufficient?
+ if (username != null && !"".equals(username.trim())) {
+ logger.info("Using proxy authentication (user=" + username + ")");
+ client.getState().setProxyCredentials(AuthScope.ANY,
+ new UsernamePasswordCredentials(username, password));
+ }
+ }
+ }
+ return client;
+ }
+
+ private String getRequest(String path) {
+ HttpClient client = getHttpClient();
client.getState().setCredentials(AuthScope.ANY, credentials);
GetMethod httpget = new GetMethod(path);
client.getParams().setAuthenticationPreemptive(true);
@@ -94,7 +117,7 @@ public class BitbucketApiClient {
}
public void deleteRequest(String path) {
- HttpClient client = new HttpClient();
+ HttpClient client = getHttpClient();
client.getState().setCredentials(AuthScope.ANY, credentials);
DeleteMethod httppost = new DeleteMethod(path);
client.getParams().setAuthenticationPreemptive(true);
@@ -107,7 +130,7 @@ public class BitbucketApiClient {
}
private String postRequest(String path, NameValuePair[] params) throws UnsupportedEncodingException {
- HttpClient client = new HttpClient();
+ HttpClient client = getHttpClient();
client.getState().setCredentials(AuthScope.ANY, credentials);
PostMethod httppost = new PostMethod(path);
httppost.setRequestBody(params);