如何使用REST API在Java中检索特定的JIRA字段

问题描述 投票:0回答:1

到目前为止,我只能与Jira建立连接,但我不知道如何获取特定字段。据我所知,JIRA API的SearchResult类将解决这个问题,但我不知道如何将它集成到我现有的代码中。任何帮助将非常感激。

Java版本 - 8,操作系统 - Windows 10,Eclipse - Mars

/ *使用的罐子:jersey-bundle-1.9.jar(https://mvnrepository.com/artifact/com.sun.jersey/jersey-bundle/1.9)javax.ws.rs-api-2.0-m02.jar(https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api/2.0-m02)* /

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.Base64;
public class JiraData {
static ClientResponse response;

public static void main(String[] args) {


try
{

String auth = new String(Base64.encode("username" + ":" + "password"));
final String headerAuthorization = "Authorization";
final String headerAuthorizationValue = "Basic " + auth;
final String headerType = "application/json";
Client c = Client.create();


WebResource webResource = c.resource("https://jira.com");
response = webResource.header(headerAuthorization, headerAuthorizationValue).type(headerType).accept(headerType).get(ClientResponse.class);
String connectionresult = response.toString();
System.out.println(connectionresult); // returned a response status of 200 OK

if (response.getResponseStatus() != null && response.getResponseStatus().getStatusCode() == 200)
{
System.out.println("Connection Successful");
fetchFields();
}


}

catch(Exception e)
{
System.out.println(" Connection Error " + e);
}




}

private static void fetchFields() {

try
{

String jql = "project = SAMPLE";
/*
* Missing logic to Capture Jira fields like Ticket Number, Ticket URL, Issue Type, Ticket Status for project passed in jql
*/


}

catch(Exception e)
{
System.out.println(" Error from fetchFields method " + e);
}

finally
{
response.close();

}


}

}
java jira-rest-api
1个回答
0
投票

由于您似乎想要使用/search端点(因为您准备了JQL语句),因此可以使用查询参数来确定应返回哪些字段。只需使用/search?fields=issuekey,summary,description之类的URL来定义要返回的字段列表(不要忘记定义您的JQL)。可以使用/field端点访问完整的可用字段列表,请参阅REST API docs here。您还可以在/search中找到REST API docs端点的更多查询参数。

© www.soinside.com 2019 - 2024. All rights reserved.