11package com .kpelykh .docker .client ;
22
3- import com .google .common .base .Preconditions ;
4- import com .kpelykh .docker .client .model .*;
5- import com .kpelykh .docker .client .utils .CompressArchiveUtil ;
6- import com .kpelykh .docker .client .utils .JsonClientFilter ;
7- import com .sun .jersey .api .client .*;
8- import com .sun .jersey .api .client .WebResource .Builder ;
9- import com .sun .jersey .api .client .config .ClientConfig ;
10- import com .sun .jersey .api .client .config .DefaultClientConfig ;
11- import com .sun .jersey .api .client .filter .LoggingFilter ;
12- import com .sun .jersey .api .json .JSONConfiguration ;
13- import com .sun .jersey .client .apache4 .ApacheHttpClient4 ;
14- import com .sun .jersey .client .apache4 .ApacheHttpClient4Handler ;
15- import com .sun .jersey .core .util .MultivaluedMapImpl ;
3+ import java .io .File ;
4+ import java .io .IOException ;
5+ import java .io .InputStream ;
6+ import java .util .HashMap ;
7+ import java .util .List ;
8+ import java .util .UUID ;
9+
10+ import javax .ws .rs .core .MediaType ;
11+ import javax .ws .rs .core .MultivaluedMap ;
12+
1613import org .apache .commons .io .FileUtils ;
1714import org .apache .commons .lang .StringUtils ;
1815import org .apache .http .client .HttpClient ;
2623import org .slf4j .Logger ;
2724import org .slf4j .LoggerFactory ;
2825
29- import javax .ws .rs .core .MediaType ;
30- import javax .ws .rs .core .MultivaluedMap ;
31- import java .io .File ;
32- import java .io .IOException ;
33- import java .util .List ;
34- import java .util .UUID ;
26+ import com .google .common .base .Preconditions ;
27+ import com .kpelykh .docker .client .model .ChangeLog ;
28+ import com .kpelykh .docker .client .model .CommitConfig ;
29+ import com .kpelykh .docker .client .model .Container ;
30+ import com .kpelykh .docker .client .model .ContainerConfig ;
31+ import com .kpelykh .docker .client .model .ContainerCreateResponse ;
32+ import com .kpelykh .docker .client .model .ContainerInspectResponse ;
33+ import com .kpelykh .docker .client .model .HostConfig ;
34+ import com .kpelykh .docker .client .model .Image ;
35+ import com .kpelykh .docker .client .model .ImageInspectResponse ;
36+ import com .kpelykh .docker .client .model .Info ;
37+ import com .kpelykh .docker .client .model .SearchItem ;
38+ import com .kpelykh .docker .client .model .Version ;
39+ import com .kpelykh .docker .client .utils .CompressArchiveUtil ;
40+ import com .kpelykh .docker .client .utils .JsonClientFilter ;
41+ import com .sun .jersey .api .client .Client ;
42+ import com .sun .jersey .api .client .ClientResponse ;
43+ import com .sun .jersey .api .client .GenericType ;
44+ import com .sun .jersey .api .client .UniformInterfaceException ;
45+ import com .sun .jersey .api .client .WebResource ;
46+ import com .sun .jersey .api .client .WebResource .Builder ;
47+ import com .sun .jersey .api .client .config .ClientConfig ;
48+ import com .sun .jersey .api .client .config .DefaultClientConfig ;
49+ import com .sun .jersey .api .client .filter .LoggingFilter ;
50+ import com .sun .jersey .api .json .JSONConfiguration ;
51+ import com .sun .jersey .client .apache4 .ApacheHttpClient4 ;
52+ import com .sun .jersey .client .apache4 .ApacheHttpClient4Handler ;
53+ import com .sun .jersey .core .util .MultivaluedMapImpl ;
3554
3655/**
3756 *
@@ -48,7 +67,7 @@ public class DockerClient
4867 private String restEndpointUrl ;
4968
5069 public DockerClient (String serverUrl ) {
51- restEndpointUrl = serverUrl + "/v1.8 " ;
70+ restEndpointUrl = serverUrl + "/v1.10 " ;
5271 ClientConfig clientConfig = new DefaultClientConfig ();
5372 clientConfig .getFeatures ().put (JSONConfiguration .FEATURE_POJO_MAPPING , Boolean .TRUE );
5473
@@ -696,4 +715,28 @@ public ClientResponse build(File dockerFolder, String tag) throws DockerExceptio
696715
697716 }
698717
718+ public InputStream copyFile (String containerId , String resource ) throws DockerException {
719+
720+ HashMap <String ,String > params = new HashMap <String ,String >();
721+ params .put ("Resource" , resource );
722+
723+ WebResource webResource = client .resource (restEndpointUrl + String .format ("/containers/%s/copy" , containerId ));
724+
725+ try {
726+ LOGGER .trace ("POST: {}" , webResource );
727+ return webResource .accept (MediaType .APPLICATION_OCTET_STREAM_TYPE ).entity (params , MediaType .APPLICATION_JSON ).post (InputStream .class );
728+ } catch (UniformInterfaceException exception ) {
729+ if (exception .getResponse ().getStatus () == 400 ) {
730+ throw new DockerException ("bad parameter" );
731+ } else if (exception .getResponse ().getStatus () == 404 ) {
732+ throw new DockerException (String .format ("No such container %s" , containerId ));
733+ } else if (exception .getResponse ().getStatus () == 500 ) {
734+ throw new DockerException ("Server error" , exception );
735+ } else {
736+ throw new DockerException (exception );
737+ }
738+ }
739+
740+ }
741+
699742}
0 commit comments