创建新的"JIRA问题";在Java中使用REST API [英] Creating a new "JIRA issue" using REST API in java

查看:501
本文介绍了创建新的"JIRA问题";在Java中使用REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我真的很为此苦苦挣扎,我想通过REST API使用Java创建新的JIRA问题,但是我看到的每个示例都不完整,或者像这样对我不起作用: 如何使用Java Rest在jira中创建问题api

Hey guys i am really struggling with this, i would like to create new JIRA issues using java through the REST API but every example i have seen is incomplete or doesnt work for me like this one: How to create an issue in jira using java rest api

任何帮助,示例代码或指向正确方向的链接将不胜感激!

Any help, sample code or link to the right direction would be greatly appreciated!

推荐答案

我认为此示例代码对您有帮助

这完全是为我工作

This is totlly working for me

 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);
}

这篇关于创建新的"JIRA问题";在Java中使用REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