Creating the project
The easiest way is to use Apache Maven2 for managing your project and just add the following dependency in your
Other build tools
JRJC library has several dependencies you need to have in your classpath in runtime.
See Project Dependencies for details.
Establishing "the connection"
RESTful architecture promotes stateless connection - that is there should be no notion of the user session.
Currently JRJC fully supports only Basic HTTP authentication (other means are coming soon), which means that you should not use it in public networks without encryption as your credentials more or less travel in the open text (just encoded with Base64). Thus use HTTPS to talk to your JIRA whenever possible. Use HTTP only in internal, private networks or for tests.
To talk to JIRA you need to obtain first a reference to
com.atlassian.jira.rest.client.JiraRestClient object, which then allows you to get references to more specialized parts of the client stack responsible for things like: handling issues, users, issue metadata, projects, etc.
com.atlassian.jira.rest.client.JiraRestClientFactory are capable of giving you the reference to
The current only implementation is Jersey-based one:
The following code snippet gets the reference to
Where to get
myAuthenticationHandler. It depends what type of authentcation mechanism you want to use. Currently you can construct an object of class
com.atlassian.jira.rest.client.auth.BasicHttpAuthenticationHandler or (for anonymous connection -
com.atlassian.jira.rest.client.auth.AnonymousAuthenticationHandler). Alternatively you can use
com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory#createWithBasicHttpAutentication to create
JiraRestClient using HTTP Basic auth with a single call.
When you have your
JiraRestClient object, it's time to make some use of it:
When things go wrong
Many things may go wrong and they often will. Network problems, authentication problems, bad data, invalid operations attempted, etc. - all of them may fail.
JRJC uses unchecked exceptions (similarly to other successful frameworks like Spring) in such cases.
com.atlassian.jira.rest.client.RestClientException is the exception thrown by JRJC classes. The original exceptions are wrapped by this exception. At the moment you need to use
getCause() to find underlying problem (like HTTP error code returned instead of expected 200 or 201) or just retrieve human readable reason with