Hi, I have problem to connection to JIRA via Java REST-API, if there is a proxy in the way. I have tryed severel solutions but I allways get "connection timeout". I can establish a connection to my JIRA via normal Http-Request and using the proxy.
Here some code that dont work.
Solution 1 - Proxy Class
URL url = new URL("https://jira.example.com/jira/"); Proxy myProxy = null; final ProxySettings proxySettings = new ProxySettings("proxy.example.com", 8080, "ProxyUsername", "ProxyPw"); if (proxySettings != null) { myProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxySettings.getHost(), proxySettings.getPort())); if (proxySettings.getUser() != null) { Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(proxySettings.getUser(), proxySettings.getPassword().toCharArray()); } }); } } URLConnection connection = null; if (myProxy != null) { connection = url.openConnection(myProxy); if (proxySettings != null && proxySettings.getUser() != null) { String proxyAuth = proxySettings.getUser() + ":" + proxySettings.getPassword(); connection.setRequestProperty("Proxy-Authorization", "Basic " + Base64.encodeBase64String((proxyAuth).getBytes())); } } final JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory(); final NullProgressMonitor pm = new NullProgressMonitor(); final URI jiraServerUri2 = connection.getURL().toURI(); final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri2, "jiraName", "JiraPW"); Issue issue = restClient.getIssueClient().getIssue("Test-4", pm); // here comes the timeout
Errormsg: "org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect"
Solution 2 - System Properties
System.getProperties().put("https.proxyHost", "proxy.example.com"); System.getProperties().put("https.proxyPort", "8080"); System.getProperties().put("https.proxyUser", "ProxyUsername"); System.getProperties().put("https.proxyPassword", "ProxyPw"); System.getProperties().put("https.proxySet", "true"); final JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory(); final NullProgressMonitor pm = new NullProgressMonitor(); final URI jiraServerUri2 = new URI("https://jira.example.com/jira/"); final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri2, "jiraName", "JiraPW"); Issue issue = restClient.getIssueClient().getIssue("Test-4", pm); // here comes the timeout
same Errormsg: "org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect"
Solution 2 - VM Arguments
-Dhttps.proxyHost=proxy.example.com
-Dhttps.proxyPort=8080
-Dhttps.proxyUser=ProxyUsername
-Dhttps.proxyPassword=ProxyPw
rest ist the same like Solution 2
A helpful answer would be very nice. I'm working on this now for over a week and a bit more i'm goning crazy XD
Thanks a lot.
PS: Sorry for my bad english. If there any unterstanding problems, say it please.
Community moderators have prevented the ability to post new answers.
Hello,
I believe your code is right (I can be wrong, though). However, this error is very clear:
org.apache.commons.httpclient.HttpMethodDirector executeWithRetry INFO: I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
This is displayed by the local JVM, pointing that java couldn't reach the remote host. I believe the best approach would be checking the log files from your proxy server. It shall have the reason why this specific connection is being dropped.
Best regards,
Lucas Timm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.