Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Using JIRA REST Java Client via a HTTP Proxy

James Bewley March 12, 2013

I have recently built a feature to submit issues directly from our product using the JIRA REST Java Client (v1.0). The client is working as expected and sumbits issues to our JIRA server but I now need to add proxy settings to the client so it can work in corporate networks etc.

According to the following ticket we are unable to configure a proxy with v1.0, is this correct? If so, is version 2 stable enough for production and how would I go about migrating?

https://ecosystem.atlassian.net/browse/JRJC-107

Many thanks,

James

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Daniel Eichhorn September 9, 2013

Thanks for your answer but I fear this won't help, since NTLM is challenge response and based on connection. So I have the feeling that there is no public interface in your code that allows me do solve this problem...

0 votes
Daniel Eichhorn September 5, 2013

The ProxySelector is not the problem. It seems that the authentication makes the difference. The first part of the code uses the plain vanilla JiraRest client. The security proxy answers that the proxy authentication failed. I have set hostname and port using the -Dproxy... settings in both cases

1) Rest Client

URL jiraServerUri = new URL("myJiraUrl");

AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();

JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "username", "password");

Issue issue = restClient.getIssueClient().getIssue("myIssue").get();

System.out.println(issue.getDescription());

restClient.close();

2) Here I'm connecting to the same url with low level API and it works!

Authenticator.setDefault(new Authenticator() {

                    @Override

                    protected PasswordAuthentication getPasswordAuthentication() {

                           returnnew PasswordAuthentication("username", "password".toCharArray());

                    }

             });

             URL url = new URL("myJiraUrl");

             URLConnection connection = url.openConnection();

             BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

            

             String line;

            

             while((line = reader.readLine())!=null) {

                    System.out.println(line);

 

             }

UPDATE: the small tool TCPMon helped me to see the request parameters of request 1 (low level api) and it seems, that the authentication expected is NTLM

Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 8, 2013

Then you just need custom authentication handler ;).

0 votes
Daniel Eichhorn September 5, 2013

@Aleksander: would you mind showing in an example how the proxy could be configured? I'm trying to talk to a JIRA instance through a proxy that does not require authentication, but the httpclient seems to use authentication, which results in an error. I don't see how I can change proxy configuration in the HttpClient, since the ProxySelectorAsyncRoutePlanner is not accessible nor is the nonCachingHttpClient

Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 5, 2013

Sorry, I don't have example for proxy. But looking at the code I can suggest setting proxy selector in ProxySelector#setDefault, as DefaultHttpClient uses ProxySelector.getDefault().

Can you share the code that you tried and doesn't work?

0 votes
Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 24, 2013

The 1.x version is already abandoned - we're not going to improve it further. Although you can build a 1.x version by yourself - there is a not-well-tested change that allows to get apache http client instance used by JRJC (JiraRestClient#getTransportClient()).

The 2.x version is quite stable now - it will take some time to hit the release (due to limited resources for that project), but API is rather stable, so grab the last milestone release and try it! In 2.x it's possible to configure the proxy, as you can pass HTTP client to the JRJC factory (AsynchronousJiraRestClientFactory#create(URI serverUri, HttpClient httpClient)), but it's not yet as easy as just passing proxy configuration (you have to create HttpClient by yourself - see AsynchronousHttpClientFactory).

The migration from 1.x to 2.x should be not-so-hard ;). The biggest change is that every method now returns Promise, so you have to call .claim() to get the actual result (or make a use of asynchronous API - see Promise class for details).

Another important change is that you have to cleanup JRJC instance by yourself - just call close() on it after you're done (or just cleanup httpClient if you have created your own instance).

If you want to migrate, change the dependency to:

<dependency>
  <groupId>com.atlassian.jira</groupId>
  <artifactId>jira-rest-java-client-core</artifactId>
  <version>2.0.0-m15</version>
</dependency>

Deepak Srivastav Srinathan May 28, 2013

Is it possible for you to provide a code snippet for doing the same? I have been trying to do it and it does not look so straight forward !

MB
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2013

Regarding the claim() method, I can help you with that. Instead of using:

jc.getSearchClient().searchJql("type = Bug ORDER BY RANK ASC", null);

try using something like this:

jc.getSearchClient().searchJql("type = Bug ORDER BY RANK ASC").claim();

shortly, remove ",null" in the method's parameter and add ".claim()" in order to get the desired object instead of Promise<object>.

MB
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 25, 2013

@Aleksander Mierzwicki
Where can I find 2.0.0-m15 jar file (or 2.0.0-m25 which is the latest as of now)?

Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 25, 2013

JRJC is in Atlassian public maven repository: https://maven.atlassian.com/public/com/atlassian/jira/jira-rest-java-client-core/

The last released version to maven is: https://maven.atlassian.com/content/repositories/atlassian-public/com/atlassian/jira/jira-rest-java-client-core/2.0.0-m23/

But the best way is to build your project using maven (you'll need to add Atlassian public to settings.xml), as this allows you to easily collect all the dependencies.

MB
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 25, 2013

Thanks. I just realized that jira-rest-java-client has been split into jira-rest-java-client-core and jira-rest-java-client-api and have tried to put into my pom.xml only this:

&lt;dependency&gt;
	&lt;groupId&gt;com.atlassian.jira&lt;/groupId&gt;
	&lt;artifactId&gt;jira-rest-java-client-core&lt;/artifactId&gt;
	&lt;version&gt;2.0.0-m23&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
	&lt;groupId&gt;com.atlassian.jira&lt;/groupId&gt;
	&lt;artifactId&gt;jira-rest-java-client-api&lt;/artifactId&gt;
	&lt;version&gt;2.0.0-m23&lt;/version&gt;
&lt;/dependency&gt;

and atlas-debug started JIRA normally, without issues, but I again experienced the same ClassNotFound runtime exception, as decsribed here https://answers.atlassian.com/questions/192961/jira-rest-client-proper-usage and here https://answers.atlassian.com/questions/194331/can-anyone-provide-a-simple-example-of-jira-rest-java-client-jrjc-plugin-code

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events