Skip to content

Commit 2d828ad

Browse files
author
Marcus Linke
committed
Added AHC dependency
1 parent 5156e37 commit 2d828ad

2 files changed

Lines changed: 109 additions & 1 deletion

File tree

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23
<modelVersion>4.0.0</modelVersion>
34

45
<parent>
@@ -201,6 +202,12 @@
201202
<version>3.0.0</version>
202203
<scope>provided</scope>
203204
</dependency>
205+
206+
<dependency>
207+
<groupId>org.asynchttpclient</groupId>
208+
<artifactId>async-http-client</artifactId>
209+
<version>2.0.0-alpha22</version>
210+
</dependency>
204211
</dependencies>
205212

206213
<distributionManagement>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.github.dockerjava.ahc;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.net.URL;
5+
import java.util.concurrent.Future;
6+
7+
import com.github.dockerjava.api.async.ResultCallback;
8+
import com.github.dockerjava.api.command.AttachContainerCmd;
9+
import com.github.dockerjava.api.model.Frame;
10+
import com.github.dockerjava.core.DockerClientConfig;
11+
import com.github.dockerjava.core.async.FrameStreamProcessor;
12+
import com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier;
13+
import com.github.dockerjava.jaxrs.async.POSTCallbackNotifier;
14+
15+
import org.asynchttpclient.*;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
18+
19+
import javax.ws.rs.client.WebTarget;
20+
21+
public class AttachContainerCmdExec implements AttachContainerCmd.Exec {
22+
23+
private static final Logger LOGGER = LoggerFactory.getLogger(AttachContainerCmdExec.class);
24+
25+
private URL baseResource;
26+
27+
private DockerClientConfig dockerClientConfig;
28+
29+
public AttachContainerCmdExec(URL baseResource, DockerClientConfig dockerClientConfig) {
30+
this.baseResource = baseResource;
31+
this.dockerClientConfig = dockerClientConfig;
32+
}
33+
34+
// @Override
35+
// protected AbstractCallbackNotifier<Frame> callbackNotifier(AttachContainerCmd command,
36+
// ResultCallback<Frame> resultCallback) {
37+
//
38+
// WebTarget webTarget = getBaseResource().path("/containers/{id}/attach").resolveTemplate("id",
39+
// command.getContainerId());
40+
//
41+
// webTarget = booleanQueryParam(webTarget, "logs", command.hasLogsEnabled());
42+
// webTarget = booleanQueryParam(webTarget, "stdout", command.hasStdoutEnabled());
43+
// // webTarget = booleanQueryParam(webTarget, "stdin", command.hasStdinEnabled());
44+
// webTarget = booleanQueryParam(webTarget, "stderr", command.hasStderrEnabled());
45+
// webTarget = booleanQueryParam(webTarget, "stream", command.hasFollowStreamEnabled());
46+
//
47+
// LOGGER.trace("POST: {}", webTarget);
48+
//
49+
// return new POSTCallbackNotifier<Frame>(new FrameStreamProcessor(), resultCallback, webTarget.request(), null);
50+
// }
51+
52+
@Override
53+
public Void exec(AttachContainerCmd command, ResultCallback<Frame> resultCallback) {
54+
AsyncHttpClientConfig config = new DefaultAsyncHttpClientConfig.Builder().build();
55+
56+
AsyncHttpClient c = new DefaultAsyncHttpClient(config);
57+
c.prepareGet("http://www.ning.com/").execute(new AsyncHandler<String>() {
58+
private ByteArrayOutputStream bytes = new ByteArrayOutputStream();
59+
60+
@Override
61+
public State onStatusReceived(HttpResponseStatus status) throws Exception {
62+
int statusCode = status.getStatusCode();
63+
// The Status have been read
64+
// If you don't want to read the headers,body or stop processing the response
65+
if (statusCode >= 500) {
66+
return State.ABORT;
67+
}
68+
69+
return State.CONTINUE;
70+
}
71+
72+
@Override
73+
public State onHeadersReceived(HttpResponseHeaders h) throws Exception {
74+
75+
// The headers have been read
76+
// If you don't want to read the body, or stop processing the response
77+
return State.CONTINUE;
78+
}
79+
80+
@Override
81+
public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
82+
bytes.write(bodyPart.getBodyPartBytes());
83+
return State.CONTINUE;
84+
}
85+
86+
@Override
87+
public String onCompleted() throws Exception {
88+
// Will be invoked once the response has been fully read or a ResponseComplete exception
89+
// has been thrown.
90+
// NOTE: should probably use Content-Encoding from headers
91+
return bytes.toString("UTF-8");
92+
}
93+
94+
@Override
95+
public void onThrowable(Throwable t) {
96+
}
97+
});
98+
99+
return null;
100+
}
101+
}

0 commit comments

Comments
 (0)