Skip to content

Commit e4a6f85

Browse files
author
Sean Fitts
committed
Backport the new structure to Jersey 1.18
This ressurects the previous Jersey 1.18 implementation in the new structure. The Jersey 2.x implementation is still here, but has been moved to the jaxrs2 package which currently is not built. Eventually these could be split into separate modules which could be combined as desired, but there is still a bit more work to do for that to work.
1 parent 328d345 commit e4a6f85

82 files changed

Lines changed: 1976 additions & 76 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@
5050

5151
<version.slf4j>1.6.1</version.slf4j>
5252

53-
<jersey.version>2.11</jersey.version>
53+
<jersey.version>1.18</jersey.version>
5454
<jersey-apache-client4.version>1.9</jersey-apache-client4.version>
5555

5656
<jackson-jaxrs.version>2.3.3</jackson-jaxrs.version>
5757

5858
<httpclient.version>4.2.5</httpclient.version>
5959
<commons-compress.version>1.5</commons-compress.version>
60-
<commons-codec.version>1.8</commons-codec.version>
60+
<commons-codec.version>1.8</commons-codec.version>
6161
<commons-io.version>2.3</commons-io.version>
6262
<commons-lang.version>2.6</commons-lang.version>
6363
<slf4j-api.version>1.7.5</slf4j-api.version>
@@ -87,16 +87,44 @@
8787
<artifactId>jackson-jaxrs-json-provider</artifactId>
8888
<version>${jackson-jaxrs.version}</version>
8989
</dependency>
90-
<!-- <dependency> -->
91-
<!-- <groupId>org.glassfish.jersey.connectors</groupId> -->
92-
<!-- <artifactId>jersey-jetty-connector</artifactId> -->
93-
<!-- <version>${jersey.version}</version> -->
94-
<!-- </dependency> -->
95-
<dependency>
96-
<groupId>org.glassfish.jersey.core</groupId>
97-
<artifactId>jersey-client</artifactId>
98-
<version>${jersey.version}</version>
99-
</dependency>
90+
91+
<!-- Jersey 2.x dependencies
92+
<dependency>
93+
<groupId>org.glassfish.jersey.core</groupId>
94+
<artifactId>jersey-client</artifactId>
95+
<version>${jersey.version}</version>
96+
</dependency>
97+
-->
98+
99+
<!-- Begin Jersey 1.18 dependencies -->
100+
<dependency>
101+
<groupId>com.sun.jersey</groupId>
102+
<artifactId>jersey-core</artifactId>
103+
<version>${jersey.version}</version>
104+
</dependency>
105+
<dependency>
106+
<groupId>com.sun.jersey</groupId>
107+
<artifactId>jersey-client</artifactId>
108+
<version>${jersey.version}</version>
109+
</dependency>
110+
111+
<dependency>
112+
<groupId>com.sun.jersey.contribs</groupId>
113+
<artifactId>jersey-multipart</artifactId>
114+
<version>${jersey.version}</version>
115+
</dependency>
116+
<dependency>
117+
<groupId>com.sun.jersey.contribs</groupId>
118+
<artifactId>jersey-apache-client4</artifactId>
119+
<version>${jersey-apache-client4.version}</version>
120+
</dependency>
121+
122+
<dependency>
123+
<groupId>org.apache.httpcomponents</groupId>
124+
<artifactId>httpclient</artifactId>
125+
<version>${httpclient.version}</version>
126+
</dependency>
127+
<!-- End Jersey 1.18 dependencies -->
100128

101129
<dependency>
102130
<groupId>org.apache.commons</groupId>
@@ -138,10 +166,10 @@
138166
</dependency>
139167

140168
<dependency>
141-
<groupId>com.google.guava</groupId>
142-
<artifactId>guava</artifactId>
143-
<version>${guava.version}</version>
144-
</dependency>
169+
<groupId>com.google.guava</groupId>
170+
<artifactId>guava</artifactId>
171+
<version>${guava.version}</version>
172+
</dependency>
145173

