Skip to content

Commit 778ff9b

Browse files
committed
Merge branch '__rultor'
2 parents f3a8549 + f97da02 commit 778ff9b

File tree

7 files changed

+204
-209
lines changed

7 files changed

+204
-209
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/**
2+
* Copyright (c) 2018, Mihai Emil Andronache
3+
* All rights reserved.
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
* 1)Redistributions of source code must retain the above copyright notice,
7+
* this list of conditions and the following disclaimer.
8+
* 2)Redistributions in binary form must reproduce the above copyright notice,
9+
* this list of conditions and the following disclaimer in the documentation
10+
* and/or other materials provided with the distribution.
11+
* 3)Neither the name of docker-java-api nor the names of its
12+
* contributors may be used to endorse or promote products derived from
13+
* this software without specific prior written permission.
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24+
* POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
package com.amihaiemil.docker;
27+
28+
import java.io.IOException;
29+
import java.util.function.Supplier;
30+
import org.apache.http.HttpHost;
31+
import org.apache.http.HttpRequest;
32+
import org.apache.http.HttpResponse;
33+
import org.apache.http.client.ClientProtocolException;
34+
import org.apache.http.client.HttpClient;
35+
import org.apache.http.client.ResponseHandler;
36+
import org.apache.http.client.methods.HttpUriRequest;
37+
import org.apache.http.conn.ClientConnectionManager;
38+
import org.apache.http.params.HttpParams;
39+
import org.apache.http.protocol.HttpContext;
40+
41+
/**
42+
* HTTP client envelope.
43+
*
44+
* @author George Aristy ([email protected])
45+
* @version $Id$
46+
* @since 0.0.4
47+
*/
48+
abstract class HttpClientEnvelope implements HttpClient {
49+
/**
50+
* Actual HttpClient.
51+
*/
52+
private final HttpClient enveloped;
53+
54+
/**
55+
* Ctor.
56+
* @param enveloped The concrete http client
57+
*/
58+
HttpClientEnvelope(final Supplier<HttpClient> enveloped) {
59+
this.enveloped = enveloped.get();
60+
}
61+
62+
@Override
63+
public HttpParams getParams() {
64+
return this.enveloped.getParams();
65+
}
66+
67+
@Override
68+
public ClientConnectionManager getConnectionManager() {
69+
return this.enveloped.getConnectionManager();
70+
}
71+
72+
@Override
73+
public HttpResponse execute(final HttpUriRequest request)
74+
throws IOException, ClientProtocolException {
75+
return this.enveloped.execute(request);
76+
}
77+
78+
@Override
79+
public HttpResponse execute(final HttpUriRequest request,
80+
final HttpContext context)
81+
throws IOException, ClientProtocolException {
82+
return this.enveloped.execute(request, context);
83+
}
84+
85+
@Override
86+
public HttpResponse execute(final HttpHost target,
87+
final HttpRequest request)
88+
throws IOException, ClientProtocolException {
89+
return this.enveloped.execute(target, request);
90+
}
91+
92+
@Override
93+
public HttpResponse execute(final HttpHost target,
94+
final HttpRequest request, final HttpContext context)
95+
throws IOException, ClientProtocolException {
96+
return this.enveloped.execute(target, request, context);
97+
}
98+
99+
@Override
100+
public <T> T execute(final HttpUriRequest request,
101+
final ResponseHandler<? extends T> responseHandler)
102+
throws IOException, ClientProtocolException {
103+
return this.enveloped.execute(request, responseHandler);
104+
}
105+
106+
@Override
107+
public <T> T execute(final HttpUriRequest request,
108+
final ResponseHandler<? extends T> responseHandler,
109+
final HttpContext context) throws IOException, ClientProtocolException {
110+
return this.enveloped.execute(request, responseHandler, context);
111+
}
112+
113+
@Override
114+
public <T> T execute(final HttpHost target, final HttpRequest request,
115+
final ResponseHandler<? extends T> responseHandler)
116+
throws IOException, ClientProtocolException {
117+
return this.enveloped.execute(target, request, responseHandler);
118+
}
119+
120+
// @checkstyle ParameterNumber (2 lines)
121+
@Override
122+
public <T> T execute(final HttpHost target, final HttpRequest request,
123+
final ResponseHandler<? extends T> responseHandler,
124+
final HttpContext context) throws IOException, ClientProtocolException {
125+
return this.enveloped.execute(
126+
target, request, responseHandler, context
127+
);
128+
}
129+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright (c) 2018, Mihai Emil Andronache
3+
* All rights reserved.
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
* 1)Redistributions of source code must retain the above copyright notice,
7+
* this list of conditions and the following disclaimer.
8+
* 2)Redistributions in binary form must reproduce the above copyright notice,
9+
* this list of conditions and the following disclaimer in the documentation
10+
* and/or other materials provided with the distribution.
11+
* 3)Neither the name of docker-java-api nor the names of its
12+
* contributors may be used to endorse or promote products derived from
13+
* this software without specific prior written permission.
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24+
* POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
package com.amihaiemil.docker;
27+
28+
import org.apache.http.impl.client.HttpClients;
29+
30+
/**
31+
* Plain HTTP (no TLS) client.
32+
*
33+
* @author George Aristy ([email protected])
34+
* @version $Id$
35+
* @since 0.0.4
36+
*/
37+
final class PlainHttpClient extends HttpClientEnvelope {
38+
/**
39+
* Ctor.
40+
*/
41+
PlainHttpClient() {
42+
super(() -> HttpClients.custom()
43+
.setMaxConnPerRoute(10)
44+
.setMaxConnTotal(10)
45+
.build()
46+
);
47+
}
48+
}

