2017-04-24 67 views
0

我一直在使用拉力賽javatoolkit一段時間添加測試用例,測試結果等沒有任何錯誤。但突然間,它開始拋出錯誤爲 「javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated」。我已經提到了頁面「rally rest api java toolkit sslpeerunverifiedexception : peer not authenticated」,rally rest api java toolkit sslpeerunverifiedexception : peer not authenticated但他們沒有幫助我。有人能幫我解決我做錯了什麼。另外如果我需要下載證書,請幫助我的Windows系統。提前致謝。我的代碼如下:peer not authenticated - 拉力賽javatoolkit錯誤

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(); 
     } 
    } 
} 

還增加了問題,我發現了一個不同的錯誤,當我改變了口,從443到8443,我得到「java.io.IOException: HTTP/1.1 522 Origin Connection Time-out」當我使用8443

回答

0

對於一些當我用正確的輸入取消註釋行//restApi.setProxy(new URI("http://myproxy.mycompany.com"), "MyProxyUsername", "MyProxyPassword");的原因時,錯誤消失。 對於所有那些誰需要輸入,請把下面的:

restApi.setProxy(new URI("http://rally1.rallydev.com"), "[email protected]", "rallypassword"); 

因此工作代碼如下:

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.scheme.Scheme; 
import org.apache.http.conn.ssl.SSLSocketFactory; 
import org.apache.http.conn.ssl.TrustStrategy; 
import com.rallydev.rest.RallyRestApi; 
import com.rallydev.rest.client.HttpClient; 
import com.rallydev.rest.request.GetRequest; 
import com.rallydev.rest.response.GetResponse; 

public class ConnnectionTestWithHTTPClient { 

    public static void main(String[] args) throws URISyntaxException, IOException { 


     String host = "https://rally1.rallydev.com"; 
     String apiKey = "_apikey"; 
     String applicationName = "Connnection Test With HTTPClient"; 
     RallyRestApi restApi = new RallyRestApi(new URI(host),apiKey); 
     restApi.setApplicationName(applicationName); 
     restApi.setProxy(new URI("http://rally1.rallydev.com"), "[email protected]", "rallypassword"); //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/1234"; 
      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(); 
     } 
    } 
}