0
我檢查了幾乎所有鏈接,但找不到適當的解決方案。 我需要使用java rest api在JIRA中創建一個問題。 代碼: -如何使用java rest api在jira中創建問題
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.codehaus.jettison.json.JSONException;
import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.api.domain.BasicProject;
import com.atlassian.jira.rest.client.api.domain.Issue;
import com.atlassian.jira.rest.client.internal.ServerVersionConstants;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactor;
public class TestingRestAPI {
private static URI jiraServerUri =
URI.create("https://vgsvdgteam.jira.com/rest/api/2/project");
public static void main(String[] args) throws URISyntaxException,
JSONException, IOException {
final AsynchronousJiraRestClientFactory factory = new
AsynchronousJiraRestClientFactory();
final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "liasia","cooki123!!");
try {
final int buildNumber = restClient.getMetadataClient().getServerInfo().claim().getBuildNumber();
System.out.println("---------------------------------"+buildNumber);
// first let's get and print all visible projects (only jira4.3+)
System.out.println("Print all print all visible projects:");
if (buildNumber >= ServerVersionConstants.BN_JIRA_6) {
final Iterable<BasicProject> allProjects = restClient.getProjectClient().getAllProjects().claim();
for (BasicProject project : allProjects) {
System.out.println(project);
}
}
// then print one issue details
System.out.println("Print issue TST-63239");
final Issue issue = restClient.getIssueClient().getIssue("TST-63239").claim();
System.out.println(issue);
}
finally {
restClient.close();
}
}
}
依賴加入pom.xml中: -
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-api</artifactId>
<version>2.0.0-m25</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>2.0.0-m25</version>
<scope>provided</scope>
</dependency>
時出現例外: -
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" RestClientException{statusCode=Optional.of(404), errorCollections=[ErrorCollection{status=404, errors={}, errorMessages=[]}]}
at com.atlassian.jira.rest.client.internal.async.DelegatingPromise.claim(DelegatingPromise.java:47)
at com.citrix.restjira.jiratest.TestingRestAPI.main(TestingRestAPI.java:25)
Caused by: RestClientException{statusCode=Optional.of(404), errorCollections=[ErrorCollection{status=404, errors={}, errorMessages=[]}]}
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:166)
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:160)
at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:48)
at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:12)
at com.atlassian.util.concurrent.Promises$Of$3.apply(Promises.java:285)
at com.atlassian.util.concurrent.Promises$2.onSuccess(Promises.java:162)
at com.google.common.util.concurrent.Futures$7.run(Futures.java:1072)
檢查異常後,它似乎Serverinfo的要求()函數類有問題。 或者URL有問題? 有人可以幫助我解決這個問題或任何有用的鏈接?
謝謝......但這裏定義的restClient和openClient方法是什麼? –
對不起,編輯我的答案 –
謝謝..非常有幫助。你能分享一些關於IssueJiraDTO issueDTO的內容嗎? –