List of usage examples for org.eclipse.jgit.util CachedAuthenticator add
public static void add(CachedAuthentication ca)
From source file:kr.re.ec.grigit.util.PgmMain.java
License:Eclipse Distribution License
/** * Configure the JRE's standard HTTP based on <code>http_proxy</code>. * <p>/*from w ww.j a v a 2 s . c om*/ * The popular libcurl library honors the <code>http_proxy</code> * environment variable as a means of specifying an HTTP proxy for requests * made behind a firewall. This is not natively recognized by the JRE, so * this method can be used by command line utilities to configure the JRE * before the first request is sent. * * @throws MalformedURLException * the value in <code>http_proxy</code> is unsupportable. */ private static void configureHttpProxy() throws MalformedURLException { final String s = System.getenv("http_proxy"); //$NON-NLS-1$ if (s == null || s.equals("")) //$NON-NLS-1$ return; final URL u = new URL((s.indexOf("://") == -1) ? "http://" + s : s); //$NON-NLS-1$ //$NON-NLS-2$ if (!"http".equals(u.getProtocol())) //$NON-NLS-1$ throw new MalformedURLException( MessageFormat.format(CLIText.get().invalidHttpProxyOnlyHttpSupported, s)); final String proxyHost = u.getHost(); final int proxyPort = u.getPort(); System.setProperty("http.proxyHost", proxyHost); //$NON-NLS-1$ if (proxyPort > 0) System.setProperty("http.proxyPort", String.valueOf(proxyPort)); //$NON-NLS-1$ final String userpass = u.getUserInfo(); if (userpass != null && userpass.contains(":")) { //$NON-NLS-1$ final int c = userpass.indexOf(':'); final String user = userpass.substring(0, c); final String pass = userpass.substring(c + 1); CachedAuthenticator.add(new CachedAuthenticator.CachedAuthentication(proxyHost, proxyPort, user, pass)); } }