I am able to clone repo using clone command in JGit
Repo is http and of course it's failing to clone when I am behind proxy
Could you help me with code sample how to configure JGit with proxy in java
thanks!
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, customizing the JVM default proxy selector as in:
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.");
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With