|
44 | 44 | import com.github.dockerjava.jaxrs.filter.JsonClientFilter; |
45 | 45 | import com.github.dockerjava.jaxrs.filter.ResponseStatusExceptionFilter; |
46 | 46 | import com.github.dockerjava.jaxrs.filter.SelectiveLoggingFilter; |
| 47 | + |
47 | 48 | import org.apache.http.config.RegistryBuilder; |
48 | 49 | import org.apache.http.conn.socket.ConnectionSocketFactory; |
49 | 50 | import org.apache.http.conn.socket.PlainConnectionSocketFactory; |
|
62 | 63 | import javax.ws.rs.client.ClientRequestFilter; |
63 | 64 | import javax.ws.rs.client.ClientResponseFilter; |
64 | 65 | import javax.ws.rs.client.WebTarget; |
| 66 | + |
65 | 67 | import java.io.IOException; |
| 68 | +import java.net.InetSocketAddress; |
| 69 | +import java.net.Proxy; |
| 70 | +import java.net.ProxySelector; |
66 | 71 | import java.net.URI; |
| 72 | +import java.util.List; |
67 | 73 |
|
68 | 74 | import static com.google.common.base.Preconditions.checkNotNull; |
69 | 75 |
|
@@ -95,6 +101,7 @@ public class DockerCmdExecFactoryImpl implements DockerCmdExecFactory { |
95 | 101 | @Override |
96 | 102 | public void init(DockerClientConfig dockerClientConfig) { |
97 | 103 | checkNotNull(dockerClientConfig, "config was not specified"); |
| 104 | + this.dockerClientConfig = dockerClientConfig; |
98 | 105 |
|
99 | 106 | ClientConfig clientConfig = new ClientConfig(); |
100 | 107 | clientConfig.connectorProvider(new ApacheConnectorProvider()); |
@@ -134,11 +141,14 @@ public void init(DockerClientConfig dockerClientConfig) { |
134 | 141 | SSLContext sslContext = null; |
135 | 142 |
|
136 | 143 | if (dockerClientConfig.getSslConfig() != null) { |
| 144 | + configureProxy(clientConfig, "https"); |
137 | 145 | try { |
138 | 146 | sslContext = dockerClientConfig.getSslConfig().getSSLContext(); |
139 | 147 | } catch (Exception ex) { |
140 | 148 | throw new DockerClientException("Error in SSL Configuration", ex); |
141 | 149 | } |
| 150 | + } else { |
| 151 | + configureProxy(clientConfig, "http"); |
142 | 152 | } |
143 | 153 |
|
144 | 154 | PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(getSchemeRegistry( |
@@ -169,7 +179,30 @@ public void init(DockerClientConfig dockerClientConfig) { |
169 | 179 |
|
170 | 180 | baseResource = client.target(dockerClientConfig.getUri()).path(dockerClientConfig.getVersion().asWebPathPart()); |
171 | 181 |
|
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 | + } |
173 | 206 | } |
174 | 207 |
|
175 | 208 | private org.apache.http.config.Registry<ConnectionSocketFactory> getSchemeRegistry(final URI originalUri, |
|
0 commit comments