Hi,
Im trying to clone a git repo using JGit.Following is the code snippet. I
have customized the JVM default proxy selector by following a forum [1]
<http://stackoverflow.com/questions/19854053/jgit-https-cloning-is-not-working>
because it is said " JGit uses the standard ProxySelector mechanism for the
Http connection. As of Today, the field
org.eclipse.jgit.transport.TransportHttp.proxySelector used by the
framework, is not overridable. It is configurable, though"
UsernamePasswordCredentialsProvider credentialsProvider = new
UsernamePasswordCredentialsProvider(gitUser, gitPassword);
ProxySelector.setDefault(new GitBlitProxySelector());
Git.cloneRepository().setCredentialsProvider(credentialsProvider).setURI(remotePath)
.setDirectory(new File(localPath)).call();
public class GitBlitProxySelector extends ProxySelector {
final ProxySelector delegate = ProxySelector.getDefault();
@Override
public List<Proxy> select(URI uri) {
// Filter the URIs to be proxied
if (uri.toString().contains("git")
&& uri.toString().contains("https")) {
return Arrays.asList(new Proxy(Proxy.Type.HTTP,
InetSocketAddress
.createUnresolved("localhost", 3128)));
}
if (uri.toString().contains("git")
&& uri.toString().contains("http")) {
return Arrays.asList(new Proxy(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.");
}
}
}
Now i get a Connection refused Exception, the stack trace is given below.
org.eclipse.jgit.api.errors.TransportException:
https://git.cloudstaging.wso2.com/git/aaishara/samplejavaapp.git: cannot
open git-upload-pack
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:139)
at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:178)
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:125)
at
org.wso2.cloud.heartbeat.monitor.modules.gitblit.GitCloneTest.gitClone(GitCloneTest.java:54)
at
org.wso2.cloud.heartbeat.monitor.modules.gitblit.GitCloneTest.execute(GitCloneTest.java:36)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
Caused by: org.eclipse.jgit.errors.TransportException:
https://git.cloudstaging.wso2.com/git/aaishara/samplejavaapp.git: cannot
open git-upload-pack
at
org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:524)Unable
at
org.eclipse.jgit.transport.TransportHttp.openFetch(TransportHttp.java:309)
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:1115)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:130)
... 6 more
Caused by: java.net.ConnectException: Connection refused
git.cloudstaging.wso2.com
at org.eclipse.jgit.util.HttpSupport.response(HttpSupport.java:175)
at
org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:475)
... 11 more
Does anyone has an idea of how i can get rid from this?
I can clone this repo using command line with the same credentials.
Thanks!
Ishara Cooray
Senior Software Engineer
Mobile : +9477 262 9512
WSO2, Inc. | http://wso2.com/
Lean . Enterprise . Middleware
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev