Skip to content
Permalink
Browse files

[FIXED JENKINS-10634] JDK downloader now uses Jenkins proxy settings

Cherry-picked-from: fa00cd2
  • Loading branch information
kohsuke committed Oct 21, 2011
1 parent cfa6eab commit 50dd2f26bced3bc22e09ec39c31ebfacb6627134
Showing with 20 additions and 0 deletions.
  1. +20 −0 core/src/main/java/hudson/tools/JDKInstaller.java
@@ -23,6 +23,9 @@
*/
package hudson.tools;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider;
import com.gargoylesoftware.htmlunit.ProxyConfig;
import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
@@ -31,6 +34,7 @@
import hudson.AbortException;
import hudson.Extension;
import hudson.FilePath;
import hudson.ProxyConfiguration;
import hudson.Launcher;
import hudson.Launcher.ProcStarter;
import hudson.Util;
@@ -46,6 +50,7 @@
import hudson.util.Secret;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.auth.CredentialsProvider;
import org.apache.commons.io.IOUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.HttpResponse;
@@ -345,6 +350,21 @@ public URL locate(TaskListener log, Platform platform, CPU cpu) throws IOExcepti
URL src = new URL(primary.filepath);

WebClient wc = new WebClient();
// honor jenkins proxy settings in WebClient
Jenkins h = Jenkins.getInstance();
ProxyConfiguration jpc = h!=null ? h.proxy : null;
if(jpc != null) {
ProxyConfig pc = new ProxyConfig();
pc.setProxyHost(jpc.name);
pc.setProxyPort(jpc.port);
wc.setProxyConfig(pc);
if(jpc.getUserName() != null) {
DefaultCredentialsProvider cp = new DefaultCredentialsProvider();
cp.addCredentials(jpc.getUserName(), jpc.getPassword(), jpc.name, jpc.port, null);
wc.setCredentialsProvider(cp);
}
}

wc.setJavaScriptEnabled(false);
wc.setCssEnabled(false);
Page page = wc.getPage(src);

0 comments on commit 50dd2f2

Please sign in to comment.
You can’t perform that action at this time.