gpt4 book ai didi

java - 带有 Rally rest api 的 SSLHandshakeException

转载 作者:太空宇宙 更新时间:2023-11-03 13:24:37 25 4
gpt4 key购买 nike

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。

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

最佳答案

您写道,您希望找到一种允许所有证书的方法,并将 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();
}
}
}

关于java - 带有 Rally rest api 的 SSLHandshakeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36851534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com