JIRA REST client - simple example

Vladimir Vasic
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 24, 2013

Hello guys and girls,

can anybody post a valid Maven pom.xml along with simple Java code example for JRJC usage.

It should use JerseyJiraRestClientFactory or AsynchronousJiraRestClientFactory for example creating issues on remote JIRA instance and retrieving JIRA Issue object

3 answers

1 accepted

2 votes
Answer accepted
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 31, 2013

I've written an example usage of the JRJC (version 2.0.0-m2) as a standalone, executable JAR.

Here's the pom.xml.

And the main Java class.

I tested it against JIRA 6.0.

Vladimir Vasic
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 31, 2013

Thank you very much Joseph. I'll give it a try.

Vladimir Vasic
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 31, 2013

Great - it finaly works! I've tested it against JIRA v5.2.5 successfully. One more question Joseph, I had an error when tried to buld it on mu plugin development environment which uses Maven v2.1 for project build. Is there any chance that I could use JRJC you sent like this in Jira plugin?

Vladimir Vasic
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 31, 2013

Sorry, forget about last question cause I just saw plugin that you have over there in Bitbucket repository and it works like charm. Only thing that I was interested about is that Maven pom of yours. I never saw that kind of exclusions in pom in order not to have dependency issue between them. So it must of bean that, that I always had problems with Maven build of given pom files until now, cause I didn't know what to exclude cause JIRA already have some of them included. Anyway thanks a lot, you saved me lot of trouble.

Sal October 12, 2013

too many dependency issues - checksum issues and not downloading other dependencies properly. Writing my own instead...

steve gee October 15, 2013

I have spent endless hours looking for a simple example ... all the API examples I found..until now...were too old and API's no longer worked.

+1

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 16, 2013

Is the example I provided OK? If not, please let me know which aspects of it you find are most in need of improvement. :-)

Rama Palaniappan October 16, 2013

The project that I shared should work.

https://code.google.com/p/ramp-sample/source/browse/samples/jira-rest-java-client/pom.xml

Let me know if this doesn't work for you.

Tony Abidi August 26, 2015

Hi @Joe Clark [Atlassian]: I did everything like in the example, but however... I'm getting an error :( do you happen to know why am I getting this? when the program get to this line JiraRestClient client = factory.createWithBasicHttpAuthentication(uri, username, password); Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/apache/http/nio/NHttpMessageParserFactory I can't help to think this is happening because of maven dependencies. Any suggestion?

Petros GiaKouvakis September 14, 2015

Thnx Joseph! Was struggling to get the JIRA Rest client working but your example really helped! Much obliged!

0 votes
RambanamP
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

Actuall i am not using JRJC, we are using our won client using jersy, you can try if you want

package com.rest.client;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;

public class RESTclient {

	public static void main(String[] args) {
		try {

			Client client = Client.create();			
			client.addFilter(new HTTPBasicAuthFilter("username", "password"));
			WebResource webResource = client.resource("http://localhosr:8080/rest/api/2/issue");			
			String input="{\"fields\":{\"project\":{\"key\":\"JIRA\"},\"summary\":\"Test Ticket\",\"description\":\"This is a test CR\", \"reporter\": {\"name\": \"prasad\"},\"issuetype\":{\"name\":\"Defect\"},\"versions\":[{\"name\":\"1.0\"}],\"customfield_10692\":{\"value\":\"Stability\"},\"customfield_10430\":{\"value\":\"Stability\"},\"customfield_10005\":{\"value\":\"Blocker\"},\"components\":[{\"name\":\"TEST\"}]}}";		
			ClientResponse response = webResource.type("application/json").post(ClientResponse.class, input);
	
			String output = response.getEntity(String.class);

			System.out.println("Output from Server .... \n");
			System.out.println(output);

		} catch (Exception e) {

			e.printStackTrace();

		}

	}
}
 

Vladimir Vasic
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 already use my own Rest client, I was just wondering if some one really use JRJC and have pom.xml and code snippet for eg. AsynchronousJiraRestClientFactory usage (JRJC v2.0.0-m23)

having all this posts and tutorials and not one really working example.

0 votes
RambanamP
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 24, 2013
Vladimir Vasic
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

It is not a solution. I see that changing the dependency scope to compile fixed initial problem but the code eventually didn't work cause of another dependency issue with apache httpclient. So I am asking if anybody have working pom.xml with code snippet of using RJRC?

Suggest an answer

Log in or Sign up to answer