|
5 | 5 | import com.kpelykh.docker.client.utils.CompressArchiveUtil; |
6 | 6 | import com.kpelykh.docker.client.utils.JsonClientFilter; |
7 | 7 | import com.sun.jersey.api.client.*; |
| 8 | +import com.sun.jersey.api.client.WebResource.Builder; |
8 | 9 | import com.sun.jersey.api.client.config.ClientConfig; |
9 | 10 | import com.sun.jersey.api.client.config.DefaultClientConfig; |
10 | 11 | import com.sun.jersey.api.json.JSONConfiguration; |
@@ -343,7 +344,12 @@ public void startContainer(String containerId, HostConfig hostConfig) throws Doc |
343 | 344 |
|
344 | 345 | try { |
345 | 346 | LOGGER.trace("POST: " + webResource.toString()); |
346 | | - webResource.accept(MediaType.TEXT_PLAIN).post(hostConfig); |
| 347 | + Builder builder = webResource.accept(MediaType.TEXT_PLAIN); |
| 348 | + if (hostConfig != null) { |
| 349 | + builder.type(MediaType.APPLICATION_JSON).post(hostConfig); |
| 350 | + } else { |
| 351 | + builder.post((HostConfig) null); |
| 352 | + } |
347 | 353 | } catch (UniformInterfaceException exception) { |
348 | 354 | if (exception.getResponse().getStatus() == 404) { |
349 | 355 | throw new DockerException(String.format("No such container %s", containerId)); |
@@ -437,11 +443,21 @@ public int waitContainer(String containerId) throws DockerException { |
437 | 443 |
|
438 | 444 |
|
439 | 445 | public ClientResponse logContainer(String containerId) throws DockerException { |
| 446 | + return logContainer(containerId, false); |
| 447 | + } |
| 448 | + |
| 449 | + public ClientResponse logContainerStream(String containerId) throws DockerException { |
| 450 | + return logContainer(containerId, true); |
| 451 | + } |
| 452 | + |
| 453 | + private ClientResponse logContainer(String containerId, boolean stream) throws DockerException { |
440 | 454 | MultivaluedMap<String,String> params = new MultivaluedMapImpl(); |
441 | 455 | params.add("logs", "1"); |
442 | 456 | params.add("stdout", "1"); |
443 | 457 | params.add("stderr", "1"); |
444 | | - //params.add("stream", "1"); this parameter keeps stream open indindefinitely |
| 458 | + if (stream) { |
| 459 | + params.add("stream", "1"); // this parameter keeps stream open indefinitely |
| 460 | + } |
445 | 461 |
|
446 | 462 | WebResource webResource = client.resource(restEndpointUrl + String.format("/containers/%s/attach", containerId)) |
447 | 463 | .queryParams(params); |
|
0 commit comments