Skip to content

Commit c8ab23f

Browse files
tejksatKostyaSha
authored andcommitted
Fix for #670 (#680)
JSON decoding disabled on /images/load command execution.
1 parent 75309ff commit c8ab23f

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/main/java/com/github/dockerjava/netty/InvocationBuilder.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ public void onNext(T object) {
6969
}
7070
}
7171

72+
public class SkipResultCallback extends ResultCallbackTemplate<ResponseCallback<Void>, Void> {
73+
@Override
74+
public void onNext(Void object) {
75+
}
76+
}
77+
7278
private ChannelProvider channelProvider;
7379

7480
private String resource;
@@ -401,6 +407,31 @@ public <T> void post(TypeReference<T> typeReference, ResultCallback<T> resultCal
401407
channel.pipeline().addLast(new JsonObjectDecoder());
402408
channel.pipeline().addLast(jsonResponseHandler);
403409

410+
postChunkedStreamRequest(requestProvider, channel, body);
411+
}
412+
413+
public void postStream(InputStream body) {
414+
SkipResultCallback resultCallback = new SkipResultCallback();
415+
416+
HttpRequestProvider requestProvider = httpPostRequestProvider(null);
417+
418+
Channel channel = getChannel();
419+
420+
HttpResponseHandler responseHandler = new HttpResponseHandler(requestProvider, resultCallback);
421+
422+
channel.pipeline().addLast(new ChunkedWriteHandler());
423+
channel.pipeline().addLast(responseHandler);
424+
425+
postChunkedStreamRequest(requestProvider, channel, body);
426+
427+
try {
428+
resultCallback.awaitCompletion();
429+
} catch (InterruptedException e) {
430+
throw new RuntimeException(e);
431+
}
432+
}
433+
434+
private void postChunkedStreamRequest(HttpRequestProvider requestProvider, Channel channel, InputStream body) {
404435
HttpRequest request = requestProvider.getHttpRequest(resource);
405436

406437
// don't accept FullHttpRequest here

src/main/java/com/github/dockerjava/netty/exec/LoadImageCmdExec.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
55

6-
import com.fasterxml.jackson.core.type.TypeReference;
76
import com.github.dockerjava.api.command.LoadImageCmd;
87
import com.github.dockerjava.core.DockerClientConfig;
98
import com.github.dockerjava.netty.WebTarget;
@@ -22,8 +21,8 @@ protected Void execute(LoadImageCmd command) {
2221
WebTarget webResource = getBaseResource().path("/images/load");
2322

2423
LOGGER.trace("POST: {}", webResource);
25-
return webResource.request()
26-
.post(new TypeReference<Void>() {
27-
}, command.getImageStream());
24+
webResource.request().postStream(command.getImageStream());
25+
26+
return null;
2827
}
2928
}

0 commit comments

Comments
 (0)