Yesterday when I was going through some article, I saw lots requests and comments for JIRA REST JAVA Client!!!
I wondered and decided to provide the REST JAVA API for JIRA, and this is the one.
Connecting to JIRA using JAVA REST API is really a very easy thing like Ice Cream Sandwich ;) :) and can be written in a plain vanilla flavor.
Today I'm providing you the search operation functionality to get the tickets.
/**
* Gets all the issues based on the query and displays .... !!!!
*
* @param username the username
* @param password the password
* @param url the url
* @return the all issues
* @throws AuthenticationException the authentication exception
* @throws JSONException the jSON exception
*/
private static void getAllIssues(String username, String password, String url) throws AuthenticationException, JSONException
{
final String auth = new String(Base64.encode(username + ":" + password));
final Client client = Client.create();
final WebResource webResource = client.resource(url);
final ClientResponse response = webResource.header("Authorization", "Basic " + auth).type("application/json")
.accept("application/json").get(ClientResponse.class);
final int statusCode = response.getStatus();
if (statusCode == 401)
{
throw new AuthenticationException("Invalid Username or Password");
}
final String stringResponse = response.getEntity(String.class);
System.out.println("sr: " + stringResponse);
}
Usage of the above method:
1) getAllIssues("krishna", "krishna", "http://server:8080/rest/api/latest/search?jql");
fetches all the issues.. !!!
2) getAllIssues("krishna", "krishna", " http://server:8080/rest/api/latest/issue/Issue-84?expand=schema,names,transitions");
It gets all the issue whose key is Issue-84.... !!!
Have FUN...!!!!