|
| 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 | +} |
0 commit comments