【问题标题】:Unable to access Sonarqube webservice API无法访问 Sonarqube 网络服务 API
【发布时间】:2016-10-01 20:52:55
【问题描述】:

我正在尝试使用 Sonarqube 网络服务 API。我需要将一些参数连同用户名和密码一起传递给这个 Web 服务 api。

为此,我编写了以下代码 -

HttpClient client = new HttpClient();
        String uri = "http://myUrl.sonar.com";
        client.getState().setCredentials(new AuthScope(uri, 8080, AuthScope.ANY_REALM),
                new UsernamePasswordCredentials("username", "password"));
        GetMethod get = new GetMethod("http://myUrl.sonar.com/api/resources?"
                + "resource=110041&format=json&metrics=ncloc,coverage&verbose=true"
                + "&metrics=sqale_index,sqale_debt_ratio,ncloc,sqale_rating");
        get.setDoAuthentication(true);
        try {
            int status = client.executeMethod(get);
            System.out.println(status + "\n" + get.getResponseBodyAsString());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            get.releaseConnection();
        }

当我从 Eclipse 运行这段代码时,它会返回

401
{"err_code":401,"err_msg":"Unauthorized"}

这有什么可能的原因吗?用户名和密码正确。

【问题讨论】:

  • 权限是否正确?
  • 用户是否拥有项目 110041 的浏览权限?
  • @JulienL.-SonarSourceTeam ,我尝试从声纳网站浏览该项目,它工作正常。我需要检查其他地方吗?
  • 应该不错。那么,您确定您使用的是正确的登录名/密码吗?
  • @JulienL.-SonarSourceTeam 是的..

标签: java web-services sonarqube apache-commons-httpclient sonarqube-web


【解决方案1】:

您应该尝试我们的 API 来查询一些 URL,查看我们 IT 中的一些示例以使用它:

你需要使用 sonar-ws,最新版本在这里可用:http://search.maven.org/#artifactdetails%7Corg.sonarsource.sonarqube%7Csonar-ws%7C5.6%7Cjar

【讨论】:

  • 这两个 url 上的 404s
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-21
  • 2017-04-16
  • 2019-08-04
  • 1970-01-01
  • 2022-08-19
  • 2016-01-01
相关资源
最近更新 更多