Skip to content

Commit a92bb00

Browse files
committed
Merge pull request docker-java#282 from docker-java/refact-config
Remove JAXRS/ApacheConnector implementation specific properties from DockerClientConfig
2 parents aef0aa8 + 2e31510 commit a92bb00

File tree

9 files changed

+85
-137
lines changed

9 files changed

+85
-137
lines changed

src/main/java/com/github/dockerjava/core/DockerClientConfig.java

Lines changed: 5 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,10 @@ public class DockerClientConfig implements Serializable {
4040

4141
private static final String DOCKER_IO_SERVER_ADDRESS_PROPERTY = "docker.io.serverAddress";
4242

43-
private static final String DOCKER_IO_READ_TIMEOUT_PROPERTY = "docker.io.readTimeout";
44-
45-
// this is really confusing, as there are two ways to spell it
46-
private static final String DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY = "docker.io.enableLoggingFilter";
47-
48-
private static final String DOCKER_IO_FOLLOW_REDIRECTS_FILTER_PROPERTY = "docker.io.followRedirectsFilter";
49-
5043
private static final String DOCKER_IO_DOCKER_CERT_PATH_PROPERTY = "docker.io.dockerCertPath";
5144

5245
private static final String DOCKER_IO_DOCKER_CFG_PATH_PROPERTY = "docker.io.dockerCfgPath";
5346

54-
// connection pooling properties
55-
private static final String DOCKER_IO_MAX_PER_ROUTE_PROPERTY = "docker.io.perRouteConnections";
56-
57-
private static final String DOCKER_IO_MAX_TOTAL_PROPERTY = "docker.io.totalConnections";
58-
5947
/**
6048
* A map from the environment name to the interval name.
6149
*/
@@ -69,9 +57,6 @@ public class DockerClientConfig implements Serializable {
6957
m.put("DOCKER_PASSWORD", DOCKER_IO_PASSWORD_PROPERTY);
7058
m.put("DOCKER_EMAIL", DOCKER_IO_EMAIL_PROPERTY);
7159
m.put("DOCKER_SERVER_ADDRESS", DOCKER_IO_SERVER_ADDRESS_PROPERTY);
72-
m.put("DOCKER_READ_TIMEOUT", DOCKER_IO_READ_TIMEOUT_PROPERTY);
73-
m.put("DOCKER_LOGGING_FILTER_ENABLED", DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY);
74-
m.put("DOCKER_FOLLOW_REDIRECTS_FILTER_ENABLED", DOCKER_IO_FOLLOW_REDIRECTS_FILTER_PROPERTY);
7560
m.put(DOCKER_CERT_PATH_PROPERTY, DOCKER_IO_DOCKER_CERT_PATH_PROPERTY);
7661
m.put("DOCKER_CFG_PATH", DOCKER_IO_DOCKER_CFG_PATH_PROPERTY);
7762
ENV_NAME_TO_IO_NAME = Collections.unmodifiableMap(m);
@@ -83,34 +68,18 @@ public class DockerClientConfig implements Serializable {
8368

8469
private final String version, username, password, email, serverAddress, dockerCfgPath;
8570

86-
private final Integer readTimeout;
87-
88-
private final boolean loggingFilterEnabled;
89-
90-
private final boolean followRedirectsFilterEnabled;
91-
9271
private final SSLConfig sslConfig;
9372

94-
private final Integer maxTotalConnections;
95-
96-
private final Integer maxPerRouteConnections;
97-
9873
DockerClientConfig(URI uri, String version, String username, String password, String email, String serverAddress,
99-
String dockerCfgPath, Integer readTimeout, boolean loggingFilterEnabled,
100-
boolean followRedirectsFilterEnabled, SSLConfig sslConfig, Integer maxTotalConns, Integer maxPerRouteConns) {
74+
String dockerCfgPath, SSLConfig sslConfig) {
10175
this.uri = uri;
10276
this.version = version;
10377
this.username = username;
10478
this.password = password;
10579
this.email = email;
10680
this.serverAddress = serverAddress;
10781
this.dockerCfgPath = dockerCfgPath;
108-
this.readTimeout = readTimeout;
109-
this.loggingFilterEnabled = loggingFilterEnabled;
110-
this.followRedirectsFilterEnabled = followRedirectsFilterEnabled;
11182
this.sslConfig = sslConfig;
112-
this.maxTotalConnections = maxTotalConns;
113-
this.maxPerRouteConnections = maxPerRouteConns;
11483
}
11584

11685
private static Properties loadIncludedDockerProperties(Properties systemProperties) {
@@ -208,8 +177,7 @@ private static Properties overrideDockerPropertiesWithSystemProperties(Propertie
208177

209178
for (String key : new String[] { DOCKER_IO_URL_PROPERTY, DOCKER_IO_VERSION_PROPERTY,
210179
DOCKER_IO_USERNAME_PROPERTY, DOCKER_IO_PASSWORD_PROPERTY, DOCKER_IO_EMAIL_PROPERTY,
211-
DOCKER_IO_SERVER_ADDRESS_PROPERTY, DOCKER_IO_READ_TIMEOUT_PROPERTY,
212-
DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY, DOCKER_IO_FOLLOW_REDIRECTS_FILTER_PROPERTY,
180+
DOCKER_IO_SERVER_ADDRESS_PROPERTY,
213181
DOCKER_IO_DOCKER_CERT_PATH_PROPERTY, DOCKER_IO_DOCKER_CFG_PATH_PROPERTY, }) {
214182
if (systemProperties.containsKey(key)) {
215183
overriddenProperties.setProperty(key, systemProperties.getProperty(key));
@@ -261,18 +229,6 @@ public String getServerAddress() {
261229
return serverAddress;
262230
}
263231

264-
public Integer getReadTimeout() {
265-
return readTimeout;
266-
}
267-
268-
public boolean isLoggingFilterEnabled() {
269-
return loggingFilterEnabled;
270-
}
271-
272-
public boolean followRedirectsFilterEnabled() {
273-
return followRedirectsFilterEnabled;
274-
}
275-
276232
public SSLConfig getSslConfig() {
277233
return sslConfig;
278234
}
@@ -281,14 +237,6 @@ public String getDockerCfgPath() {
281237
return dockerCfgPath;
282238
}
283239

284-
public Integer getMaxTotalConnections() {
285-
return maxTotalConnections;
286-
}
287-
288-
public Integer getMaxPerRoutConnections() {
289-
return maxPerRouteConnections;
290-
}
291-
292240
private AuthConfig getAuthConfig() {
293241
AuthConfig authConfig = null;
294242
if (getUsername() != null && getPassword() != null && getEmail() != null && getServerAddress() != null) {
@@ -352,8 +300,6 @@ public boolean equals(Object o) {
352300

353301
DockerClientConfig that = (DockerClientConfig) o;
354302

355-
if (loggingFilterEnabled != that.loggingFilterEnabled)
356-
return false;
357303
if (sslConfig != null ? !sslConfig.equals(that.sslConfig) : that.sslConfig != null)
358304
return false;
359305
if (dockerCfgPath != null ? !dockerCfgPath.equals(that.dockerCfgPath) : that.dockerCfgPath != null)
@@ -362,8 +308,6 @@ public boolean equals(Object o) {
362308
return false;
363309
if (password != null ? !password.equals(that.password) : that.password != null)
364310
return false;
365-
if (readTimeout != null ? !readTimeout.equals(that.readTimeout) : that.readTimeout != null)
366-
return false;
367311
if (serverAddress != null ? !serverAddress.equals(that.serverAddress) : that.serverAddress != null)
368312
return false;
369313
if (uri != null ? !uri.equals(that.uri) : that.uri != null)
@@ -386,8 +330,6 @@ public int hashCode() {
386330
result = 31 * result + (serverAddress != null ? serverAddress.hashCode() : 0);
387331
result = 31 * result + (dockerCfgPath != null ? dockerCfgPath.hashCode() : 0);
388332
result = 31 * result + (sslConfig != null ? sslConfig.hashCode() : 0);
389-
result = 31 * result + (readTimeout != null ? readTimeout.hashCode() : 0);
390-
result = 31 * result + (loggingFilterEnabled ? 1 : 0);
391333
return result;
392334
}
393335

@@ -396,19 +338,14 @@ public String toString() {
396338
return "DockerClientConfig{" + "uri=" + uri + ", version='" + version + '\'' + ", username='" + username + '\''
397339
+ ", password='" + password + '\'' + ", email='" + email + '\'' + ", serverAddress='" + serverAddress
398340
+ '\'' + ", dockerCfgPath='" + dockerCfgPath + '\'' + ", sslConfig='" + sslConfig + '\''
399-
+ ", readTimeout=" + readTimeout + ", loggingFilterEnabled=" + loggingFilterEnabled
400-
+ ", followRedirectsFilterEnabled=" + followRedirectsFilterEnabled + '}';
341+
+ '}';
401342
}
402343

403344
public static class DockerClientConfigBuilder {
404345
private URI uri;
405346

406347
private String version, username, password, email, serverAddress, dockerCfgPath;
407348

408-
private Integer readTimeout, maxTotalConnections, maxPerRouteConnections;
409-
410-
private boolean loggingFilterEnabled, followRedirectsFilterEnabled;
411-
412349
private SSLConfig sslConfig;
413350

414351
/**
@@ -424,21 +361,8 @@ public DockerClientConfigBuilder withProperties(Properties p) {
424361
.withPassword(p.getProperty(DOCKER_IO_PASSWORD_PROPERTY))
425362
.withEmail(p.getProperty(DOCKER_IO_EMAIL_PROPERTY))
426363
.withServerAddress(p.getProperty(DOCKER_IO_SERVER_ADDRESS_PROPERTY))
427-
.withReadTimeout(Integer.valueOf(p.getProperty(DOCKER_IO_READ_TIMEOUT_PROPERTY, "0")))
428-
.withLoggingFilter(Boolean.valueOf(p.getProperty(DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY, "true")))
429-
.withFollowRedirectsFilter(
430-
Boolean.valueOf(p.getProperty(DOCKER_IO_FOLLOW_REDIRECTS_FILTER_PROPERTY, "false")))
431364
.withDockerCertPath(p.getProperty(DOCKER_IO_DOCKER_CERT_PATH_PROPERTY))
432-
.withDockerCfgPath(p.getProperty(DOCKER_IO_DOCKER_CFG_PATH_PROPERTY))
433-
.withMaxPerRouteConnections(integerValue(p.getProperty(DOCKER_IO_MAX_PER_ROUTE_PROPERTY)))
434-
.withMaxTotalConnections(integerValue(p.getProperty(DOCKER_IO_MAX_TOTAL_PROPERTY)));
435-
}
436-
437-
private Integer integerValue(String value) {
438-
if (value != null)
439-
return Integer.valueOf(value);
440-
else
441-
return null;
365+
.withDockerCfgPath(p.getProperty(DOCKER_IO_DOCKER_CFG_PATH_PROPERTY));
442366
}
443367

444368
public final DockerClientConfigBuilder withUri(String uri) {
@@ -472,31 +396,6 @@ public DockerClientConfigBuilder withServerAddress(String serverAddress) {
472396
return this;
473397
}
474398

475-
public final DockerClientConfigBuilder withReadTimeout(Integer readTimeout) {
476-
this.readTimeout = readTimeout;
477-
return this;
478-
}
479-
480-
public final DockerClientConfigBuilder withMaxTotalConnections(Integer maxTotalConnections) {
481-
this.maxTotalConnections = maxTotalConnections;
482-
return this;
483-
}
484-
485-
public final DockerClientConfigBuilder withMaxPerRouteConnections(Integer maxPerRouteConnections) {
486-
this.maxPerRouteConnections = maxPerRouteConnections;
487-
return this;
488-
}
489-
490-
public final DockerClientConfigBuilder withLoggingFilter(boolean loggingFilterEnabled) {
491-
this.loggingFilterEnabled = loggingFilterEnabled;
492-
return this;
493-
}
494-
495-
public final DockerClientConfigBuilder withFollowRedirectsFilter(boolean followRedirectsFilterEnabled) {
496-
this.followRedirectsFilterEnabled = followRedirectsFilterEnabled;
497-
return this;
498-
}
499-
500399
public final DockerClientConfigBuilder withDockerCertPath(String dockerCertPath) {
501400
if (dockerCertPath != null) {
502401
this.sslConfig = new LocalDirectorySSLConfig(dockerCertPath);
@@ -516,8 +415,7 @@ public final DockerClientConfigBuilder withSSLConfig(SSLConfig config) {
516415

517416
public DockerClientConfig build() {
518417
return new DockerClientConfig(uri, version, username, password, email, serverAddress, dockerCfgPath,
519-
readTimeout, loggingFilterEnabled, followRedirectsFilterEnabled, sslConfig, maxTotalConnections,
520-
maxPerRouteConnections);
418+
sslConfig);
521419
}
522420
}
523421

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

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import javax.net.ssl.SSLContext;
99
import javax.ws.rs.client.Client;
1010
import javax.ws.rs.client.ClientBuilder;
11+
import javax.ws.rs.client.ClientRequestFilter;
12+
import javax.ws.rs.client.ClientResponseFilter;
1113
import javax.ws.rs.client.WebTarget;
1214

1315
import org.apache.http.config.RegistryBuilder;
@@ -62,13 +64,13 @@
6264
import com.github.dockerjava.api.command.VersionCmd;
6365
import com.github.dockerjava.api.command.WaitContainerCmd;
6466
import com.github.dockerjava.core.DockerClientConfig;
65-
import com.github.dockerjava.core.util.FollowRedirectsFilter;
66-
import com.github.dockerjava.core.util.JsonClientFilter;
67-
import com.github.dockerjava.core.util.ResponseStatusExceptionFilter;
68-
import com.github.dockerjava.core.util.SelectiveLoggingFilter;
6967
//import org.glassfish.jersey.apache.connector.ApacheConnectorProvider;
7068
// see https://github.com/docker-java/docker-java/issues/196
7169
import com.github.dockerjava.jaxrs.connector.ApacheConnectorProvider;
70+
import com.github.dockerjava.jaxrs.filter.FollowRedirectsFilter;
71+
import com.github.dockerjava.jaxrs.filter.JsonClientFilter;
72+
import com.github.dockerjava.jaxrs.filter.ResponseStatusExceptionFilter;
73+
import com.github.dockerjava.jaxrs.filter.SelectiveLoggingFilter;
7274

7375
public class DockerCmdExecFactoryImpl implements DockerCmdExecFactory {
7476

@@ -78,6 +80,18 @@ public class DockerCmdExecFactoryImpl implements DockerCmdExecFactory {
7880

7981
private WebTarget baseResource;
8082

83+
private Integer readTimeout = null;
84+
85+
private Integer connectTimeout = null;
86+
87+
private Integer maxTotalConnections = null;
88+
89+
private Integer maxPerRouteConnections = null;
90+
91+
private ClientRequestFilter[] clientRequestFilters = null;
92+
93+
private ClientResponseFilter[] clientResponseFilters = null;
94+
8195
@Override
8296
public void init(DockerClientConfig dockerClientConfig) {
8397
checkNotNull(dockerClientConfig, "config was not specified");
@@ -90,20 +104,30 @@ public void init(DockerClientConfig dockerClientConfig) {
90104
clientConfig.register(JsonClientFilter.class);
91105
clientConfig.register(JacksonJsonProvider.class);
92106

93-
if (dockerClientConfig.followRedirectsFilterEnabled()) {
94-
clientConfig.register(FollowRedirectsFilter.class);
107+
// logging may disabled via log level
108+
clientConfig.register(new SelectiveLoggingFilter(LOGGER, true));
109+
110+
if (readTimeout != null) {
111+
clientConfig.property(ClientProperties.READ_TIMEOUT, readTimeout);
95112
}
96113

97-
if (dockerClientConfig.isLoggingFilterEnabled()) {
98-
clientConfig.register(new SelectiveLoggingFilter(LOGGER, true));
114+
if (connectTimeout != null) {
115+
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout);
99116
}
100117

101-
if (dockerClientConfig.getReadTimeout() != null) {
102-
int readTimeout = dockerClientConfig.getReadTimeout();
103-
clientConfig.property(ClientProperties.READ_TIMEOUT, readTimeout);
118+
if (clientResponseFilters != null) {
119+
for (ClientResponseFilter clientResponseFilter : clientResponseFilters) {
120+
if (clientResponseFilter != null)
121+
clientConfig.register(clientResponseFilter);
122+
}
104123
}
105124

106-
// clientConfig.property(ClientProperties.CONNECT_TIMEOUT, 10000);
125+
if (clientRequestFilters != null) {
126+
for (ClientRequestFilter clientRequestFilter : clientRequestFilters) {
127+
if(clientRequestFilter != null)
128+
clientConfig.register(clientRequestFilter);
129+
}
130+
}
107131

108132
URI originalUri = dockerClientConfig.getUri();
109133

@@ -120,10 +144,10 @@ public void init(DockerClientConfig dockerClientConfig) {
120144
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(getSchemeRegistry(
121145
originalUri, sslContext));
122146

123-
if (dockerClientConfig.getMaxTotalConnections() != null)
124-
connManager.setMaxTotal(dockerClientConfig.getMaxTotalConnections());
125-
if (dockerClientConfig.getMaxPerRoutConnections() != null)
126-
connManager.setDefaultMaxPerRoute(dockerClientConfig.getMaxPerRoutConnections());
147+
if (maxTotalConnections != null)
148+
connManager.setMaxTotal(maxTotalConnections);
149+
if (maxPerRouteConnections != null)
150+
connManager.setDefaultMaxPerRoute(maxPerRouteConnections);
127151

128152
clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, connManager);
129153

@@ -353,4 +377,34 @@ public void close() throws IOException {
353377
client.close();
354378
}
355379

380+
public DockerCmdExecFactoryImpl withReadTimeout(Integer readTimeout) {
381+
this.readTimeout = readTimeout;
382+
return this;
383+
}
384+
385+
public DockerCmdExecFactoryImpl withConnectTimeout(Integer connectTimeout) {
386+
this.connectTimeout = connectTimeout;
387+
return this;
388+
}
389+
390+
public DockerCmdExecFactoryImpl withMaxTotalConnections(Integer maxTotalConnections) {
391+
this.maxTotalConnections = maxTotalConnections;
392+
return this;
393+
}
394+
395+
public DockerCmdExecFactoryImpl withMaxPerRouteConnections(Integer maxPerRouteConnections) {
396+
this.maxPerRouteConnections = maxPerRouteConnections;
397+
return this;
398+
}
399+
400+
public DockerCmdExecFactoryImpl withClientResponseFilters(ClientResponseFilter... clientResponseFilter) {
401+
this.clientResponseFilters = clientResponseFilter;
402+
return this;
403+
}
404+
405+
public DockerCmdExecFactoryImpl withClientRequestFilters(ClientRequestFilter... clientRequestFilters) {
406+
this.clientRequestFilters = clientRequestFilters;
407+
return this;
408+
}
409+
356410
}

src/main/java/com/github/dockerjava/core/util/FollowRedirectsFilter.java renamed to src/main/java/com/github/dockerjava/jaxrs/filter/FollowRedirectsFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.dockerjava.core.util;
1+
package com.github.dockerjava.jaxrs.filter;
22

33
import java.io.IOException;
44
import java.io.InputStream;

src/main/java/com/github/dockerjava/core/util/JsonClientFilter.java renamed to src/main/java/com/github/dockerjava/jaxrs/filter/JsonClientFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.dockerjava.core.util;
1+
package com.github.dockerjava.jaxrs.filter;
22

33
import java.io.IOException;
44

src/main/java/com/github/dockerjava/core/util/LoggingFilter.java renamed to src/main/java/com/github/dockerjava/jaxrs/filter/LoggingFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.dockerjava.core.util;
1+
package com.github.dockerjava.jaxrs.filter;
22

33
/*
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

src/main/java/com/github/dockerjava/core/util/ResponseStatusExceptionFilter.java renamed to src/main/java/com/github/dockerjava/jaxrs/filter/ResponseStatusExceptionFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.dockerjava.core.util;
1+
package com.github.dockerjava.jaxrs.filter;
22

33
import java.io.EOFException;
44
import java.io.IOException;

src/main/java/com/github/dockerjava/core/util/SelectiveLoggingFilter.java renamed to src/main/java/com/github/dockerjava/jaxrs/filter/SelectiveLoggingFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.dockerjava.core.util;
1+
package com.github.dockerjava.jaxrs.filter;
22

33
import java.io.IOException;
44
import java.util.Collections;

0 commit comments

Comments
 (0)