Skip to content

Commit

Permalink
[FIXED JENKINS-10634] JDK downloader now uses Jenkins proxy settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Bradley authored and kohsuke committed Sep 18, 2011
1 parent beb1666 commit fa00cd2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -55,6 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>
JDK auto-installation does not respect proxy settings
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-10634">issue 10634</a>)
<li class=bug>
Tools download does not respect proxy settings
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-5271">issue 5271</a>)
Expand Down
20 changes: 20 additions & 0 deletions core/src/main/java/hudson/tools/JDKInstaller.java
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -45,6 +49,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;
Expand Down Expand Up @@ -344,6 +349,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);
Expand Down

1 comment on commit fa00cd2

@tom-canova
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, it is still not respecting the proxy configuration
I'm using Jenkins ver. 1.432-SNAPSHOT (private-09/19/2011 18:09 GMT-jenkins)

We don't use a username/password for our proxy. If jsp.getUsername() returned "", that would cause a problem for us.

Also - installation of plugins was not respecting the proxy for us.

Here's the console output:
Started by user anonymous Installing JDK jdk-6u26-oth-JPR Downloading JDK from http://download.oracle.com/otn/java/jdk/6u26-b03//jdk-6u26-windows-i586.exe
ERROR: Failed to parse POMs
java.io.IOException: GET http://download.oracle.com/otn/java/jdk/6u26-b03//jdk-6u26-windows-i586.exe failed at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:130) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1456) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1387) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:328) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:389) at hudson.tools.JDKInstaller.locate(JDKInstaller.java:369) at hudson.tools.JDKInstaller.performInstallation(JDKInstaller.java:125) at hudson.tools.InstallerTranslator.getToolHome(InstallerTranslator.java:61) at hudson.tools.ToolLocationNodeProperty.getToolHome(ToolLocationNodeProperty.java:107) at hudson.tools.ToolInstallation.translateFor(ToolInstallation.java:150) at hudson.model.JDK.forNode(JDK.java:112) at hudson.model.AbstractBuild.getEnvironment(AbstractBuild.java:821) at hudson.maven.AbstractMavenBuild.getEnvironment(AbstractMavenBuild.java:59) at hudson.maven.MavenModuleSetBuild.getEnvironment(MavenModuleSetBuild.java:160) at hudson.maven.MavenModuleSetBuild$RunnerImpl.doRun(MavenModuleSetBuild.java:564) at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:459) at hudson.model.Run.run(Run.java:1389) at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:474) at hudson.model.ResourceController.execute(ResourceController.java:88) at hudson.model.Executor.run(Executor.java:230) Caused by: java.net.ConnectException: Connection timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(Unknown Source) at java.net.PlainSocketImpl.connectToAddress(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.(Unknown Source) at java.net.Socket.(Unknown Source) at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80) at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:122) at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707) at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361) at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387) at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346) at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:101) ... 19 more Finished: FAILURE

and here's the error from trying to install a plugin

Active Directory plugin
Failure -

java.io.IOException: Server returned HTTP response code: 502 for URL: http://updates.jenkins-ci.org/download/plugins/active-directory/1.19/active-directory.hpi
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at hudson.model.UpdateCenter$UpdateCenterConfiguration.download(UpdateCenter.java:607)
at hudson.model.UpdateCenter$DownloadJob._run(UpdateCenter.java:950)
at hudson.model.UpdateCenter$InstallationJob._run(UpdateCenter.java:1058)
at hudson.model.UpdateCenter$DownloadJob.run(UpdateCenter.java:932)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: Server returned HTTP response code: 502 for URL: http://updates.jenkins-ci.org/download/plugins/active-directory/1.19/active-directory.hpi
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(Unknown Source)
at java.net.URLConnection.getHeaderFieldInt(Unknown Source)
at java.net.URLConnection.getContentLength(Unknown Source)
at hudson.model.UpdateCenter$UpdateCenterConfiguration.download(UpdateCenter.java:606)
... 9 more

Please sign in to comment.