From a6a6f97241608397988a2e3024b062c7190e9c7f Mon Sep 17 00:00:00 2001 From: Michael Hartle Date: Tue, 5 Apr 2016 13:06:49 +0200 Subject: [PATCH] Added JiraClient constructor to allow passing in a custom HttpClient, e.g. configured for proxying --- .../java/net/rcarz/jiraclient/JiraClient.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/rcarz/jiraclient/JiraClient.java b/src/main/java/net/rcarz/jiraclient/JiraClient.java index 18edb4f..62f90f5 100644 --- a/src/main/java/net/rcarz/jiraclient/JiraClient.java +++ b/src/main/java/net/rcarz/jiraclient/JiraClient.java @@ -50,7 +50,7 @@ public class JiraClient { * @throws JiraException */ public JiraClient(String uri) throws JiraException { - this(uri, null); + this(null, uri, null); } /** @@ -61,12 +61,26 @@ public class JiraClient { * @throws JiraException */ public JiraClient(String uri, ICredentials creds) throws JiraException { - PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(); - connManager.setDefaultMaxPerRoute(20); - connManager.setMaxTotal(40); - HttpClient httpclient = new DefaultHttpClient(connManager); + this(null, uri, creds); + } + + /** + * Creates an authenticated JIRA client with custom HttpClient. + * + * @param httpClient Custom HttpClient to be used + * @param uri Base URI of the JIRA server + * @param creds Credentials to authenticate with + * @throws JiraException + */ + public JiraClient(HttpClient httpClient, String uri, ICredentials creds) throws JiraException { + if (httpClient == null) { + PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(); + connManager.setDefaultMaxPerRoute(20); + connManager.setMaxTotal(40); + httpClient = new DefaultHttpClient(connManager); + } - restclient = new RestClient(httpclient, creds, URI.create(uri)); + restclient = new RestClient(httpClient, creds, URI.create(uri)); if (creds != null) { username = creds.getLogonName();