集会休息 api java 工具包 sslpeerunverifiedexception:对等方未通过身份验证 [英] rally rest api java toolkit sslpeerunverifiedexception : peer not authenticated

查看:43
本文介绍了集会休息 api java 工具包 sslpeerunverifiedexception:对等方未通过身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此工具包来测试 Rally 的网络服务 api.我们有一个 Rally 的内部设置.我的代码如下所示:

I am trying to use this toolkit to test Rally's webservice api. We have an internal setup of Rally. My code looks like this:

    RallyRestApi restApi = new RallyRestApi (new URI("https://rally"), "userName", "password");
    restApi.setApplicationName("Test");
    restApi.setWsapiVersion(wsapiVersion);

    String workspaceRef = new String("/workspace/11457676");
    String projectRef = new String("/project/11457760");

    String storyFormattedID = "US576";

    QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement");
    storyRequest.setFetch(new Fetch("FormattedID","Name","Owner"));
    storyRequest.setQueryFilter(new QueryFilter("FormattedID", "=", storyFormattedID));
    storyRequest.setWorkspace(workspaceRef);
    storyRequest.setProject(projectRef);
    QueryResponse storyQueryResponse = restApi.query(storyRequest);
    ....

...."之前的激光行生成异常:javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated.当我在浏览器上手动访问这样的网络服务时工作正常,但我注意到有证书错误:"https://rally/slm/webservice/1.29/defect/10509982"

The lase line before "...." generate a exception: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated. When I manually access the webservice like this on browser works fine except I noticed there is Certificate Error: "https://rally/slm/webservice/1.29/defect/10509982"

有人有这方面的经验吗?谢谢.

Does anyone have experience with this? Thanks.

推荐答案

开始2.1版本的jar工具包允许访问其下的HTTPClient,我们可以告诉HTTPClient忽略无效的证书链并容忍自签名证书为了解决SSLPeerUnverifiedException: peer not authenticated 异常

Starting with 2.1 version of the jar the toolkit allows access to the HTTPClient under it, and we can tell HTTPClient to ignore invalid certificate chains and tolerate self-singed certificates in order to workaround SSLPeerUnverifiedException: peer not authenticated exception

当我们实例化 RallyRestApi 时:

When we instantiate RallyRestApi:

String host = "https://rally1.rallydev.com";
String apiKey = "_abc123";
RallyRestApi restApi = new RallyRestApi(new URI(host),apiKey);
restApi.setProxy(new URI("http://myproxy.mycompany.com"), "MyProxyUsername", "MyProxyPassword");

我们可以使用 getClient() 访问 HttpClient

we may access HttpClient with getClient()

这是一个完整的代码示例:

Here is a full code example:

import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.client.HttpClient;
import com.rallydev.rest.request.GetRequest;
import com.rallydev.rest.response.GetResponse;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.conn.scheme.Scheme;


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");  //SET PROXY SETTINS 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"; //USE VALID WORKSPACE OID 
            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 java 工具包 sslpeerunverifiedexception:对等方未通过身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