Hey everyone, I’m trying to hook up my Java app to JIRA using their REST API. I’ve been messing with the JIRA REST Java Client (JRJC) but no luck so far.
Here’s what I’ve got:
import java.net.URI;
import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
public class JiraConnector {
private static final URI JIRA_URL = URI.create("http://localhost:8080/jira");
public static void main(String[] args) {
AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
JiraRestClient client = factory.createWithBasicHttpAuthentication(JIRA_URL, "myuser", "mypass");
// Trying to fetch user and issue info
var userPromise = client.getUserClient().getUser("myuser");
var issuePromise = client.getIssueClient().getIssue("PROJ-123");
// This part fails
var user = userPromise.claim();
var issue = issuePromise.claim();
System.out.println("User email: " + user.getEmailAddress());
System.out.println("Issue summary: " + issue.getSummary());
}
}
I’ve tried different JRJC versions (2.0.0-m2, 3.0.0, 4.0.0) but I’m getting a ‘Promise cannot be resolved’ error. Any ideas what I’m doing wrong? I’m totally stuck!
I’ve encountered similar issues when integrating Java applications with JIRA’s REST API. One potential solution is to use the JIRA REST API directly with a standard HTTP client like Apache HttpClient or OkHttp, instead of relying on JRJC.
Here’s a basic example using Apache HttpClient:
HttpClient httpClient = HttpClientBuilder.create().build();
HttpGet request = new HttpGet("http://localhost:8080/jira/rest/api/2/issue/PROJ-123");
request.addHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString(("myuser:mypass").getBytes()));
HttpResponse response = httpClient.execute(request);
String jsonResponse = EntityUtils.toString(response.getEntity());
// Parse JSON response and extract required information
This approach gives you more control over the HTTP requests and responses, and it’s often easier to troubleshoot. Remember to handle exceptions and close resources properly in a production environment.
hey mate, have u tried using the Unirest library? its pretty sweet for REST API stuff. heres a quick example:
HttpResponse<JsonNode> response = Unirest.get("http://localhost:8080/jira/rest/api/2/issue/PROJ-123")
.basicAuth("myuser", "mypass")
.asJson();
JSONObject issue = response.getBody().getObject();
its way simpler than JRJC and works like a charm. give it a shot!
I’ve been in your shoes, struggling with JIRA API integration. Here’s what worked for me:
Instead of JRJC, I switched to using Jersey client. It’s more straightforward and reliable for REST API calls. Here’s a snippet that might help:
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8080/jira/rest/api/2/issue/PROJ-123");
Response response = target.request(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "Basic " + Base64.getEncoder().encodeToString("myuser:mypass".getBytes()))
.get();
String jsonResponse = response.readEntity(String.class);
This approach bypasses the Promise issues you’re facing. Just remember to add proper exception handling and close your client when you’re done. Also, consider using a properties file for your JIRA URL and credentials for better security and flexibility.