繁体   English   中英

如何使用Java解决Rally Rest api中的javax.net.ssl.SSLPeerUnverifiedException:对等体未通过身份验证的异常?

[英]How to solve javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated Exception in Rally Rest api using java?

这是我的代码。 我想使用QueryResponse从Rally Api获取数据。 但是它显示javax.net.ssl.SSLPeerUnverifiedException:对等端未通过身份验证异常对等端未通过身份验证。 我正在尝试使用此Java工具包来测试Rally的webservice api。 我们有一个内部的Rally设置。 我的代码如下所示:

    public static void main(String[] args) throws URISyntaxException 
    {
        String projectRef = "/project/123";
        RallyRestApi restpoint = new RallyRestApi(new URI("http://rally1.rallydev.com"), "_api key");   


        // i have added following section because which is given as a solution for above exception. but then also it is giving me javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated exception
        HttpClient client = restpoint.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));  

        }catch (Exception e) 
        {             
            System.out.println(e);        

        }
        try {
            String version = restpoint.getWsapiVersion();
            System.out.println("version : " + version);
            QueryRequest defects = new QueryRequest("hierarchicalrequirement");

            defects.setFetch(new Fetch("FormattedID","Owner", "Name", "State", "Iteration", "Project", "Defect", "ScheduleState", "PlanEstimate"));
            defects.setOrder("FormattedID ASC"); 
            defects.setProject(projectRef);
            defects.setQueryFilter(
                    new QueryFilter("Iteration.StartDate", ">=", "2017-10-01"));
            //Return up to 5, 1 per page
            defects.setPageSize(1);
            defects.setLimit(10);

            QueryResponse queryResponse = restpoint.query(defects); //here i am getting above exception

 //following code is printing the JSON data
            if (queryResponse.wasSuccessful()) {
                System.out.println(String.format("\nTotal results: %d", queryResponse.getTotalResultCount()));

                for (JsonElement result : queryResponse.getResults()) {
                    JsonObject defect = result.getAsJsonObject();
                    JsonObject project = defect.getAsJsonObject("Project");
                    JsonObject itr = defect.getAsJsonObject("Iteration");
                    JsonObject def = defect.getAsJsonObject("Defect");
                    //System.out.println(defect.toString());
                    System.out.println(String.format("User Story ID: %-10s \nName Of Story: %-30s: \nOwner: %-10s \nProject: %-15s \nStatus: %s",
                            defect.get("FormattedID").getAsString(),
                            defect.get("Name").getAsString(),
                            defect.get("Owner").getAsJsonObject().getAsJsonObject().get("_refObjectName"),
                            project.get("Name").getAsString(),
                            defect.get("ScheduleState").getAsString()
                            ));
                    System.out.println();System.out.println();



                }
            } else {
                System.err.println("The following errors occurred: ");
                for (String err : queryResponse.getErrors()) {
                    System.err.println("\t" + err);
                }
            }

        } catch (IOException e) {

            e.printStackTrace();
        } finally {
            try {
                restpoint.close();  //closing rally Api
            } catch (IOException e) {
                e.printStackTrace();
            }
        }   




        }

请参阅类似的帖子, 同行未通过身份验证-Rally javatoolkit错误

特别是张贴者提到添加代理配置的部分解决了该问题。

希望有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM