【问题标题】:Creating a new "JIRA issue" using REST API in java在 Java 中使用 REST API 创建一个新的“JIRA 问题”
【发布时间】: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


    【解决方案1】:

    我认为这个示例代码对你有帮助

    这完全适合我

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

    【讨论】:

    • 您好,感谢您的评论,很抱歉回复晚了,您能告诉我您正在使用哪些库吗?
    • 使用这个maven差异commons-httpclientcommons-httpclient3.1`跨度>
    • 嘿,对不起,我离开后没有尽快回复您,您给我的代码似乎可以正常工作,因为我得到了正确的响应,但我没有登录,我得到了这个:感谢您的帮助
    猜你喜欢
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    • 2012-10-20
    • 1970-01-01
    • 2016-11-16
    • 1970-01-01
    • 2014-12-23
    • 1970-01-01
    相关资源
    最近更新 更多