Skip to content

Commit

Permalink
Merge pull request #584 from jianghaolu/master
Browse files Browse the repository at this point in the history
Support proxy for Apache clients
  • Loading branch information
jianghaolu committed Jan 26, 2016
2 parents 87aaf3f + 4f21d73 commit 90b7de0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
11 changes: 11 additions & 0 deletions ChangeLog.txt
@@ -1,3 +1,14 @@
2016.1.26 Version 0.9.2
* Fix HTTP Proxy for Apache HTTP Client in Service Clients
* Key Vault: Fix KeyVaultKey to not attempt to load RSA Private Key

2016.1.8 Version 0.9.1
* Support HTTP Proxy
* Fix token expiration issue #557
* Service Bus: Add missing attributes: partitionKey, viaPartitionKey
* Traffic Manager: Update API version, add MinChildEndpoints for NestedEndpoints
* Media: Add support for Widevine (DRM) dynamic encryption

2015.10.21 Version 0.9.0
* New Azure Resource Manager Storage Management library
* Fix a few bugs
Expand Down
Expand Up @@ -57,6 +57,12 @@ public class Configuration {
*/
public static final String PROPERTY_HTTP_PROXY_PORT = "http.proxyPort";

/**
* Property name to control which scheme the Rest client uses to make a connection to the Proxy server. Default value
* is 'http'.
*/
public static final String PROPERTY_HTTP_PROXY_SCHEME = "http.proxyScheme";

/**
* The configuration properties.
*/
Expand Down
Expand Up @@ -50,10 +50,7 @@ public CloseableHttpClient getHttpClient() {
String proxyHost = System.getProperty("http.proxyHost");
String proxyPort = System.getProperty("http.proxyPort");
if ((proxyHost != null) && (proxyPort != null)) {
HttpHost proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort));
if (proxy != null) {
httpClientBuilder.setProxy(proxy);
}
httpClientBuilder.setProxy(new HttpHost(proxyHost, Integer.parseInt(proxyPort)));
}

this.httpClient = httpClientBuilder.build();
Expand Down
Expand Up @@ -18,6 +18,7 @@

package com.microsoft.windowsazure.core.pipeline.apache;

import com.microsoft.windowsazure.Configuration;
import com.microsoft.windowsazure.core.pipeline.filter.ServiceRequestFilter;
import org.apache.http.HttpHost;
import org.apache.http.client.HttpRequestRetryHandler;
Expand All @@ -26,7 +27,6 @@
import org.apache.http.impl.client.DefaultRedirectStrategy;
import org.apache.http.impl.client.HttpClientBuilder;

import java.util.ArrayList;
import java.util.Map;

public class ApacheConfigSettings {
Expand Down Expand Up @@ -107,6 +107,19 @@ public HttpClientBuilder applyConfig(HttpClientBuilder httpClientBuilder) {
httpClientBuilder.addInterceptorFirst(new FilterInterceptor(filter));
}

if (properties.containsKey(profile + Configuration.PROPERTY_HTTP_PROXY_HOST) &&
properties.containsKey(profile + Configuration.PROPERTY_HTTP_PROXY_PORT)) {
String proxyHost = (String) properties.get(profile + Configuration.PROPERTY_HTTP_PROXY_HOST);
int proxyPort = Integer.parseInt((String) properties.get(profile + Configuration.PROPERTY_HTTP_PROXY_PORT));
HttpHost proxy;
if (properties.containsKey(profile + Configuration.PROPERTY_HTTP_PROXY_SCHEME)) {
proxy = new HttpHost(proxyHost, proxyPort, (String) properties.get(profile + Configuration.PROPERTY_HTTP_PROXY_SCHEME));
} else {
proxy = new HttpHost(proxyHost, proxyPort);
}
httpClientBuilder.setProxy(proxy);
}

return httpClientBuilder;
}
}

0 comments on commit 90b7de0

Please sign in to comment.