2013-06-04 8 views
5

के प्रॉक्सी कॉन्फ़िगरेशन मैं JGit में क्लोन आदेश का उपयोग रेपो क्लोन करने में सक्षम हूँJGit कोड

रेपो है http और निश्चित रूप से यह क्लोन करने के लिए जब मैं प्रॉक्सी

पीछे कर रहा हूँ

तुम मुझे कोड नमूना इसमें सहायता कर सके नाकाम रहने है जावा

धन्यवाद में प्रॉक्सी के साथ जेजीआईटी को कॉन्फ़िगर करने के लिए!

+2

क्या आपने JVM स्तर पर HTTP प्रॉक्सी सेट करने के शास्त्रीय तरीके का उपयोग करने का प्रयास किया है? – fge

+0

इस प्रश्न में उल्लेख के रूप में, मुझे इसे कोड में सेट करने की आवश्यकता है ... –

+1

प्रश्न वास्तव में था अगर आपने मानक तरीके का उपयोग किया तो यह काम करता था। आपका प्रश्न वास्तव में नहीं बताता है। – fge

उत्तर

8

जेजीआईटी एचटीपी कनेक्शन के लिए मानक ProxySelector तंत्र का उपयोग करता है। आज के रूप में, ढांचे द्वारा उपयोग किए जाने वाले क्षेत्र 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() {...}); 
संबंधित मुद्दे