99import com .sun .jersey .api .client .config .DefaultClientConfig ;
1010import com .sun .jersey .api .json .JSONConfiguration ;
1111import com .sun .jersey .client .apache4 .ApacheHttpClient4 ;
12+ import com .sun .jersey .client .apache4 .ApacheHttpClient4Handler ;
1213import com .sun .jersey .core .util .MultivaluedMapImpl ;
1314import org .apache .commons .io .FileUtils ;
1415import org .apache .commons .lang .StringUtils ;
16+ import org .apache .http .client .HttpClient ;
17+ import org .apache .http .conn .scheme .PlainSocketFactory ;
18+ import org .apache .http .conn .scheme .Scheme ;
19+ import org .apache .http .conn .scheme .SchemeRegistry ;
20+ import org .apache .http .impl .client .DefaultHttpClient ;
21+ import org .apache .http .impl .conn .PoolingClientConnectionManager ;
1522import org .codehaus .jettison .json .JSONException ;
1623import org .codehaus .jettison .json .JSONObject ;
1724import org .slf4j .Logger ;
@@ -43,12 +50,23 @@ public DockerClient(String serverUrl) {
4350 restEndpointUrl = serverUrl + "/v1.3" ;
4451 ClientConfig clientConfig = new DefaultClientConfig ();
4552 clientConfig .getFeatures ().put (JSONConfiguration .FEATURE_POJO_MAPPING , Boolean .TRUE );
46- client = ApacheHttpClient4 .create (clientConfig );
53+
54+ SchemeRegistry schemeRegistry = new SchemeRegistry ();
55+ schemeRegistry .register (new Scheme ("http" , 4243 , PlainSocketFactory .getSocketFactory ()));
56+
57+ PoolingClientConnectionManager cm = new PoolingClientConnectionManager (schemeRegistry );
58+ // Increase max total connection
59+ cm .setMaxTotal (1000 );
60+ // Increase default max connection per route
61+ cm .setDefaultMaxPerRoute (1000 );
62+
63+ HttpClient httpClient = new DefaultHttpClient (cm );
64+ client = new ApacheHttpClient4 (new ApacheHttpClient4Handler (httpClient , null , false ), clientConfig );
65+
4766 client .addFilter (new JsonClientFilter ());
4867 //client.addFilter(new LoggingFilter());
4968 }
5069
51-
5270 /**
5371 ** MISC API
5472 **
@@ -91,15 +109,15 @@ public Version version() throws DockerException {
91109 **
92110 **/
93111
94- public String pull (String repository ) throws DockerException {
112+ public ClientResponse pull (String repository ) throws DockerException {
95113 return this .pull (repository , null , null );
96114 }
97115
98- public String pull (String repository , String tag ) throws DockerException {
116+ public ClientResponse pull (String repository , String tag ) throws DockerException {
99117 return this .pull (repository , tag , null );
100118 }
101119
102- public String pull (String repository , String tag , String registry ) throws DockerException {
120+ public ClientResponse pull (String repository , String tag , String registry ) throws DockerException {
103121 Preconditions .checkNotNull (repository , "Repository was not specified" );
104122
105123 if (StringUtils .countMatches (repository , ":" ) == 1 ) {
@@ -118,7 +136,7 @@ public String pull(String repository, String tag, String registry) throws Docker
118136
119137 try {
120138 LOGGER .trace ("POST: " + webResource .toString ());
121- return webResource .accept (MediaType .APPLICATION_JSON ).post (String .class );
139+ return webResource .accept (MediaType .APPLICATION_OCTET_STREAM_TYPE ).post (ClientResponse .class );
122140 } catch (UniformInterfaceException exception ) {
123141 if (exception .getResponse ().getStatus () == 500 ) {
124142 throw new DockerException ("Server error." , exception );
@@ -424,11 +442,7 @@ public ClientResponse logContainer(String containerId) throws DockerException {
424442 params .add ("logs" , "1" );
425443 params .add ("stdout" , "1" );
426444 params .add ("stderr" , "1" );
427- //params.add("stream", "1");
428-
429- Client client = Client .create ();
430- ClientConfig clientConfig = new DefaultClientConfig ();
431- clientConfig .getFeatures ().put (JSONConfiguration .FEATURE_POJO_MAPPING , Boolean .TRUE );
445+ params .add ("stream" , "1" );
432446
433447 WebResource webResource = client .resource (restEndpointUrl + String .format ("/containers/%s/attach" , containerId ))
434448 .queryParams (params );
@@ -580,10 +594,6 @@ public ClientResponse build(File dockerFolder, String tag) throws DockerExceptio
580594 //We need to use Jersey HttpClient here, since ApacheHttpClient4 will not add boundary filed to
581595 //Content-Type: multipart/form-data; boundary=Boundary_1_372491238_1372806136625
582596
583- Client client = Client .create ();
584- ClientConfig clientConfig = new DefaultClientConfig ();
585- clientConfig .getFeatures ().put (JSONConfiguration .FEATURE_POJO_MAPPING , Boolean .TRUE );
586-
587597 MultivaluedMap <String ,String > params = new MultivaluedMapImpl ();
588598 params .add ("t" , tag );
589599
0 commit comments