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

name lastname Jul 16, 2013

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 in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

1,055 views 13 15
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you