Project

General

Profile

Rest api with java » History » Version 8

Alex Last, 2011-01-26 09:19

1 1 Jean-Philippe Lang
h1. Using the REST API with Java
2 2 Alex Last
3 8 Alex Last
"Redmine Java API library":http://www.taskadapter.com/redmine_java_api is a -commercial- (becomes FREE and open-source in the next few days), third-party Java library that can be used to access the Redmine API.
4 2 Alex Last
5
Sample usage:
6 6 Jean-Philippe Lang
7 2 Alex Last
<pre>
8
import java.io.IOException;
9
import java.util.List;
10
11
import org.alskor.httputils.AuthenticationException;
12 4 Alex Last
import org.alskor.httputils.NotFoundException;
13 2 Alex Last
import org.alskor.redmine.RedmineManager;
14
import org.alskor.redmine.beans.Issue;
15
16
public class Simple {
17
	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 4 Alex Last
	private static String Integer = null; // any
21 2 Alex Last
22
	public static void main(String[] args) {
23
		RedmineManager mgr = new RedmineManager(redmineHost, apiAccessKey);
24
		try {
25
			tryGetIssues(mgr);
26
		} catch (Exception e) {
27
			e.printStackTrace();
28
		}
29 1 Jean-Philippe Lang
	}
30 2 Alex Last
31 4 Alex Last
	private static void tryGetIssues(RedmineManager mgr) throws IOException, AuthenticationException, NotFoundException {
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>