Project

General

Profile

Rest api with java » History » Revision 15

Revision 14 (Terence Mill, 2013-06-06 09:47) → Revision 15/19 (Alex Last, 2014-09-15 01:30)

h1. Using the REST API with Java 

 h2. Jredmine 

 "Jredmine":http://maven-site.nuiton.org/jredmine/index.html (implements its own redmine plugin and correspodnsing java client - more other/features than redmine rest api) 

 h2. redmine-jconnector 

 "redmine-jconnector":https://code.google.com/p/redmine-jconnector/ (only until redmine 1.4 using REST API) 

 h2. Redmine Java API library from taskadapter 

 "Redmine Java API library":https://github.com/taskadapter/redmine-java-api is a FREE third-party Java library that can be used to access the Redmine API. It is released under Apache 2 open-source license. (support until Redmine 2.3 using REST API) 

 Sample usage: 

 <pre> 

	 
 import java.io.IOException; 
 import java.net.URISyntaxException; 
 import java.util.List; 
 import com.taskadapter.redmineapi.RedmineManager; 
 import com.taskadapter.redmineapi.bean.Issue; 

 public class Simple { 
	 private static String uri redmineHost = "https://www.hostedredmine.com"; 
	 private static String apiAccessKey = "a3221bfcef5750219bd0a2df69519416dba17fc9"; 
	 private static String projectKey = "taskconnector-test"; 
	 private static Integer queryId = null; // any 
        
         ... 
	
         

	 public static void main(String[] args) { 
		 RedmineManager mgr = RedmineManagerFactory.createWithApiKey(uri, new RedmineManager(redmineHost, apiAccessKey); 
         IssueManager issueManager = mgr.getIssueManager(); 
         
		 try { 
			 tryGetIssues(mgr); 
		 } catch (Exception e) { 
			 e.printStackTrace(); 
		 } 
	 } 

	 private static void tryGetIssues(RedmineManager mgr) throws Exception { 
		 List<Issue> issues = issueManager.getIssues(projectKey, mgr.getIssues(projectKey, queryId); 
         
		 for (Issue issue : issues) { 
             
			 System.out.println(issue.toString()); 
         
		 } 

         // 
	 } 
 } 
 </pre> 

 Create issue Issue: 

 <pre> 
	 Issue issueToCreate = IssueFactory.createWithSubject("some subject"); new Issue(); 
	 issueToCreate.setSubject("This is the summary line 123"); 
	 Issue createdIssue newIssue = issueManager.createIssue(projectKey , mgr.createIssue(PROJECT_KEY, issueToCreate); 

         // 
 </pre> 

 Get issue by ID: 

	 

 <pre> 
	 Issue issue = issueManager.getIssueById(123); mgr.getIssueById(123); 
 </pre>