JIRA 使用 Rest Assured API 创建错误:AuthenticationException:无效的用户名或密码

问题描述

查询

当使用放心 API(java) 测试失败时,自动在 JIRA 门户中创建错误,但输出为 AuthenticationException: Invalid Username or Password but the Same 在 Postman 中获得成功。我可以创建错误并使用 Jira 的所有 API,这些 API 通过基本的用户名和密码身份验证本身可以正常工作。尝试了我在 StackOverflow 中找到的几个场景,但响应相同(AuthenticationException: Invalid Username or Password )

采取的步骤:

Scenario 1 : 
------------

public void endTest(ITestResult result) throws JiraException {
        System.out.println("Ended Test execution");
        String username = "*******";
        String password = "*******";

        if (result.getStatus() == ITestResult.FAILURE) {
            BasicCredentials cred = new BasicCredentials(username,password);
            JiraClient jira = new JiraClient("http://localhost:8080/",cred);
            Issue issueName = jira.createIssue("AAA","Bug").field(Field.SUMMARY,result.getmethod().getmethodName() + "is Failed due to: " + result.getThrowable().toString()).field(Field.DESCRIPTION,"Please take this Bug priority").execute();
            System.out.println("Issue created in Jira with key : " + issueName.getKey());
        }

    }

Response : net.rcarz.jiraclient.JiraException: Failed to retrieve issue Metadata
401 Unauthorized: {"servlet":"Stapler","message":"Invalid password/token for user: *******","url":"/rest/api/latest/issue/createMeta","status":"401"}

Scenario 2 : 
------------

public static String invokePostMethod() throws ClientHandlerException,AuthenticationException,IOException {
        String username = "*******";
        String password = "*******";
        Client client = Client.create();
        WebResource webResource = client.resource("http://localhost:8080/rest/api/2/issue");

        String data = "{\n" +
                "    \"fields\": {\n" +
                "        \"project\": {\n" +
                "           \"key\":\"QQQ\"\n" +
                "        },\n" +
                "        \"summary\": \"creating Bug QQQ project\",\n" +
                "         \"description\": \"Exception three\",\n" +
                "        \"issuetype\": {\n" +
                "            \"name\":\"Bug\"\n" +
                "        }\n" +
                "    }\n" +
                "}";

        String auth = new String(Base64.encode(username + ":" + 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);
    }

Response: Exception caught - Invalid Username or Password

解决方法

找到解决方案:我的坏我很傻检查以下条件 看起来两个服务器运行在同一个端口 检查端口中运行了多少服务的命令:sudo lsof -i:8080 杀死端口的命令:kill -9

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...