AWS SDK for C++  0.12.9
AWS SDK for C++
AWSClient.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2016 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 #pragma once
17 
18 #include <aws/core/Core_EXPORTS.h>
24 #include <memory>
25 #include <atomic>
26 
27 namespace Aws
28 {
29  namespace Utils
30  {
31  template<typename R, typename E>
32  class Outcome;
33 
34  namespace Xml
35  {
36  class XmlDocument;
37  } // namespace Xml
38 
39  namespace Json
40  {
41  class JsonValue;
42  } // namespace Json
43 
44  namespace RateLimits
45  {
47  } // namespace RateLimits
48 
49  namespace Crypto
50  {
51  class MD5;
52  } // namespace Crypto
53  } // namespace Utils
54 
55  namespace Http
56  {
57  class HttpClient;
58 
59  class HttpClientFactory;
60 
61  class HttpRequest;
62 
63  class HttpResponse;
64  } // namespace Http
65 
67 
68  namespace Client
69  {
70  template<typename ERROR_TYPE>
71  class AWSError;
72  class AWSErrorMarshaller;
73  class AWSRestfulJsonErrorMarshaller;
74  class AWSAuthSigner;
75  struct ClientConfiguration;
77 
80 
85  {
86  public:
92  AWSClient(const Aws::Client::ClientConfiguration& configuration,
93  const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer,
94  const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller);
95 
96  virtual ~AWSClient();
97 
102  Aws::String GeneratePresignedUrl(Aws::Http::URI& uri, Aws::Http::HttpMethod method, long long expirationInSeconds = 0);
103 
108  void DisableRequestProcessing();
109 
113  void EnableRequestProcessing();
114 
115  protected:
120  HttpResponseOutcome AttemptExhaustively(const Aws::String& uri,
121  const Aws::AmazonWebServiceRequest& request,
122  Http::HttpMethod httpMethod) const;
123 
128  HttpResponseOutcome AttemptExhaustively(const Aws::String& uri, Http::HttpMethod httpMethod) const;
129 
134  HttpResponseOutcome AttemptOneRequest(const Aws::String& uri,
135  const Aws::AmazonWebServiceRequest& request,
136  Http::HttpMethod httpMethod) const;
137 
142  HttpResponseOutcome AttemptOneRequest(const Aws::String& uri, Http::HttpMethod httpMethod) const;
143 
148  StreamOutcome MakeRequestWithUnparsedResponse(const Aws::String& uri,
149  const Aws::AmazonWebServiceRequest& request,
150  Http::HttpMethod method = Http::HttpMethod::HTTP_POST) const;
151 
155  virtual AWSError<CoreErrors> BuildAWSError(const std::shared_ptr<Aws::Http::HttpResponse>& response) const = 0;
156 
160  virtual void BuildHttpRequest(const Aws::AmazonWebServiceRequest& request,
161  const std::shared_ptr<Aws::Http::HttpRequest>& httpRequest) const;
162 
166  const std::shared_ptr<AWSErrorMarshaller>& GetErrorMarshaller() const
167  {
168  return m_errorMarshaller;
169  }
170 
171  private:
172  void AddHeadersToRequest(const std::shared_ptr<Aws::Http::HttpRequest>& httpRequest, const Http::HeaderValueCollection& headerValues) const;
173  void AddContentBodyToRequest(const std::shared_ptr<Aws::Http::HttpRequest>& httpRequest,
174  const std::shared_ptr<Aws::IOStream>& body, bool needsContentMd5 = false) const;
175  void AddCommonHeaders(Aws::Http::HttpRequest& httpRequest) const;
176  void InitializeGlobalStatics();
177  void CleanupGlobalStatics();
178 
179  std::shared_ptr<Aws::Http::HttpClient> m_httpClient;
180  std::shared_ptr<Aws::Client::AWSAuthSigner> m_signer;
181  std::shared_ptr<AWSErrorMarshaller> m_errorMarshaller;
182  std::shared_ptr<RetryStrategy> m_retryStrategy;
183  std::shared_ptr<Aws::Utils::RateLimits::RateLimiterInterface> m_writeRateLimiter;
184  std::shared_ptr<Aws::Utils::RateLimits::RateLimiterInterface> m_readRateLimiter;
185  Aws::String m_userAgent;
186  std::shared_ptr<Aws::Utils::Crypto::Hash> m_hash;
187  static std::atomic<int> s_refCount;
188  };
189 
191 
197  {
198  public:
200 
204  AWSJsonClient(const Aws::Client::ClientConfiguration& configuration,
205  const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer,
206  const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller);
207 
208  virtual ~AWSJsonClient() = default;
209 
210  protected:
214  virtual AWSError<CoreErrors> BuildAWSError(const std::shared_ptr<Aws::Http::HttpResponse>& response) const override;
215 
222  JsonOutcome MakeRequest(const Aws::String& uri,
223  const Aws::AmazonWebServiceRequest& request,
224  Http::HttpMethod method = Http::HttpMethod::HTTP_POST) const;
225 
232  JsonOutcome MakeRequest(const Aws::String& uri,
233  Http::HttpMethod method = Http::HttpMethod::HTTP_POST) const;
234 
235  };
236 
238 
244  {
245  public:
246 
248 
249  AWSXMLClient(const Aws::Client::ClientConfiguration& configuration,
250  const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer,
251  const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller);
252 
253  virtual ~AWSXMLClient() = default;
254 
255  protected:
259  virtual AWSError<CoreErrors> BuildAWSError(const std::shared_ptr<Aws::Http::HttpResponse>& response) const override;
260 
267  XmlOutcome MakeRequest(const Aws::String& uri,
268  const Aws::AmazonWebServiceRequest& request,
269  Http::HttpMethod method = Http::HttpMethod::HTTP_POST) const;
270 
277  XmlOutcome MakeRequest(const Aws::String& uri,
278  Http::HttpMethod method = Http::HttpMethod::HTTP_POST) const;
279  };
280 
281  } // namespace Client
282 } // namespace Aws
Utils::Outcome< AmazonWebServiceResult< Utils::Stream::ResponseStream >, AWSError< CoreErrors > > StreamOutcome
Definition: AWSClient.h:79
Aws::Map< Aws::String, Aws::String > HeaderValueCollection
Definition: HttpTypes.h:63
const std::shared_ptr< AWSErrorMarshaller > & GetErrorMarshaller() const
Definition: AWSClient.h:166
Utils::Outcome< std::shared_ptr< Aws::Http::HttpResponse >, AWSError< CoreErrors > > HttpResponseOutcome
Definition: AWSClient.h:76
Utils::Outcome< AmazonWebServiceResult< Utils::Json::JsonValue >, AWSError< CoreErrors > > JsonOutcome
Definition: AWSClient.h:190
HTTP_POST
Definition: HttpTypes.h:35
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
Utils::Outcome< AmazonWebServiceResult< Utils::Xml::XmlDocument >, AWSError< CoreErrors > > XmlOutcome
Definition: AWSClient.h:237
#define AWS_CORE_API
Definition: Core_EXPORTS.h:30
JSON (JavaScript Object Notation).