It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to connect to JIRA with Java REST-API via a proxy-Server

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.

1 answer

1 accepted

1 vote
Answer accepted

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

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published Thursday in Confluence

Confluence CVEs and common questions

Two vulnerabilities have been published for Confluence Server and Data Center recently: March 20, 2019 CVE-2019-3395 / CVE-2019-3396 April 17, 2019 CVE-2019-3398 The goal of this article is...

75 views 0 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you