Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

9 Commits

Repository files navigation

JIRA JSON API Client

A lightweight Java client library for the JIRA JSON API, supporting both REST and JSON-RPC 2.0 protocols.

The JSON-RPC client covers the transition period between JIRA 4.x and 5.x. The REST client targets the modern JIRA REST API (/rest/api/latest).

Why?

Available Java options at the time didn't work out of the box, or their documentation was outdated and hard to find. The official atlassian-jira-rest-java-client required extra keytool work for SSL and didn't expose the underlying Jersey configuration.

This library gives you direct, simple access to JIRA's JSON APIs with full control over the Jersey client configuration.

Requirements

  • Java 8+
  • Maven 3.x

Installation

Add the dependency to your pom.xml:

<dependency>
<groupId>com.ghosthack</groupId>
<artifactId>jira-json-client</artifactId>
<version>2.0.0</version>
</dependency>

Or build from source:

git clone https://github.com/ghosthack/jira-api-client.git
cd jira-api-client
mvn clean package

Usage

REST API Client

// Basic authenticationJiraJsonRestApiClientclient = newJiraJsonRestApiClient(
"https://jira.example.com", "username", "password");
// List all projectsList<Project> projects = client.getProjects();
// Create and post an issueIssueissue = client.buildIssue("PROJ", "Bug", "Login broken", "Cannot log in with SSO");
Map<String, Object> response = client.postIssue(issue);
// Get watchers for an issueList<String> watchers = client.getWatchers("PROJ-123");
// Add a watcherclient.postWatchers("PROJ-123", "jdoe");

JSON-RPC Client

// Create client (optionally pass a Jersey ClientConfig)JiraJsonRpcApiClientclient = newJiraJsonRpcApiClient("https://jira.example.com");
// AuthenticateStringtoken = client.login("admin", "password");
// Get an issueMap<String, Object> issue = client.getIssue(token, "PROJ-123");
// Create an issueIssuenewIssue = newIssue("PROJ", 1, "Summary", "Description");
Map<String, Object> created = client.createIssue(token, newIssue);

Custom Jersey Configuration

Both clients accept a Jersey ClientConfig for advanced configuration:

ClientConfigconfig = newDefaultClientConfig();
// customize config...JiraJsonRestApiClientclient = newJiraJsonRestApiClient(
"https://jira.example.com", config, "user", "pass");

SSL Certificate Bypass (Development Only)

For development environments with self-signed certificates:

importcom.ghosthack.jira.json.client.util.JerseyCertificateIgnoreBlackMagic;
ClientConfigconfig = JerseyCertificateIgnoreBlackMagic.ignoreCertConfig();
JiraJsonRestApiClientclient = newJiraJsonRestApiClient(
"https://localhost:8443", config, "admin", "admin");

Warning: This disables all SSL certificate validation. Never use in production.

Project Structure

src/main/java/com/ghosthack/jira/json/client/
AbstractJiraApiClient.java -- Shared base class
JiraJsonRestApiClient.java -- REST API client
JiraJsonRpcApiClient.java -- JSON-RPC 2.0 client
JiraJsonClientException.java -- Client exception type
model/
rest/ -- REST API models
Issue.java, IssueFields.java, IssueTypeName.java,
Login.java, Project.java, ProjectKey.java,
Watcher.java, Watchers.java
rpc/ -- JSON-RPC models
Issue.java, RpcParam.java, RpcRequest.java, RpcString.java
util/
CertificateIgnoreBlackMagic.java -- SSL bypass utility
JerseyCertificateIgnoreBlackMagic.java -- Jersey SSL config

Building and Testing

# Compile
mvn clean compile
# Run tests
mvn test# Package as JAR
mvn package
# Package as fat JAR with dependencies
mvn assembly:single

Dependencies

DependencyVersionPurpose
Jersey Client1.19.4HTTP/REST transport
Jersey Apache Client1.19.4Apache HTTP connector
Jackson Databind2.15.3JSON serialization
Jackson Annotations2.15.3JSON annotations

Test dependencies: JUnit 4.13.2, Mockito 4.11.0

References

License

See repository for license details.

About

WIP JIRA JSON APIs (RPC, REST) client

Resources

Stars

7 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages