public static InputStream getInputStream(URL url) throws IOException { final ProxyConfiguration p = get(); if (p == null) return new RetryableHttpStream(url); Proxy proxy = p.createProxy(url.getHost()); InputStream is = new RetryableHttpStream(url, proxy); if (p.getUserName() != null) { // Add an authenticator which provides the credentials for proxy authentication Authenticator.setDefault(p.authenticator); p.jenkins48775workaround(proxy, url); } return is; }
/** * This method should be used wherever {@link URL#openConnection()} to internet URLs is invoked directly. */ public static URLConnection open(URL url) throws IOException { final ProxyConfiguration p = get(); URLConnection con; if(p==null) { con = url.openConnection(); } else { Proxy proxy = p.createProxy(url.getHost()); con = url.openConnection(proxy); if(p.getUserName()!=null) { // Add an authenticator which provides the credentials for proxy authentication Authenticator.setDefault(p.authenticator); p.jenkins48775workaround(proxy, url); } } if(DEFAULT_CONNECT_TIMEOUT_MILLIS > 0) { con.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MILLIS); } if (JenkinsJVM.isJenkinsJVM()) { // this code may run on a slave decorate(con); } return con; }
public static InputStream getInputStream(URL url) throws IOException { final ProxyConfiguration p = get(); if (p == null) return new RetryableHttpStream(url); InputStream is = new RetryableHttpStream(url, p.createProxy(url.getHost())); if (p.getUserName() != null) { // Add an authenticator which provides the credentials for proxy authentication Authenticator.setDefault(new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { if (getRequestorType() != RequestorType.PROXY) { return null; } return new PasswordAuthentication(p.getUserName(), p.getPassword().toCharArray()); } }); } return is; }
final ProxyConfiguration p = get();