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