【发布时间】:2016-07-15 13:53:12
【问题描述】:
嘿,伙计们,我真的在为此苦苦挣扎,我想通过 REST API 使用 java 创建新的 JIRA 问题,但是我看到的每个示例都不完整或对我不起作用: How to create an issue in jira using java rest api
任何帮助、示例代码或正确方向的链接将不胜感激!
【问题讨论】:
标签: java rest jira jira-rest-java-api
嘿,伙计们,我真的在为此苦苦挣扎,我想通过 REST API 使用 java 创建新的 JIRA 问题,但是我看到的每个示例都不完整或对我不起作用: How to create an issue in jira using java rest api
任何帮助、示例代码或正确方向的链接将不胜感激!
【问题讨论】:
标签: java rest jira jira-rest-java-api
我认为这个示例代码对你有帮助
这完全适合我
public static String invokePostMethod() throws AuthenticationException, ClientHandlerException, IOException {
Client client = Client.create();
WebResource webResource = client.resource("http://localhost:8080/rest/api/latest/issue");
String data = "{"fields":{"project":{"key":"DEMO"},"summary":"REST Test","issuetype":{"name":"Bug"}}}";
String auth = new String(Base64.encode(Uname + ":" + Password));
ClientResponse response = webResource.header("Authorization", "Basic " + auth).type("application/json").accept("application/json").post(ClientResponse.class, data);
int statusCode = response.getStatus();
if (statusCode == 401) {
throw new AuthenticationException("Invalid Username or Password");
} else if (statusCode == 403) {
throw new AuthenticationException("Forbidden");
} else if (statusCode == 200 || statusCode == 201) {
System.out.println("Ticket Create succesfully");
} else {
System.out.print("Http Error : " + statusCode);
}
// ******************************Getting Responce body*********************************************
BufferedReader inputStream = new BufferedReader(new InputStreamReader(response.getEntityInputStream()));
String line = null;
while ((line = inputStream.readLine()) != null) {
System.out.println(line);
}
return response.getEntity(String.class);
}
【讨论】: