1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */

15
16 package software.amazon.awssdk.http.apache.internal.impl;
17
18 import java.io.IOException;
19 import org.apache.http.HttpHost;
20 import org.apache.http.HttpRequest;
21 import org.apache.http.HttpResponse;
22 import org.apache.http.client.HttpClient;
23 import org.apache.http.client.ResponseHandler;
24 import org.apache.http.client.methods.HttpUriRequest;
25 import org.apache.http.conn.ClientConnectionManager;
26 import org.apache.http.conn.HttpClientConnectionManager;
27 import org.apache.http.params.HttpParams;
28 import org.apache.http.protocol.HttpContext;
29 import software.amazon.awssdk.annotations.SdkInternalApi;
30
31 /**
32  * An instance of {@link ConnectionManagerAwareHttpClient} that delegates all the requests to the given http client.
33  */

34 @SdkInternalApi
35 public class ApacheSdkHttpClient implements ConnectionManagerAwareHttpClient {
36
37     private final HttpClient delegate;
38
39     private final HttpClientConnectionManager cm;
40
41     public ApacheSdkHttpClient(final HttpClient delegate,
42                                final HttpClientConnectionManager cm) {
43         if (delegate == null) {
44             throw new IllegalArgumentException("delegate " +
45                                                "cannot be null");
46         }
47         if (cm == null) {
48             throw new IllegalArgumentException("connection manager " +
49                                                "cannot be null");
50         }
51         this.delegate = delegate;
52         this.cm = cm;
53     }
54
55     @Override
56     public HttpParams getParams() {
57         return delegate.getParams();
58     }
59
60     @Override
61     public ClientConnectionManager getConnectionManager() {
62         return delegate.getConnectionManager();
63     }
64
65     @Override
66     public HttpResponse execute(HttpUriRequest request) throws IOException {
67         return delegate.execute(request);
68     }
69
70     @Override
71     public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException {
72         return delegate.execute(request, context);
73     }
74
75     @Override
76     public HttpResponse execute(HttpHost target, HttpRequest request) throws IOException {
77         return delegate.execute(target, request);
78     }
79
80     @Override
81     public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException {
82         return delegate.execute(target, request, context);
83     }
84
85     @Override
86     public <T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler) throws IOException {
87         return delegate.execute(request, responseHandler);
88     }
89
90     @Override
91     public <T> T execute(HttpUriRequest request,
92                          ResponseHandler<? extends T> responseHandler,
93                          HttpContext context) throws IOException {
94         return delegate.execute(request, responseHandler, context);
95     }
96
97     @Override
98     public <T> T execute(HttpHost target,
99                          HttpRequest request,
100                          ResponseHandler<? extends T> responseHandler) throws IOException {
101         return delegate.execute(target, request, responseHandler);
102     }
103
104     @Override
105     public <T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler,
106                          HttpContext context) throws IOException {
107         return delegate.execute(target, request, responseHandler, context);
108     }
109
110     @Override
111     public HttpClientConnectionManager getHttpClientConnectionManager() {
112         return cm;
113     }
114 }
115