SSLHandshakeException 与 Rally 休息 api
SSLHandshakeException with Rally rest api
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();
}
}
}
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();
}
}
}