146174
<!-- /// Test /////////////////////////// -->
147175
<dependency>
@@ -240,6 +268,15 @@
240268
<encoding>ISO-8859-1</encoding>
241269
<debug>${jdk.debug}</debug>
242270
<optimize>${jdk.optimize}</optimize>
271+
272+
<!-- Exclude the Jersey 2.x code until both it and the 1.18 code can coexist -->
273+
<excludes>
274+
<exclude>**/jaxrs2/*.java</exclude>
275+
<exclude>**/jaxrs2/util/*.java</exclude>
276+
</excludes>
277+
<testExcludes>
278+
<exclude>**/jaxrs2/*.java</exclude>
279+
</testExcludes>
243280
</configuration>
244281
</plugin>
245282

@@ -338,6 +375,7 @@
338375
<id>release</id>
339376
<build>
340377
<plugins>
378+
<!--
341379
<plugin>
342380
<groupId>org.apache.maven.plugins</groupId>
343381
<artifactId>maven-gpg-plugin</artifactId>
@@ -351,6 +389,7 @@
351389
</execution>
352390
</executions>
353391
</plugin>
392+
-->
354393

355394
<plugin>
356395
<groupId>org.apache.maven.plugins</groupId>

src/main/java/com/github/dockerjava/core/command/CopyFileFromContainerCmdImpl.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,4 @@ public InputStream exec() throws NotFoundException {
8585
return super.exec();
8686
}
8787

88-
// protected InputStream impl() throws DockerException {
89-
//
90-
// CopyFileFromContainerCmd command = this;
91-
//
92-
// WebTarget webResource =
93-
// baseResource.path("/containers/{id}/copy").resolveTemplate("id", command.getContainerId());
94-
//
95-
// LOGGER.trace("POST: " + webResource.toString());
96-
//
97-
// return webResource.request().accept(MediaType.APPLICATION_OCTET_STREAM_TYPE).post(entity(command, MediaType.APPLICATION_JSON), Response.class).readEntity(InputStream.class);
98-
// }
99-
100-
10188
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.github.dockerjava.jaxrs1;
2+
3+
import java.io.IOException;
4+
5+
import org.apache.commons.codec.binary.Base64;
6+
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import com.github.dockerjava.api.DockerException;
9+
import com.github.dockerjava.api.command.DockerCmd;
10+
import com.github.dockerjava.api.command.DockerCmdExec;
11+
import com.github.dockerjava.api.model.AuthConfig;
12+
import com.google.common.base.Preconditions;
13+
import com.sun.jersey.api.client.ClientHandlerException;
14+
import com.sun.jersey.api.client.WebResource;
15+
import com.sun.jersey.api.uri.UriTemplate;
16+
17+
public abstract class AbstrDockerCmdExec<CMD_T extends DockerCmd<RES_T>, RES_T>
18+
implements DockerCmdExec<CMD_T, RES_T> {
19+
20+
private WebResource baseResource;
21+
22+
public AbstrDockerCmdExec(WebResource baseResource) {
23+
Preconditions.checkNotNull(baseResource,
24+
"baseResource was not specified");
25+
this.baseResource = baseResource;
26+
}
27+
28+
protected WebResourceBuilder getBaseResource() {
29+
return new WebResourceBuilder(baseResource);
30+
}
31+
32+
public static class WebResourceBuilder {
33+
WebResource resource;
34+
35+
private WebResourceBuilder(WebResource resource) {
36+
this.resource = resource;
37+
}
38+
39+
public WebResourceBuilder path(String pathStr) {
40+
this.resource = this.resource.path(pathStr);
41+
return this;
42+
}
43+
44+
public WebResourceBuilder resolveTemplate(String path, String... values) {
45+
UriTemplate tmplt = new UriTemplate(path);
46+
this.resource = this.resource.path(tmplt.createURI(values));
47+
return this;
48+
}
49+
50+
public WebResourceBuilder queryParam(String name, String value) {
51+
if (value != null) {
52+
this.resource = this.resource.queryParam(name, value);
53+
}
54+
return this;
55+
}
56+
57+
public WebResource build() {
58+
return this.resource;
59+
}
60+
}
61+
62+
protected String registryAuth(AuthConfig authConfig) {
63+
try {
64+
return Base64.encodeBase64String(new ObjectMapper()
65+
.writeValueAsString(authConfig).getBytes());
66+
} catch (IOException e) {
67+
throw new RuntimeException(e);
68+
}
69+
}
70+
71+
public RES_T exec(CMD_T command) {
72+
// this hack works because of ResponseStatusExceptionFilter
73+
RES_T result;
74+
try {
75+
result = execute(command);
76+
} catch (ClientHandlerException e) {
77+
if(e.getCause() instanceof DockerException) {
78+
throw (DockerException)e.getCause();
79+
} else {
80+
throw e;
81+
}
82+
}
83+
return result;
84+
}
85+
86+
protected abstract RES_T execute(CMD_T command);
87+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.github.dockerjava.jaxrs1;
2+
3+
import java.io.InputStream;
4+
5+
import javax.ws.rs.core.MediaType;
6+
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
10+
import com.github.dockerjava.api.command.AttachContainerCmd;
11+
import com.sun.jersey.api.client.WebResource;
12+
13+
public class AttachContainerCmdExec extends AbstrDockerCmdExec<AttachContainerCmd, InputStream> implements AttachContainerCmd.Exec {
14+
15+
private static final Logger LOGGER = LoggerFactory
16+
.getLogger(AttachContainerCmdExec.class);
17+
18+
public AttachContainerCmdExec(WebResource baseResource) {
19+
super(baseResource);
20+
}
21+
22+
@Override
23+
protected InputStream execute(AttachContainerCmd command) {
24+
WebResource webResource = getBaseResource()
25+
.resolveTemplate("/containers/{id}/attach", command.getContainerId())
26+
.queryParam("logs", command.hasLogsEnabled() ? "1" : "0")
27+
.queryParam("stdout", command.hasStdoutEnabled() ? "1" : "0")
28+
.queryParam("stderr", command.hasStderrEnabled() ? "1" : "0")
29+
.queryParam("stream", command.hasFollowStreamEnabled() ? "1" : "0")
30+
.build();
31+
32+
LOGGER.trace("POST: {}", webResource);
33+
34+
return webResource.accept(MediaType.APPLICATION_OCTET_STREAM_TYPE)
35+
.entity(null, MediaType.APPLICATION_JSON)
36+
.post(InputStream.class);
37+
}
38+
39+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.github.dockerjava.jaxrs1;
2+
3+
import javax.ws.rs.core.MediaType;
4+
import javax.ws.rs.core.Response;
5+
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import com.github.dockerjava.api.UnauthorizedException;
10+
import com.github.dockerjava.api.command.AuthCmd;
11+
import com.sun.jersey.api.client.WebResource;
12+
13+
public class AuthCmdExec extends AbstrDockerCmdExec<AuthCmd, Void> implements AuthCmd.Exec {
14+
15+
private static final Logger LOGGER = LoggerFactory
16+
.getLogger(AuthCmdExec.class);
17+
18+
public AuthCmdExec(WebResource baseResource) {
19+
super(baseResource);
20+
}
21+
22+
@Override
23+
protected Void execute(AuthCmd command) {
24+
WebResource webResource = getBaseResource().path("/auth").build();
25+
LOGGER.trace("POST: {}", webResource);
26+
Response response = webResource
27+
.accept(MediaType.APPLICATION_JSON)
28+
.entity(command.getAuthConfig(), MediaType.APPLICATION_JSON)
29+
.post(Response.class);
30+
31+
if(response.getStatus() == 401) {
32+
throw new UnauthorizedException("Unauthorized");
33+
};
34+
35+
return null;
36+
}
37+
38+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.github.dockerjava.jaxrs1;
2+
3+
import java.io.InputStream;
4+
5+
import javax.ws.rs.core.MediaType;
6+
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
10+
import com.github.dockerjava.api.command.BuildImageCmd;
11+
import com.sun.jersey.api.client.WebResource;
12+
13+
public class BuildImageCmdExec extends AbstrDockerCmdExec<BuildImageCmd, InputStream> implements BuildImageCmd.Exec {
14+
15+
private static final Logger LOGGER = LoggerFactory
16+
.getLogger(BuildImageCmdExec.class);
17+
18+
public BuildImageCmdExec(WebResource baseResource) {
19+
super(baseResource);
20+
}
21+
22+
@Override
23+
protected InputStream execute(BuildImageCmd command) {
24+
WebResource webResource = getBaseResource().path("/build").build();
25+
26+
if(command.getTag() != null) {
27+
webResource = webResource.queryParam("t", command.getTag());
28+
}
29+
if (command.hasNoCacheEnabled()) {
30+
webResource = webResource.queryParam("nocache", "true");
31+
}
32+
if (command.hasRemoveEnabled()) {
33+
webResource = webResource.queryParam("rm", "true");
34+
}
35+
if (command.isQuiet()) {
36+
webResource = webResource.queryParam("q", "true");
37+
}
38+
39+
LOGGER.debug("POST: {}", webResource);
40+
return webResource
41+
.accept(MediaType.TEXT_PLAIN)
42+
.entity(command.getTarInputStream(), "application/tar")
43+
.post(InputStream.class);
44+
45+
}
46+
47+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.github.dockerjava.jaxrs1;
2+
3+
import javax.ws.rs.core.MediaType;
4+
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
import com.fasterxml.jackson.databind.node.ObjectNode;
9+
import com.github.dockerjava.api.command.CommitCmd;
10+
import com.sun.jersey.api.client.WebResource;
11+
12+
public class CommitCmdExec extends AbstrDockerCmdExec<CommitCmd, String> implements CommitCmd.Exec {
13+
14+
private static final Logger LOGGER = LoggerFactory
15+
.getLogger(CommitCmdExec.class);
16+
17+
public CommitCmdExec(WebResource baseResource) {
18+
super(baseResource);
19+
}
20+
21+
@Override
22+
protected String execute(CommitCmd command) {
23+
WebResource webResource = getBaseResource()
24+
.path("/commit")
25+
.queryParam("container", command.getContainerId())
26+
.queryParam("repo", command.getRepository())
27+
.queryParam("tag", command.getTag())
28+
.queryParam("m", command.getMessage())
29+
.queryParam("author", command.getAuthor())
30+
.queryParam("pause", command.hasPauseEnabled() ? "1" : "0")
31+
.build();
32+
33+
LOGGER.trace("POST: {}", webResource);
34+
ObjectNode objectNode = webResource
35+
.accept("application/vnd.docker.raw-stream")
36+
.entity(command, MediaType.APPLICATION_JSON)
37+
.post(ObjectNode.class);
38+
return objectNode.get("Id").asText();
39+
}
40+
41+
}

0 commit comments

Comments
 (0)