src/main/java/com/amihaiemil/docker/RemoteDocker.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ public final class RemoteDocker extends RtDocker {
7676
);
7777
}
7878

79+
/**
80+
* Remote Docker engine.
81+
*
82+
* An insecure docker API v1.35 endpoint is assumed.
83+
*
84+
* @param uri Remote Docker URI.
85+
*/
86+
public RemoteDocker(final URI uri) {
87+
this(new PlainHttpClient(), uri);
88+
}
89+
7990
/**
8091
* Remote Docker engine. You have to configure your own HttpClient,
8192
* most likely with some authentication mechanism, depending on where

src/main/java/com/amihaiemil/docker/SslHttpClient.java

Lines changed: 2 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,8 @@
3030
import java.security.GeneralSecurityException;
3131
import java.util.function.Supplier;
3232

33-
import org.apache.http.HttpHost;
34-
import org.apache.http.HttpRequest;
35-
import org.apache.http.HttpResponse;
36-
import org.apache.http.client.ClientProtocolException;
3733
import org.apache.http.client.HttpClient;
38-
import org.apache.http.client.ResponseHandler;
39-
import org.apache.http.client.methods.HttpUriRequest;
40-
import org.apache.http.conn.ClientConnectionManager;
4134
import org.apache.http.impl.client.HttpClients;
42-
import org.apache.http.params.HttpParams;
43-
import org.apache.http.protocol.HttpContext;
4435
import org.apache.http.ssl.SSLContexts;
4536

4637
/**
@@ -50,16 +41,8 @@
5041
* @version $Id$
5142
* @since 0.0.1
5243
* @checkstyle ParameterNumber (150 lines)
53-
* @todo #100:30min Add a plain HTTP client for use. It is possible
54-
* for users to disable TLS on docker's API. See
55-
* https://docs.docker.com/registry/insecure/.
5644
*/
57-
final class SslHttpClient implements HttpClient {
58-
/**
59-
* Decorated HttpClient.
60-
*/
61-
private final HttpClient origin;
62-
45+
final class SslHttpClient extends HttpClientEnvelope {
6346
/**
6447
* Ctor.
6548
* @param keys Path to the keystore.
@@ -92,79 +75,6 @@ final class SslHttpClient implements HttpClient {
9275
* @param client Decorated HttpClient.
9376
*/
9477
SslHttpClient(final Supplier<HttpClient> client) {
95-
this(client.get());
96-
}
97-
98-
/**
99-
* Ctor.
100-
* @param client Decorated HttpClient.
101-
*/
102-
SslHttpClient(final HttpClient client) {
103-
this.origin = client;
104-
}
105-
106-
@Override
107-
public HttpParams getParams() {
108-
throw new UnsupportedOperationException("Not supported yet.");
109-
}
110-
111-
@Override
112-
public ClientConnectionManager getConnectionManager() {
113-
throw new UnsupportedOperationException("Not supported yet.");
114-
}
115-
116-
@Override
117-
public HttpResponse execute(final HttpUriRequest request)
118-
throws IOException, ClientProtocolException {
119-
return this.origin.execute(request);
120-
}
121-
122-
@Override
123-
public HttpResponse execute(final HttpUriRequest request,
124-
final HttpContext context)
125-
throws IOException, ClientProtocolException {
126-
throw new UnsupportedOperationException("Not supported yet.");
127-
}
128-
129-
@Override
130-
public HttpResponse execute(final HttpHost target,
131-
final HttpRequest request)
132-
throws IOException, ClientProtocolException {
133-
throw new UnsupportedOperationException("Not supported yet.");
134-
}
135-
136-
@Override
137-
public HttpResponse execute(final HttpHost target,
138-
final HttpRequest request, final HttpContext context)
139-
throws IOException, ClientProtocolException {
140-
throw new UnsupportedOperationException("Not supported yet.");
141-
}
142-
143-
@Override
144-
public <T> T execute(final HttpUriRequest request,
145-
final ResponseHandler<? extends T> responseHandler)
146-
throws IOException, ClientProtocolException {
147-
throw new UnsupportedOperationException("Not supported yet.");
148-
}
149-
150-
@Override
151-
public <T> T execute(final HttpUriRequest request,
152-
final ResponseHandler<? extends T> responseHandler,
153-
final HttpContext context) throws IOException, ClientProtocolException {
154-
throw new UnsupportedOperationException("Not supported yet.");
155-
}
156-
157-
@Override
158-
public <T> T execute(final HttpHost target, final HttpRequest request,
159-
final ResponseHandler<? extends T> responseHandler)
160-
throws IOException, ClientProtocolException {
161-
throw new UnsupportedOperationException("Not supported yet.");
162-
}
163-
164-
@Override
165-
public <T> T execute(final HttpHost target, final HttpRequest request,
166-
final ResponseHandler<? extends T> responseHandler,
167-
final HttpContext context) throws IOException, ClientProtocolException {
168-
throw new UnsupportedOperationException("Not supported yet.");
78+
super(client);
16979
}
17080
}

0 commit comments

Comments
 (0)