使用带有maven的java中的REST API创建新的“JIRA问题”

时间:2016-12-21 06:14:37

标签: java maven jira-rest-api

我尝试执行下面的代码,它将响应状态代码设置为200,但它没有在JIRA中创建任何问题。

public static String invokePostMethod() throws AuthenticationException, ClientHandlerException, IOException {

        Client client = Client.create();
        WebResource webResource = client.resource("JIRA_URL");                 

        String data = "{\"fields\":{\"project\":{\"key\":\"test\"},\"summary\":\"test\",\"issuetype\":{\"name\":\"Bug\"}}},\"assignee\":{\"name\":\"QA\"}}}";

        String auth = new String(Base64.encode(("uname" + ":" + "pwd").getBytes(),0));
        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);
    }

我也在发布控制台输出,如下所示....

<input type="hidden" title="loggedInUser" value="userName">
<input type="hidden" title="ajaxTimeout" value="The call to the JIRA server did not complete within the timeout period.  We are unsure of the result of this operation.">
<input type="hidden" title="JiraVersion" value="6.0.4" />
<input type="hidden" title="ajaxUnauthorised" value="You are not authorized to perform this operation.  Please log in.">
<input type="hidden" title="baseURL" value="JIRA_URL">
<input type="hidden" title="ajaxCommsError" value="The JIRA server could not be contacted.  This may be a temporary glitch or the server may be down.">
<input type="hidden" title="ajaxServerError" value="The JIRA server was contacted but has returned an error response. We are unsure of the result of this operation.">
<input type="hidden" title="ajaxErrorCloseDialog" value="Close this dialog and press refresh in your browser">
<input type="hidden" title="ajaxErrorDialogHeading" value="Communications Breakdown">

<input type="hidden" title="dirtyMessage" value="You have entered new data on this page. If you navigate away from this page without first saving your data, the changes will be lost.">
<input type="hidden" title="dirtyDialogMessage" value="You have entered new data in this dialog. If you navigate away from this dialog without first saving your data, the changes will be lost. Click cancel to return to the dialog.">
<input type="hidden" title="keyType" value="Type">
<input type="hidden" title="keyThen" value="then">
<input type="hidden" title="dblClickToExpand" value="Double click to expand">
<input type="hidden" title="actions" value="Actions">
<input type="hidden" title="removeItem" value="Remove">
<input type="hidden" title="workflow" value="Workflow">
<input type="hidden" title="labelNew" value="New Label">
<input type="hidden" title="issueActionsHint" value="Begin typing for available operations or press down to see all">
<input type="hidden" title="closelink" value="Close">
<input type="hidden" title="dotOperations" value="Operations">
<input type="hidden" title="dotLoading" value="Loading...">
<input type="hidden" title="frotherSuggestions" value="Suggestions">
<input type="hidden" title="frotherNomatches" value="No Matches">
<input type="hidden" title="multiselectVersionsError" value="{0} is not a valid version.">
<input type="hidden" title="multiselectComponentsError" value="{0} is not a valid component.">
<input type="hidden" title="multiselectGenericError" value="The value {0} is invalid.">

任何人都可以调查一下,让我知道我是否可以改进我的代码......?

0 个答案:

没有答案