你写道,你想找到一种方法来允许所有的证书,并使用Rally Rest Toolkit for Java的HttpClient。以下是您如何从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();
}
}
}
是否有原因导致您无法使用Rally Rest Toolkit for Java? https://github.com/RallyTools/RallyRestToolkitForJava –
我正在使用Rally Rest Toolkit for java。这个问题出现在api的查询函数中。在此阶段获取此SSLhandshakeException。我可以通过在可信密钥库中添加证书来临时解决此问题,但有效性设置为小范围。 – Tontodoin