使用Java将Bitbucket存储库克隆到本地目录?

时间:2018-06-27 11:05:56

标签: java bitbucket clone

我正在尝试通过Java代码将一个Bitbucket存储库克隆到我的本地目录中。但是,原因如下:javax.net.ssl.SSLHandshakeException:java.security.cert.CertificateException:找不到与cedt-gct-bitbucket匹配的主题替代DNS名称。

下面是相同的代码。

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.CloneCommand;
    import java.io.File;
import java.nio.file.Paths;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class Checkout {

    private TrustManager[] trustAllCerts;
    private SSLContext sslContext;


    public void setUp() throws Exception {
        trustAllCerts = new TrustManager[]{
          new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
              return new X509Certificate[0];
            }
            public void checkClientTrusted(
                java.security.cert.X509Certificate[] certs, String authType) {
            }
            public void checkServerTrusted(
                java.security.cert.X509Certificate[] certs, String authType) {
              if (certs.length != 1 || !certs[0].getIssuerX500Principal().getName()
                  .contains("CN=localhost")) {
                throw new SecurityException("Invalid certificate");
              }
            }
          }
        };
        sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustAllCerts, new SecureRandom());
        }

    public static void main(String[] args) {

        Checkout co = new Checkout();
        try {
            co.setUp();
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        String repoUrl = "<------BITBUCKET REPOSITORY----->; //link for bit repo
        String cloneDirectoryPath = "C:\\Users\\username\\TestFolder"; 
        try {
            System.out.println("Cloning "+repoUrl+" into "+repoUrl);
            Git.cloneRepository()
                .setURI(repoUrl)
                .setDirectory(Paths.get(cloneDirectoryPath).toFile())
                .call();
            System.out.println("Completed Cloning");
        } catch (GitAPIException e) {
            System.out.println("Exception occurred while cloning repo");
            e.printStackTrace();
        }
        }
    }

有什么建议吗?

0 个答案:

没有答案