Project

General

Profile

Rest api with java » History » Version 13

Terence Mill, 2013-06-06 09:46

1 1 Jean-Philippe Lang
h1. Using the REST API with Java
2 2 Alex Last
3 13 Terence Mill
* "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)
4
* "redmine-jconnector":https://code.google.com/p/redmine-jconnector/ (only until redmine 1.4 using REST API)
5
* "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)
6 2 Alex Last
7
Sample usage:
8 6 Jean-Philippe Lang
9 2 Alex Last
<pre>
10 1 Jean-Philippe Lang
import java.io.IOException;
11 9 Alex Last
import java.net.URISyntaxException;
12 1 Jean-Philippe Lang
import java.util.List;
13 12 Chris Maiden
import com.taskadapter.redmineapi.RedmineManager;
14
import com.taskadapter.redmineapi.bean.Issue;
15 2 Alex Last
16 1 Jean-Philippe Lang
public class Simple {
17 2 Alex Last
	private static String redmineHost = "https://www.hostedredmine.com";
18
	private static String apiAccessKey = "a3221bfcef5750219bd0a2df69519416dba17fc9";
19 1 Jean-Philippe Lang
	private static String projectKey = "taskconnector-test";
20 9 Alex Last
	private static Integer queryId = null; // any
21 2 Alex Last
22
	public static void main(String[] args) {
23
		RedmineManager mgr = new RedmineManager(redmineHost, apiAccessKey);
24
		try {
25 1 Jean-Philippe Lang
			tryGetIssues(mgr);
26 2 Alex Last
		} catch (Exception e) {
27 1 Jean-Philippe Lang
			e.printStackTrace();
28
		}
29
	}
30 9 Alex Last
31 10 Alex Last
	private static void tryGetIssues(RedmineManager mgr) throws Exception {
32 2 Alex Last
		List<Issue> issues = mgr.getIssues(projectKey, queryId);
33
		for (Issue issue : issues) {
34
			System.out.println(issue.toString());
35
		}
36
	}
37
}
38
</pre>
39
40
Create Issue:
41
42
<pre>
43
	Issue issueToCreate = new Issue();
44
	issueToCreate.setSubject("This is the summary line 123");
45
	Issue newIssue = mgr.createIssue(PROJECT_KEY, issueToCreate);
46
</pre>
47
48
Get issue by ID:
49
50
<pre>
51 5 Alex Last
	Issue issue = mgr.getIssueById(123);
52
</pre>