Skip to content

Commit

Permalink
[WIP][DO NOT MERGE][JENKINS-25829] proxy usage from jenkins (#148)
Browse files Browse the repository at this point in the history
* [JENKINS-25829] add support for proxy usage (with basic authz)

Signed-off-by: olivier lamy <olamy@apache.org>

* fix non used import

Signed-off-by: olivier lamy <olamy@apache.org>

* add some unit tests for ApacheAsyncHttpClient

Signed-off-by: olivier lamy <olamy@apache.org>

* reenable coverage as there is now some tests for httpclient

Signed-off-by: olivier lamy <olamy@apache.org>

* remove non used files (should improve coverage ;-) )

Signed-off-by: olivier lamy <olamy@apache.org>
  • Loading branch information
olamy committed May 3, 2018
1 parent abd0928 commit f4d9368
Show file tree
Hide file tree
Showing 9 changed files with 350 additions and 389 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,3 +8,4 @@ bin
.idea/
work
atlassian-ide-plugin.xml
.work/
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -132,7 +132,7 @@
</ignores>
<excludes>
<exclude>hudson/plugins/jira/Messages*.class</exclude>
<exclude>com/atlassian/httpclient/**/*.class</exclude>
<!--exclude>com/atlassian/httpclient/**/*.class</exclude-->
</excludes>
</instrumentation>
</configuration>
Expand Down
@@ -1,9 +1,6 @@
package com.atlassian.httpclient.apache.httpcomponents;

import com.atlassian.event.api.EventPublisher;
import com.atlassian.fugue.Effect;
import com.atlassian.httpclient.apache.httpcomponents.proxy.ProxyConfigFactory;
import com.atlassian.httpclient.apache.httpcomponents.proxy.ProxyCredentialsProvider;
import com.atlassian.httpclient.api.DefaultResponseTransformation;
import com.atlassian.httpclient.api.HttpClient;
import com.atlassian.httpclient.api.HttpStatus;
Expand All @@ -22,11 +19,17 @@
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.base.Throwables;
import hudson.ProxyConfiguration;
import jenkins.model.Jenkins;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpDelete;
Expand All @@ -42,6 +45,7 @@
import org.apache.http.conn.ssl.SSLContextBuilder;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.ProxyAuthenticationStrategy;
import org.apache.http.impl.conn.DefaultSchemePortResolver;
import org.apache.http.impl.conn.SystemDefaultDnsResolver;
Expand Down Expand Up @@ -192,6 +196,24 @@ protected void finalize() throws Throwable
.setUserAgent(getUserAgent(options))
.setDefaultRequestConfig(requestConfig);

ProxyConfiguration proxyConfiguration = Jenkins.getInstance().proxy;
if(proxyConfiguration!=null)
{

clientBuilder.setProxy( new HttpHost( proxyConfiguration.name, proxyConfiguration.port ) );
if(StringUtils.isNotBlank( proxyConfiguration.getUserName()))
{
clientBuilder.setProxyAuthenticationStrategy( ProxyAuthenticationStrategy.INSTANCE );
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials( new AuthScope( proxyConfiguration.name, proxyConfiguration.port),
new UsernamePasswordCredentials(proxyConfiguration.getUserName(),
proxyConfiguration.getPassword()) );
clientBuilder.setDefaultCredentialsProvider( credsProvider );
}
}


/*
ProxyConfigFactory.getProxyHost(options).foreach(new Effect<HttpHost>()
{
@Override
Expand All @@ -209,6 +231,7 @@ public void apply(final ProxyCredentialsProvider proxyCredentialsProvider)
});
}
});
*/

this.nonCachingHttpClient = clientBuilder.build();
this.callbackExecutor = options.getCallbackExecutor();
Expand Down Expand Up @@ -518,7 +541,10 @@ public EventConsumerFunction(EventPublisher eventPublisher)
@Override
public Void apply(Object event)
{
eventPublisher.publish(event);
if (eventPublisher != null)
{
eventPublisher.publish( event );
}
return null;
}
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit f4d9368

Please sign in to comment.