Skip to content

Commit 8e2a1af

Browse files
author
Marcus Linke
committed
Merge branch 'redirects' of https://github.com/gabeki/docker-java into
gabeki-redirects Conflicts: src/main/java/com/github/dockerjava/core/DockerClientConfig.java src/main/java/com/github/dockerjava/jaxrs/DockerCmdExecFactoryImpl.java
2 parents 4dea651 + adb85a8 commit 8e2a1af

6 files changed

Lines changed: 317 additions & 277 deletions

File tree

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class DockerClientConfig implements Serializable {
3333
private static final String DOCKER_IO_READ_TIMEOUT_PROPERTY = "docker.io.readTimeout";
3434
// this is really confusing, as there are two ways to spell it
3535
private static final String DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY = "docker.io.enableLoggingFilter";
36+
private static final String DOCKER_IO_FOLLOW_REDIRECTS_FILTER_PROPERTY = "docker.io.followRedirectsFilter";
3637
private static final String DOCKER_IO_DOCKER_CERT_PATH_PROPERTY = "docker.io.dockerCertPath";
3738
private static final String DOCKER_IO_DOCKER_CFG_PATH_PROPERTY = "docker.io.dockerCfgPath";
3839
// connection pooling properties
@@ -53,6 +54,7 @@ public class DockerClientConfig implements Serializable {
5354
m.put("DOCKER_SERVER_ADDRESS", DOCKER_IO_SERVER_ADDRESS_PROPERTY);
5455
m.put("DOCKER_READ_TIMEOUT", DOCKER_IO_READ_TIMEOUT_PROPERTY);
5556
m.put("DOCKER_LOGGING_FILTER_ENABLED", DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY);
57+
m.put("DOCKER_FOLLOW_REDIRECTS_FILTER_ENABLED", DOCKER_IO_FOLLOW_REDIRECTS_FILTER_PROPERTY);
5658
m.put(DOCKER_CERT_PATH_PROPERTY, DOCKER_IO_DOCKER_CERT_PATH_PROPERTY);
5759
m.put("DOCKER_CFG_PATH", DOCKER_IO_DOCKER_CFG_PATH_PROPERTY);
5860
ENV_NAME_TO_IO_NAME = Collections.unmodifiableMap(m);
@@ -63,14 +65,15 @@ public class DockerClientConfig implements Serializable {
6365
private final String version, username, password, email, serverAddress, dockerCfgPath;
6466
private final Integer readTimeout;
6567
private final boolean loggingFilterEnabled;
68+
private final boolean followRedirectsFilterEnabled;
6669
private final SSLConfig sslConfig;
6770

6871
private final Integer maxTotalConnections;
6972
private final Integer maxPerRouteConnections;
7073

7174
DockerClientConfig(URI uri, String version, String username, String password, String email, String serverAddress,
72-
String dockerCfgPath, Integer readTimeout, boolean loggingFilterEnabled, SSLConfig sslConfig,
73-
Integer maxTotalConns, Integer maxPerRouteConns) {
75+
String dockerCfgPath, Integer readTimeout, boolean loggingFilterEnabled, boolean followRedirectsFilterEnabled,
76+
SSLConfig sslConfig, Integer maxTotalConns, Integer maxPerRouteConns) {
7477
this.uri = uri;
7578
this.version = version;
7679
this.username = username;
@@ -80,6 +83,7 @@ public class DockerClientConfig implements Serializable {
8083
this.dockerCfgPath = dockerCfgPath;
8184
this.readTimeout = readTimeout;
8285
this.loggingFilterEnabled = loggingFilterEnabled;
86+
this.followRedirectsFilterEnabled = followRedirectsFilterEnabled;
8387
this.sslConfig = sslConfig;
8488
this.maxTotalConnections = maxTotalConns;
8589
this.maxPerRouteConnections = maxPerRouteConns;
@@ -182,6 +186,7 @@ private static Properties overrideDockerPropertiesWithSystemProperties(Propertie
182186
DOCKER_IO_SERVER_ADDRESS_PROPERTY,
183187
DOCKER_IO_READ_TIMEOUT_PROPERTY,
184188
DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY,
189+
DOCKER_IO_FOLLOW_REDIRECTS_FILTER_PROPERTY,
185190
DOCKER_IO_DOCKER_CERT_PATH_PROPERTY,
186191
DOCKER_IO_DOCKER_CFG_PATH_PROPERTY,
187192
}) {
@@ -243,6 +248,10 @@ public boolean isLoggingFilterEnabled() {
243248
return loggingFilterEnabled;
244249
}
245250

251+
public boolean followRedirectsFilterEnabled() {
252+
return followRedirectsFilterEnabled;
253+
}
254+
246255
public SSLConfig getSslConfig() {
247256
return sslConfig;
248257
}
@@ -353,14 +362,15 @@ public String toString() {
353362
", sslConfig='" + sslConfig + '\'' +
354363
", readTimeout=" + readTimeout +
355364
", loggingFilterEnabled=" + loggingFilterEnabled +
365+
", followRedirectsFilterEnabled=" + followRedirectsFilterEnabled +
356366
'}';
357367
}
358368

359369
public static class DockerClientConfigBuilder {
360370
private URI uri;
361371
private String version, username, password, email, serverAddress, dockerCfgPath;
362372
private Integer readTimeout, maxTotalConnections, maxPerRouteConnections;
363-
private boolean loggingFilterEnabled;
373+
private boolean loggingFilterEnabled, followRedirectsFilterEnabled;
364374
private SSLConfig sslConfig;
365375

366376
/**
@@ -378,6 +388,7 @@ public DockerClientConfigBuilder withProperties(Properties p) {
378388
.withServerAddress(p.getProperty(DOCKER_IO_SERVER_ADDRESS_PROPERTY))
379389
.withReadTimeout(Integer.valueOf(p.getProperty(DOCKER_IO_READ_TIMEOUT_PROPERTY, "0")))
380390
.withLoggingFilter(Boolean.valueOf(p.getProperty(DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY, "true")))
391+
.withFollowRedirectsFilter(Boolean.valueOf(p.getProperty(DOCKER_IO_FOLLOW_REDIRECTS_FILTER_PROPERTY, "false")))
381392
.withDockerCertPath(p.getProperty(DOCKER_IO_DOCKER_CERT_PATH_PROPERTY))
382393
.withDockerCfgPath(p.getProperty(DOCKER_IO_DOCKER_CFG_PATH_PROPERTY))
383394
.withMaxPerRouteConnections(integerValue(p.getProperty(DOCKER_IO_MAX_PER_ROUTE_PROPERTY)))
@@ -442,6 +453,11 @@ public final DockerClientConfigBuilder withLoggingFilter(boolean loggingFilterEn
442453
return this;
443454
}
444455

456+
public final DockerClientConfigBuilder withFollowRedirectsFilter(boolean followRedirectsFilterEnabled) {
457+
this.followRedirectsFilterEnabled = followRedirectsFilterEnabled;
458+
return this;
459+
}
460+
445461
public final DockerClientConfigBuilder withDockerCertPath(String dockerCertPath) {
446462
this.sslConfig = new LocalDirectorySSLConfig(dockerCertPath);
447463
return this;
@@ -469,6 +485,7 @@ public DockerClientConfig build() {
469485
dockerCfgPath,
470486
readTimeout,
471487
loggingFilterEnabled,
488+
followRedirectsFilterEnabled,
472489
sslConfig,
473490
maxTotalConnections,
474491
maxPerRouteConnections
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.github.dockerjava.core.util;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
6+
import javax.ws.rs.client.ClientRequestContext;
7+
import javax.ws.rs.client.ClientResponseContext;
8+
import javax.ws.rs.client.ClientResponseFilter;
9+
import javax.ws.rs.core.Response;
10+
11+
/**
12+
* Default implementation of RedirectStrategy honors the restrictions
13+
* on automatic redirection of entity enclosing methods such as POST
14+
* and PUT imposed by the HTTP specification. 302 Moved Temporarily,
15+
* 301 Moved Permanently and 307 Temporary Redirect status codes will
16+
* result in an automatic redirect of HEAD and GET methods only.
17+
*
18+
* {@link org.apache.http.impl.client.DefaultRedirectStrategy}
19+
*
20+
* This filter allows arbitrary redirection for other methods.
21+
*/
22+
public class FollowRedirectsFilter implements ClientResponseFilter {
23+
24+
@Override
25+
public void filter(ClientRequestContext requestContext,
26+
ClientResponseContext responseContext) throws IOException {
27+
if (!responseContext.getStatusInfo().getFamily().equals(Response.Status.Family.REDIRECTION)) {
28+
return;
29+
}
30+
31+
Response resp = requestContext.getClient().target(responseContext.getLocation())
32+
.request().method(requestContext.getMethod());
33+
responseContext.setEntityStream((InputStream) resp.getEntity());
34+
responseContext.setStatusInfo(resp.getStatusInfo());
35+
responseContext.setStatus(resp.getStatus());
36+
}
37+
}

src/main/java/com/github/dockerjava/core/util/ResponseStatusExceptionFilter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public void filter(ClientRequestContext requestContext, ClientResponseContext re
3737
case 200:
3838
case 201:
3939
case 204:
40-
case 301:
4140
return;
4241
case 304:
4342
throw new NotModifiedException(getBodyAsMessage(responseContext));

0 commit comments

Comments
 (0)