'Harnessing JIRA's SOAP API with Java' post illustration

Harnessing JIRA's SOAP API with Java

avatar

JIRA is a popular issue tracking and project management software. It can be used and accessed by lots of different means like IDE, email client or a web browser. Also there are many plug-ins for all sorts of other software products. Such an abundance is explained by the fact that JIRA has open and convenient remote procedure call APIs: REST, XML-RPC and SOAP.

So, it is possible to make your application communicate with JIRA through these APIs, too. If correctly integrate a Java API client, issuing a command to JIRA becomes the same as invoking a local subroutine. Let’s create such a little Java program and do some manipulations with an Issue in JIRA.

SOAP is the preferred method for remote method calls in JIRA and is the most frequently updated therefore we’ll stick with it. First of all, ensure that RPC is enabled in your JIRA. For the client implementation JIRA's proposing to generate .java files from WSDL description. But there is a precompiled library already in a Atlassian Maven repository with all dependencies needed. Simply put the dependency in your project’s .pom file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<repositories>
   <repository>
       <id>atlassian-contrib</id>
       <url>https[column]//maven.atlassian.com/contrib/</url>
   </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>org.swift.common</groupId>
    <artifactId>jira-soap</artifactId>
    <version>4.4.0</version>
  </dependency>
</dependencies>

Now you are ready to go. The first thing what you have to do is to log in:

1
2
3
4
5
6
7
8
9
10
// Initialize JiraSoapService object, which will be used for all communication with JIRA
String ENDPOINT = "/rpc/soap/jirasoapservice-v2";
JiraSoapServiceServiceLocator jiraSoapServiceGetter = new JiraSoapServiceServiceLocator() {{
   // Provide your JIRA base URL like http://[host]:[port]
   setJirasoapserviceV2EndpointAddress("JIRA_BASE_URL" + ENDPOINT);
   setMaintainSession(true);
}};
JiraSoapService jiraSoapService = jiraSoapServiceGetter.getJirasoapserviceV2();
// Provide your username and password
String token = jiraSoapService.login("username", "password");

After calling login on a JiraSoapService with a valid username and password you will get a token that you will pass to all functions hereafter.

From the moment you are logged in you can do manipulations. Suppose you have an open Issue already in your JIRA. You can get available fields for edition:

1
2
// Provide Issue key which you want to modify, like PROJECTNAME-###
RemoteField[] availableFields = jiraSoapService.getFieldsForEdit(token, "ISSUE_KEY");

You can modify the Issue:

1
2
3
RemoteFieldValue descriptionField = new RemoteFieldValue("description", new String[]{"new description"});
RemoteFieldValue assigneeField = new RemoteFieldValue("assignee", new String[]{"savvyAssignee"});
jiraSoapService.updateIssue(token, issueKey, new RemoteFieldValue[]{descriptionField, assigneeField});

Just post a comment on the Issue:

1
2
3
4
RemoteComment remoteComment = new RemoteComment() {{
       setBody("It was a really easy issue");
}};
jiraSoapService.addComment(token, "ISSUE_KEY", remoteComment);

Or resolve the Issue:

1
2
jiraSoapService.progressWorkflowAction(token, "ISSUE_KEY", "5", new RemoteFieldValue[]{});
//"4"--Start progress, "5"--Resolve, "3"--Reopen

This is just a little example to help you get started, there is a plethora of stuff to play with. Study JiraSoapService documentation to know what more you can do with your JIRA.

If you're looking for a developer or considering starting a new project,
we are always ready to help!