【问题标题】:SSLHandshakeException with Rally rest apiSSLHandshakeException 与 Rally rest api
【发布时间】:2016-04-25 21:37:45
【问题描述】:

api中的查询功能失败,出现以下异常:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

为了解决这个异常,我手动下载了证书并将其导入到 cacerts,一切正常。但是该证书的有效期已设置为几天,使得该解决方案不可行。

出于测试目的,我创建了一个信任策略来允许所有证书,但我没有找到将它与 Rest Api 集成的方法。我正在使用 HttpClient 4.4。

我该如何解决这个问题?谢谢。

【问题讨论】:

  • 您是否有不能使用 Rally Rest Toolkit for Java 的原因? github.com/RallyTools/RallyRestToolkitForJava
  • 我正在使用 Rally Rest Toolkit for java。问题出现在api的查询功能中。在此阶段获取此 SSLhandshakeException。我可以通过在受信任的密钥库中添加证书来临时解决此问题,但有效性设置为一个小范围。

标签: java ssl rally apache-httpclient-4.x sslhandshakeexception


【解决方案1】:

您写道,您希望找到一种方法来允许所有证书,并将 HttpClient 与 Rally Rest Toolkit for Java 一起使用。以下是从 restApi 访问 HttpClient 的方法:

HttpClient client = restApi.getClient();

这是一个信任所有证书的示例,例如自签名证书:

public class ConnnectionTestWithHTTPClient {

    public static void main(String[] args) throws URISyntaxException, IOException {


        String host = "https://rally1.rallydev.com";
        String apiKey = "_abc123";
        String applicationName = "Connnection Test With HTTPClient";
        RallyRestApi restApi = new RallyRestApi(new URI(host),apiKey);
        restApi.setApplicationName(applicationName); 
        //restApi.setProxy(new URI("http://myproxy.mycompany.com"), "MyProxyUsername", "MyProxyPassword");  //YOUR PROXY SETTINGS HERE
        HttpClient client = restApi.getClient();
        try {
            SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy() {
                public boolean isTrusted(X509Certificate[] certificate, String authType)
                    throws CertificateException {
                    //trust all certs
                    return true;
                }
            }, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            client.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, sf));

            String workspaceRef = "/workspace/12345"; 
            GetRequest getRequest = new GetRequest(workspaceRef);
            GetResponse getResponse = restApi.get(getRequest);
            System.out.println(getResponse.getObject());
        } catch (Exception e) {
            System.out.println(e);
        } finally {
            restApi.close();
        }   
    } 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-29
    相关资源
    最近更新 更多