Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to fetch and update existing JIRA issues using RestClient api through Eclipse IDE?

Rutuja
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 11, 2018

Purpose : To create an interface between java based tool and JIRA.

Requirements: 1)To fetch existing issues and issue attributes from JIRA (Read from JIRA)

                        2) Update the issue attributes in JIRA (Write back in JIRA)

 

Description: While trying to fetch the issues from JIRA using RestClient, getting RestClient exception.

Sample code:

// Accessing Issue
Promise<Issue> promise2=client.getIssueClient().getIssue("TESKAN-1");
System.out.println(promise2);
/* ============Getting an exception when trying to fetch the attributes of JIRA issue===========*/
Issue issue = promise2.claim();

Error code:

com.atlassian.jira.rest.client.internal.async.DelegatingPromise@5a4041cc
Exception in thread "main" RestClientException{statusCode=Optional.absent(), errorCollections=[]}
at com.atlassian.jira.rest.client.internal.async.DelegatingPromise.claim(DelegatingPromise.java:47)
at JiraInterface.main(JiraInterface.java:56)
Caused by: RestClientException{statusCode=Optional.absent(), errorCollections=[]}

 

1 answer

0 votes
Thomas Deiler
Community Champion
December 11, 2018

Dear @Rutuja,

I understand your requirement but what's the issue with Eclipse? Do you call Jira from Eclipse or from the RestClient?

So long

Thomas

Rutuja
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 11, 2018

Hello @Thomas Deiler

No issues with Eclipse. It is just that Eclipse platform is used for java code development.

JIRA is called using RestClient api.

Please find the code below for you reference.

Thank you.

 ==========================================================

import java.net.URI;

import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.api.JiraRestClientFactory;
//import com.atlassian.jira.rest.client.api.domain.BasicProject;
//import com.atlassian.jira.rest.client.api.NullProgressMonitor;
//import com.atlassian.jira.rest.client.api.domain.User;
import com.atlassian.jira.rest.client.api.domain.Issue;
//import com.atlassian.jira.rest.client.api.domain.Project;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
//import com.atlassian.util.concurrent.Promise;

/**
* Entry-point invoked when the jar is executed.
*/
public class trial
{
private static final String JIRA_URL = "";

private static final String JIRA_ADMIN_USERNAME = "";
private static final String JIRA_ADMIN_PASSWORD = "";

public static void main(String[] args) throws Exception
{

// Print usage instructions
StringBuilder intro = new StringBuilder();
intro.append("**********************************************************************************************\r\n");
intro.append("* JIRA REST Java Client ('JRJC') example. *\r\n");
intro.append("* NOTE: Start JIRA using the Atlassian Plugin SDK before running this example. *\r\n");
intro.append("* (for example, use 'atlas-run-standalone --product jira --version 6.0 --data-version 6.0'.) *\r\n");
intro.append("**********************************************************************************************\r\n");
System.out.println(intro.toString());

// Construct the JRJC client
System.out.println(String.format("Logging in to %s with username '%s' and password '%s'", JIRA_URL, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD));
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
URI uri = new URI(JIRA_URL);
JiraRestClient client = factory.createWithBasicHttpAuthentication(uri, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD);
try{

/*=========Getting Rest Client Exception here while I try to fetch any particular issue ========*/
Issue issue = client.getIssueClient().getIssue("TESKAN-1").claim();
System.out.println(issue);


System.out.println(issue.getKey());
System.out.println("Summary : " + issue.getSummary());
System.out.println("Description : " + issue.getDescription());
System.out.println("Status : " + issue.getStatus().getName());
System.out.println("Issue Type : " + issue.getIssueType().getName());
System.out.println("Assignee : " + issue.getAssignee().getDisplayName());
System.out.println("Reporter : " + issue.getReporter().getDisplayName());

// Done
System.out.println("Example complete. Now exiting.");
System.exit(0);
}
finally {
// cleanup the restClient
client.close();
}
}
}

===========================================================

Error Code :

 

Exception in thread "main" RestClientException{statusCode=Optional.absent(), errorCollections=[]}
at com.atlassian.jira.rest.client.internal.async.DelegatingPromise.claim(DelegatingPromise.java:47)
at trial.main(trial.java:45)
Caused by: RestClientException{statusCode=Optional.absent(), errorCollections=[]}

============================================================

Thomas Deiler
Community Champion
December 12, 2018

I am not familiar with the RestClient from Atlassian. I prefer direct communication with Apache's HTTPClient Lib.

I recommend to to dump the sent request from this RestClient and drop it inside any other RestClient like Postman (or any other browser extension supporting REST).

Just to ensure the request built from the RestClient is integer.

So long

Thomas

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events