Skip to content

Commit 8d714ad

Browse files
author
Marcus Linke
committed
Merge branch '2.x'
Conflicts: CHANGELOG.md
2 parents d63e70b + 7b1e190 commit 8d714ad

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All changes
1111

1212
* [#392] (https://github.com/docker-java/docker-java/pull/392) Introduce InspectContainerResponse.Mounts
1313
* [#387] (https://github.com/docker-java/docker-java/pull/387) Make ProgressDetails attributes public
14+
* [#386] (https://github.com/docker-java/docker-java/pull/386) Basic http proxy configuration support
1415
* [#362] (https://github.com/docker-java/docker-java/pull/362) Deprecate "network" and enable "networks" stats (remote Docker API 1.21)
1516
* [#359] (https://github.com/docker-java/docker-java/pull/359) Fix performance issue of build command by adding bulk-read variant of InputStream.read()
1617
* [#357] (https://github.com/docker-java/docker-java/pull/357) Wait container command needs possibility to abort operation
@@ -19,7 +20,8 @@ All changes
1920
2.1.3-SNAPSHOT
2021
---
2122
* [#387] (https://github.com/docker-java/docker-java/pull/387) Make ProgressDetails attributes public
22-
* [#362] (https://github.com/docker-java/docker-java/pull/362) Deprecate "network" and enable "networks" stats (remote Docker API 1.21)
23+
* [#386] (https://github.com/docker-java/docker-java/pull/386) Basic http proxy configuration support
24+
* [#362] (https://github.com/docker-java/docker-java/pull/362) Deprecate "network" and enable "networks" stats (remote Docker API 1.21)
2325

2426
v2.1.2
2527
---

src/main/java/com/github/dockerjava/jaxrs/DockerCmdExecFactoryImpl.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.github.dockerjava.jaxrs.filter.JsonClientFilter;
4545
import com.github.dockerjava.jaxrs.filter.ResponseStatusExceptionFilter;
4646
import com.github.dockerjava.jaxrs.filter.SelectiveLoggingFilter;
47+
4748
import org.apache.http.config.RegistryBuilder;
4849
import org.apache.http.conn.socket.ConnectionSocketFactory;
4950
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
@@ -62,8 +63,13 @@
6263
import javax.ws.rs.client.ClientRequestFilter;
6364
import javax.ws.rs.client.ClientResponseFilter;
6465
import javax.ws.rs.client.WebTarget;
66+
6567
import java.io.IOException;
68+
import java.net.InetSocketAddress;
69+
import java.net.Proxy;
70+
import java.net.ProxySelector;
6671
import java.net.URI;
72+
import java.util.List;
6773

6874
import static com.google.common.base.Preconditions.checkNotNull;
6975

@@ -95,6 +101,7 @@ public class DockerCmdExecFactoryImpl implements DockerCmdExecFactory {
95101
@Override
96102
public void init(DockerClientConfig dockerClientConfig) {
97103
checkNotNull(dockerClientConfig, "config was not specified");
104+
this.dockerClientConfig = dockerClientConfig;
98105

99106
ClientConfig clientConfig = new ClientConfig();
100107
clientConfig.connectorProvider(new ApacheConnectorProvider());
@@ -134,11 +141,14 @@ public void init(DockerClientConfig dockerClientConfig) {
134141
SSLContext sslContext = null;
135142

136143
if (dockerClientConfig.getSslConfig() != null) {
144+
configureProxy(clientConfig, "https");
137145
try {
138146
sslContext = dockerClientConfig.getSslConfig().getSSLContext();
139147
} catch (Exception ex) {
140148
throw new DockerClientException("Error in SSL Configuration", ex);
141149
}
150+
} else {
151+
configureProxy(clientConfig, "http");
142152
}
143153

144154
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(getSchemeRegistry(
@@ -169,7 +179,30 @@ public void init(DockerClientConfig dockerClientConfig) {
169179

170180
baseResource = client.target(dockerClientConfig.getUri()).path(dockerClientConfig.getVersion().asWebPathPart());
171181

172-
this.dockerClientConfig = dockerClientConfig;
182+
}
183+
184+
private void configureProxy(ClientConfig clientConfig, String protocol) {
185+
186+
List<Proxy> proxies = ProxySelector.getDefault().select(dockerClientConfig.getUri());
187+
188+
for (Proxy proxy : proxies) {
189+
InetSocketAddress address = (InetSocketAddress) proxy.address();
190+
if (address != null) {
191+
String hostname = address.getHostName();
192+
int port = address.getPort();
193+
194+
clientConfig.property(ClientProperties.PROXY_URI, protocol + "://" + hostname + ":" + port);
195+
196+
String httpProxyUser = System.getProperty(protocol + ".proxyUser");
197+
if (httpProxyUser != null) {
198+
clientConfig.property(ClientProperties.PROXY_USERNAME, httpProxyUser);
199+
String httpProxyPassword = System.getProperty(protocol + ".proxyPassword");
200+
if (httpProxyPassword != null) {
201+
clientConfig.property(ClientProperties.PROXY_PASSWORD, httpProxyPassword);
202+
}
203+
}
204+
}
205+
}
173206
}
174207

175208
private org.apache.http.config.Registry<ConnectionSocketFactory> getSchemeRegistry(final URI originalUri,

0 commit comments

Comments
 (0)