Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit » JGit HTTPS cloning is not working(JGit HTTPS cloning is not working)
JGit HTTPS cloning is not working [message #1176232] Fri, 08 November 2013 07:50 Go to next message
kaleeswaran S is currently offline kaleeswaran SFriend
Messages: 6
Registered: September 2012
Junior Member
I am having the Geritt GitHub Url : HTTPS -> ://mycompany.com/gerrit/p/my-services.git

I cloned via terminal it is working fine : git clone HTTPS -> ://mycompany.com/gerrit/p/my-services.git.

When I use the java code to clone using JGit , It is throwing error like "UnknownHostException",

I am wondering when I clone in terminal it is working fine, But When I try it with JGit , it is throwing error ? Why it is not recognizing that domain on JGit ?

Error log is,

org.eclipse.jgit.api.errors.TransportException: https -> ://mycompany.com/gerrit/p/my-services.git: cannot open git-upload-pack
        at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:137)
        at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:178)
        at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:125)
        at com.test.AppTest.importGit(AppTest.java:128)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:115)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
        at $Proxy0.invoke(Unknown Source)
        at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
        at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
Caused by: org.eclipse.jgit.errors.TransportException: https -> ://mycompany.com/gerrit/p/my-services.git: cannot open git-upload-pack
        at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:499)
        at org.eclipse.jgit.transport.TransportHttp.openFetch(TransportHttp.java:308)
        at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136)
        at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122)
        at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1105)
        at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:128)
        ... 34 more
Caused by: java.net.UnknownHostException: mycompany.com
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:195)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:529)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:570)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:158)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:411)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:525)
        at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:272)
        at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:966)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1195)
        at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:318)
        at org.eclipse.jgit.util.HttpSupport.response(HttpSupport.java:167)
        at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:462)
        ... 39 more


My code is,

// I am using the below code to trust all the https urls,

// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { 
    new X509TrustManager() {     
        public java.security.cert.X509Certificate[] getAcceptedIssuers() { 
            return null;
        } 
        public void checkClientTrusted( 
            java.security.cert.X509Certificate[] certs, String authType) {
            } 
        public void checkServerTrusted( 
            java.security.cert.X509Certificate[] certs, String authType) {
        }
    } 
}; 

// Install the all-trusting trust manager
try {
    SSLContext sc = SSLContext.getInstance("SSL"); 
    sc.init(null, trustAllCerts, new java.security.SecureRandom()); 
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (GeneralSecurityException e) {
	
}


String url = "https -> ://mycompany.com/gerrit/p/my-services.git";
String username = "username";
String password = "password";
String checkoutLocation = "/Users/testing";
String branch = "my-services-sample-test";

UsernamePasswordCredentialsProvider userCredential = new UsernamePasswordCredentialsProvider(username, password);
Git r = Git.cloneRepository().setDirectory(new File(checkoutLocation + "/clonned"))
.setCredentialsProvider(userCredential)
.setURI(url)
.setProgressMonitor(new TextProgressMonitor())
.setBranch(branch)
.call();
System.out.println("Clonning @ " + checkoutLocation);
r.getRepository().close();  


I am usign the dependency

<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>3.0.0.201306101825-r</version>
<scope>compile</scope>
</dependency>

Why it is not recognizing that domain on JGit ?
Re: JGit HTTPS cloning is not working [message #1176644 is a reply to message #1176232] Fri, 08 November 2013 13:15 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 612
Registered: July 2009
Senior Member
- maybe you need some proxy configuration ?
- instead of using your own TrustManager you could configure http.sslVerify = false in order to instruct jgit to trust all certs
- you are not using the latest jgit release, though 3.0 should work
Re: JGit HTTPS cloning is not working [message #1176680 is a reply to message #1176644] Fri, 08 November 2013 13:38 Go to previous messageGo to next message
kaleeswaran S is currently offline kaleeswaran SFriend
Messages: 6
Registered: September 2012
Junior Member
Hi Matthias Sohn,

I specified the http.sslVerify = false in Bash profile. May I know the what kind of configuration that I have to specify ? . Code level idea is highly appreciated.
Re: JGit HTTPS cloning is not working [message #1176786 is a reply to message #1176680] Fri, 08 November 2013 14:58 Go to previous messageGo to next message
kaleeswaran S is currently offline kaleeswaran SFriend
Messages: 6
Registered: September 2012
Junior Member
Hi Matthias Sohn,

Your suggestion guided me to find the solution. I need to set the proxy configuration in Jgit,

ProxySelector.setDefault(new ProxySelector() {
final ProxySelector delegate = ProxySelector.getDefault();

@Override
public List<Proxy> select(URI uri) {
// Filter the URIs to be proxied

if (uri.toString().contains("github")
&& uri.toString().contains("https")) {
return Arrays.asList(new Proxy(Type.HTTP, InetSocketAddress
.createUnresolved("localhost", 3128)));
}
if (uri.toString().contains("github")
&& uri.toString().contains("http")) {
return Arrays.asList(new Proxy(Type.HTTP, InetSocketAddress
.createUnresolved("localhost", 3129)));
}
// revert to the default behaviour
return delegate == null ? Arrays.asList(Proxy.NO_PROXY)
: delegate.select(uri);
}

@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
if (uri == null || sa == null || ioe == null) {
throw new IllegalArgumentException(
"Arguments can't be null.");
}
}
});

Ref: http://stackoverflow.com/questions/16921374/jgit-proxy-configuration-in-code
Re: JGit HTTPS cloning is not working [message #1176865 is a reply to message #1176786] Fri, 08 November 2013 16:02 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 612
Registered: July 2009
Senior Member
JGit doesn't look into the bash profile, it loads the git configuration from the usual git config files [1]:
* system level located at <native git installation path>/etc/gitconfig
* user level located at ~/.gitconfig
* repository level located at /path/to/repo/.git/config

In addition you can tweak the configuration programmatically using class FileBasedConfig.

[1] http://git-scm.com/book/en/Customizing-Git-Git-Configuration
Re: JGit HTTPS cloning is not working [message #1457639 is a reply to message #1176232] Fri, 31 October 2014 14:45 Go to previous messageGo to next message
Johnatan Oliveira is currently offline Johnatan OliveiraFriend
Messages: 1
Registered: October 2014
Junior Member
Hello, I come to ask for help in a research project I am working. My algorithm makes analysis of refactoring between versions of projects
software written in java language. For that I need to test the tool with several projects. My choice was between test versions of projects
exposed on github. For this, we developed an algorithm communicates with the api git. Use the egit and JGit, but currently the algorithm
captures only link by .git download link. How could I do to download several projects going .git? Example of my code:

String urlGit="github.com/centic9/jgit-cookbook.git";
File localPath = File.createTempFile("GitRepository", "", new File("C:/GitHub"));
downloadgit.specificDownload(localPath, urlGit);
..............

protected void specificDownload(File path, String url) throws Exception {
Git.cloneRepository()
.setDirectory(path)
.setURI(url)
.setBare(false)
.setCloneAllBranches(true)
.call();
}
Re: JGit HTTPS cloning is not working [message #1461306 is a reply to message #1457639] Tue, 04 November 2014 12:26 Go to previous message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 612
Registered: July 2009
Senior Member
don't highjack another thread for an unrelated question
Previous Topic:Use git repository directly from remote server
Next Topic:Amazon S3 Object Interaction
Goto Forum:
  


Current Time: Mon Dec 22 23:44:19 GMT 2014

Powered by FUDForum. Page generated in 0.01849 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software