|
45 | 45 | import com.github.dockerjava.jaxrs.filter.JsonClientFilter; |
46 | 46 | import com.github.dockerjava.jaxrs.filter.ResponseStatusExceptionFilter; |
47 | 47 | import com.github.dockerjava.jaxrs.filter.SelectiveLoggingFilter; |
| 48 | + |
48 | 49 | import org.apache.http.config.RegistryBuilder; |
49 | 50 | import org.apache.http.conn.socket.ConnectionSocketFactory; |
50 | 51 | import org.apache.http.conn.socket.PlainConnectionSocketFactory; |
|
63 | 64 | import javax.ws.rs.client.ClientRequestFilter; |
64 | 65 | import javax.ws.rs.client.ClientResponseFilter; |
65 | 66 | import javax.ws.rs.client.WebTarget; |
| 67 | + |
66 | 68 | import java.io.IOException; |
| 69 | +import java.net.InetSocketAddress; |
| 70 | +import java.net.Proxy; |
| 71 | +import java.net.ProxySelector; |
67 | 72 | import java.net.URI; |
| 73 | +import java.util.List; |
68 | 74 |
|
69 | 75 | import static com.google.common.base.Preconditions.checkNotNull; |
70 | 76 |
|
@@ -96,6 +102,7 @@ public class DockerCmdExecFactoryImpl implements DockerCmdExecFactory { |
96 | 102 | @Override |
97 | 103 | public void init(DockerClientConfig dockerClientConfig) { |
98 | 104 | checkNotNull(dockerClientConfig, "config was not specified"); |
| 105 | + this.dockerClientConfig = dockerClientConfig; |
99 | 106 |
|
100 | 107 | ClientConfig clientConfig = new ClientConfig(); |
101 | 108 | clientConfig.connectorProvider(new ApacheConnectorProvider()); |
@@ -135,11 +142,14 @@ public void init(DockerClientConfig dockerClientConfig) { |
135 | 142 | SSLContext sslContext = null; |
136 | 143 |
|
137 | 144 | if (dockerClientConfig.getSslConfig() != null) { |
| 145 | + configureProxy(clientConfig, "https"); |
138 | 146 | try { |
139 | 147 | sslContext = dockerClientConfig.getSslConfig().getSSLContext(); |
140 | 148 | } catch (Exception ex) { |
141 | 149 | throw new DockerClientException("Error in SSL Configuration", ex); |
142 | 150 | } |
| 151 | + } else { |
| 152 | + configureProxy(clientConfig, "http"); |
143 | 153 | } |
144 | 154 |
|
145 | 155 | PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(getSchemeRegistry( |
@@ -170,7 +180,30 @@ public void init(DockerClientConfig dockerClientConfig) { |
170 | 180 |
|
171 | 181 | baseResource = client.target(dockerClientConfig.getUri()).path(dockerClientConfig.getVersion().asWebPathPart()); |
172 | 182 |
|
173 | | - this.dockerClientConfig = dockerClientConfig; |
| 183 | + } |
| 184 | + |
| 185 | + private void configureProxy(ClientConfig clientConfig, String protocol) { |
| 186 | + |
| 187 | + List<Proxy> proxies = ProxySelector.getDefault().select(dockerClientConfig.getUri()); |
| 188 | + |
| 189 | + for (Proxy proxy : proxies) { |
| 190 | + InetSocketAddress address = (InetSocketAddress) proxy.address(); |
| 191 | + if (address != null) { |
| 192 | + String hostname = address.getHostName(); |
| 193 | + int port = address.getPort(); |
| 194 | + |
| 195 | + clientConfig.property(ClientProperties.PROXY_URI, protocol + "://" + hostname + ":" + port); |
| 196 | + |
| 197 | + String httpProxyUser = System.getProperty(protocol + ".proxyUser"); |
| 198 | + if (httpProxyUser != null) { |
| 199 | + clientConfig.property(ClientProperties.PROXY_USERNAME, httpProxyUser); |
| 200 | + String httpProxyPassword = System.getProperty(protocol + ".proxyPassword"); |
| 201 | + if (httpProxyPassword != null) { |
| 202 | + clientConfig.property(ClientProperties.PROXY_PASSWORD, httpProxyPassword); |
| 203 | + } |
| 204 | + } |
| 205 | + } |
| 206 | + } |
174 | 207 | } |
175 | 208 |
|
176 | 209 | private org.apache.http.config.Registry<ConnectionSocketFactory> getSchemeRegistry(final URI originalUri, |
|
0 commit comments