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