声纳客户端org.sonar.wsclient.base.HttpException:错误407

时间:2019-02-04 11:45:47

标签: sonarqube sonarqube-scan

我正在使用声纳客户端API,以便以个性化版本显示代码的味道。但是我在执行时遇到上述错误吗?在我以前获得输出之前。

public class ab{
public static void main(String args[]) {
try {
    String url = "http://127.0.0.1:9001";
    String login = "admin";
    String password = "admin";

    SonarClient client = SonarClient.builder()
              .url(url)
              .login(login)
              .password(password)
              .build();

    IssueQuery query = IssueQuery.create();
    query.rules("Major","Minor","Critical");
    IssueClient issueClient = client.issueClient();
    Issues issues = issueClient.find(query);
    List<Issue> issueList = issues.list();

    for (int i = 0; i < issueList.size(); i++) {
       System.out.println(issueList.get(i).projectKey() + " " +
                          issueList.get(i).componentKey() + " " +
                          issueList.get(i).line() + " " +
                          issueList.get(i).ruleKey() + " " +
                          issueList.get(i).severity() + " " +
                          issueList.get(i).message());
     }
} catch (Exception ex) {
  System.out.println(ex);
}
}

1 个答案:

答案 0 :(得分:0)

当您尝试访问的资源需要代理身份验证时,会抛出

Http Error 407。但是,当您通过 127.0.0.1 访问服务时,表明它是您的本地系统,因此不会出现407错误。尝试将条目添加为您的主机文件(在 YOUR_WINDOWS_FOLDER \ System32 \ drivers \ etc 下)为

127.0.0.1       localhost

或者,您是否尝试过通过localhost通过以下方式访问URL?

  

http://localhost:9001

最后,如果将声纳托管在单独的服务器上,则可以在调用服务之前按如下所示设置代理身份验证。

import java.net.Authenticator;
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.net.Proxy;
.
.
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("PROXY_SERVER", 80));
Authenticator authenticator = new Authenticator() {

    public PasswordAuthentication getPasswordAuthentication() {
        return (new PasswordAuthentication("PROXY_USERNAME", "PROXY_PASSWORD".toCharArray()));
    }
};
Authenticator.setDefault(authenticator);