5
Q
JGit代碼
A
回答
8
JGit使用標準ProxySelector
機制進行Http連接。 截至今日,該框架使用的字段org.eclipse.jgit.transport.TransportHttp.proxySelector
不可覆蓋。它是可配置的,不過,定製JVM默認代理選擇,如:
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.");
}
}
});
1
在卡羅佩萊格里尼回答的補充,如果你的代理服務器需要一些認證,你應該配置一個Authenticator
,像(基於Authenticated HTTP proxy with Java問題):
Authenticator.setDefault(new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
// If proxy is non authenticated for some URLs, the requested URL is the endpoint (and not the proxy host)
// In this case the authentication should not be the one of proxy ... so return null (and JGit CredentialsProvider will be used)
if (super.getRequestingHost().equals("localhost")) {
return new PasswordAuthentication("foo", "bar".toCharArray());
}
return null;
}
});
ProxySelector.setDefault(new ProxySelector() {...});
相關問題
- 1. JGit FetchCommand
- 2. 獲取從jgit
- 3. Jgit RevWalk.parseCommit()throw MissingObjectException
- 4. JGit克隆庫
- 5. 通過JGit
- 6. MissingObjectException而與JGit
- 7. JGit - ssh connectivity
- 8. JGIT拉NoHeadException
- 9. JGit MergeCommand示例
- 10. JGit PullCommand異常
- 11. 乾淨關機JGit
- 12. JGit獲取文件
- 13. Jgit javadocs在哪裏?
- 14. 淺克隆與JGIT
- 15. JGit:計數對象
- 16. Maven jgit JDWP傳輸錯誤
- 17. 如何在JGit中合併?
- 18. 爲什麼jgit默認
- 19. jGit推動產生異常
- 20. JGit分支結帳問題
- 21. 如何與JGit衝突線
- 22. JGit:簽出遠程分支
- 23. 使用JGit重命名庫
- 24. JGit獲取提交時區
- 25. 使用JGit和CLI git
- 26. JGit fetch()不更新標記
- 27. Jenkins發佈jgit問題
- 28. 你如何安裝JGit?
- 29. JGit合併額外選項
- 30. jGit構造函數錯誤
您是否嘗試過使用在JVM級別設置HTTP代理的經典方法? – fge
在問題中提到,我需要在代碼中進行設置... –
如果使用標準方式,它的工作原理就是如此。你的問題並沒有真正說明。 – fge