Repository navigation
Expand file tree
/
Copy pathJsonProtocolClient.cpp
More file actions
298 lines (260 loc) · 17.8 KB
/
Copy pathJsonProtocolClient.cpp
File metadata and controls
298 lines (260 loc) · 17.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/core/auth/AWSAuthSigner.h>
#include <aws/core/auth/AWSCredentialsProviderChain.h>
#include <aws/core/client/CoreErrors.h>
#include <aws/core/client/RetryStrategy.h>
#include <aws/core/http/HttpClient.h>
#include <aws/core/http/HttpClientFactory.h>
#include <aws/core/http/HttpResponse.h>
#include <aws/core/utils/DNS.h>
#include <aws/core/utils/Outcome.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <aws/core/utils/logging/ErrorMacros.h>
#include <aws/core/utils/logging/LogMacros.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>
#include <aws/core/utils/threading/Executor.h>
#include <aws/json-protocol/JsonProtocolClient.h>
#include <aws/json-protocol/JsonProtocolEndpointProvider.h>
#include <aws/json-protocol/JsonProtocolErrorMarshaller.h>
#include <aws/json-protocol/model/ContentTypeParametersRequest.h>
#include <aws/json-protocol/model/DatetimeOffsetsRequest.h>
#include <aws/json-protocol/model/EmptyOperationRequest.h>
#include <aws/json-protocol/model/EndpointOperationRequest.h>
#include <aws/json-protocol/model/EndpointWithHostLabelOperationRequest.h>
#include <aws/json-protocol/model/FractionalSecondsRequest.h>
#include <aws/json-protocol/model/GreetingWithErrorsRequest.h>
#include <aws/json-protocol/model/HostWithPathOperationRequest.h>
#include <aws/json-protocol/model/JsonEnumsRequest.h>
#include <aws/json-protocol/model/JsonIntEnumsRequest.h>
#include <aws/json-protocol/model/JsonUnionsRequest.h>
#include <aws/json-protocol/model/KitchenSinkOperationRequest.h>
#include <aws/json-protocol/model/NullOperationRequest.h>
#include <aws/json-protocol/model/OperationWithOptionalInputOutputRequest.h>
#include <aws/json-protocol/model/PutAndGetInlineDocumentsRequest.h>
#include <aws/json-protocol/model/PutWithContentEncodingRequest.h>
#include <aws/json-protocol/model/SimpleScalarPropertiesRequest.h>
#include <aws/json-protocol/model/SparseNullsOperationRequest.h>
#include <smithy/tracing/TracingUtils.h>
using namespace Aws;
using namespace Aws::Auth;
using namespace Aws::Client;
using namespace Aws::JsonProtocol;
using namespace Aws::JsonProtocol::Model;
using namespace Aws::Http;
using namespace Aws::Utils::Json;
using namespace smithy::components::tracing;
using ResolveEndpointOutcome = Aws::Endpoint::ResolveEndpointOutcome;
namespace Aws {
namespace JsonProtocol {
const char SERVICE_NAME[] = "jsonprotocol";
const char ALLOCATION_TAG[] = "JsonProtocolClient";
} // namespace JsonProtocol
} // namespace Aws
const char* JsonProtocolClient::GetServiceName() { return SERVICE_NAME; }
const char* JsonProtocolClient::GetAllocationTag() { return ALLOCATION_TAG; }
JsonProtocolClient::JsonProtocolClient(const JsonProtocol::JsonProtocolClientConfiguration& clientConfiguration,
std::shared_ptr<JsonProtocolEndpointProviderBase> endpointProvider)
: BASECLASS(clientConfiguration,
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG,
Aws::MakeShared<DefaultAWSCredentialsProviderChain>(
ALLOCATION_TAG, clientConfiguration.ResolveCredentialProviderConfig()),
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)),
Aws::MakeShared<JsonProtocolErrorMarshaller>(ALLOCATION_TAG)),
m_clientConfiguration(clientConfiguration),
m_endpointProvider(endpointProvider ? std::move(endpointProvider) : Aws::MakeShared<JsonProtocolEndpointProvider>(ALLOCATION_TAG)) {
init(m_clientConfiguration);
}
JsonProtocolClient::JsonProtocolClient(const AWSCredentials& credentials,
std::shared_ptr<JsonProtocolEndpointProviderBase> endpointProvider,
const JsonProtocol::JsonProtocolClientConfiguration& clientConfiguration)
: BASECLASS(clientConfiguration,
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, Aws::MakeShared<SimpleAWSCredentialsProvider>(ALLOCATION_TAG, credentials),
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)),
Aws::MakeShared<JsonProtocolErrorMarshaller>(ALLOCATION_TAG)),
m_clientConfiguration(clientConfiguration),
m_endpointProvider(endpointProvider ? std::move(endpointProvider) : Aws::MakeShared<JsonProtocolEndpointProvider>(ALLOCATION_TAG)) {
init(m_clientConfiguration);
}
JsonProtocolClient::JsonProtocolClient(const std::shared_ptr<AWSCredentialsProvider>& credentialsProvider,
std::shared_ptr<JsonProtocolEndpointProviderBase> endpointProvider,
const JsonProtocol::JsonProtocolClientConfiguration& clientConfiguration)
: BASECLASS(clientConfiguration,
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, credentialsProvider, SERVICE_NAME,
Aws::Region::ComputeSignerRegion(clientConfiguration.region)),
Aws::MakeShared<JsonProtocolErrorMarshaller>(ALLOCATION_TAG)),
m_clientConfiguration(clientConfiguration),
m_endpointProvider(endpointProvider ? std::move(endpointProvider) : Aws::MakeShared<JsonProtocolEndpointProvider>(ALLOCATION_TAG)) {
init(m_clientConfiguration);
}
/* Legacy constructors due deprecation */
JsonProtocolClient::JsonProtocolClient(const Aws::Client::ClientConfiguration& clientConfiguration)
: BASECLASS(clientConfiguration,
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG,
Aws::MakeShared<DefaultAWSCredentialsProviderChain>(
ALLOCATION_TAG, clientConfiguration.ResolveCredentialProviderConfig()),
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)),
Aws::MakeShared<JsonProtocolErrorMarshaller>(ALLOCATION_TAG)),
m_clientConfiguration(clientConfiguration),
m_endpointProvider(Aws::MakeShared<JsonProtocolEndpointProvider>(ALLOCATION_TAG)) {
init(m_clientConfiguration);
}
JsonProtocolClient::JsonProtocolClient(const AWSCredentials& credentials, const Aws::Client::ClientConfiguration& clientConfiguration)
: BASECLASS(clientConfiguration,
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, Aws::MakeShared<SimpleAWSCredentialsProvider>(ALLOCATION_TAG, credentials),
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)),
Aws::MakeShared<JsonProtocolErrorMarshaller>(ALLOCATION_TAG)),
m_clientConfiguration(clientConfiguration),
m_endpointProvider(Aws::MakeShared<JsonProtocolEndpointProvider>(ALLOCATION_TAG)) {
init(m_clientConfiguration);
}
JsonProtocolClient::JsonProtocolClient(const std::shared_ptr<AWSCredentialsProvider>& credentialsProvider,
const Aws::Client::ClientConfiguration& clientConfiguration)
: BASECLASS(clientConfiguration,
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, credentialsProvider, SERVICE_NAME,
Aws::Region::ComputeSignerRegion(clientConfiguration.region)),
Aws::MakeShared<JsonProtocolErrorMarshaller>(ALLOCATION_TAG)),
m_clientConfiguration(clientConfiguration),
m_endpointProvider(Aws::MakeShared<JsonProtocolEndpointProvider>(ALLOCATION_TAG)) {
init(m_clientConfiguration);
}
/* End of legacy constructors due deprecation */
JsonProtocolClient::~JsonProtocolClient() { ShutdownSdkClient(this, -1); }
std::shared_ptr<JsonProtocolEndpointProviderBase>& JsonProtocolClient::accessEndpointProvider() { return m_endpointProvider; }
void JsonProtocolClient::init(const JsonProtocol::JsonProtocolClientConfiguration& config) {
AWSClient::SetServiceClientName("Json Protocol");
if (!m_clientConfiguration.executor && m_clientConfiguration.configFactories.executorCreateFn) {
m_clientConfiguration.executor = m_clientConfiguration.configFactories.executorCreateFn();
}
if (!m_clientConfiguration.executor) {
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to initialize client: config is missing Executor or executorCreateFn");
m_isInitialized = false;
return;
}
AWSClient::SetUserAgentExecutor(*m_clientConfiguration.executor);
AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider);
m_endpointProvider->InitBuiltInParameters(config, "jsonprotocol");
}
void JsonProtocolClient::OverrideEndpoint(const Aws::String& endpoint) {
AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider);
m_clientConfiguration.endpointOverride = endpoint;
m_endpointProvider->OverrideEndpoint(endpoint);
}
JsonProtocolClient::InvokeOperationOutcome JsonProtocolClient::InvokeServiceOperation(const AmazonWebServiceRequest& request,
Aws::Http::HttpMethod httpMethod) const {
auto operationName = request.GetServiceRequestName();
auto serviceName = GetServiceClientName();
AWS_OPERATION_GUARD_DYNAMIC(operationName);
AWS_OPERATION_CHECK_PTR_DYNAMIC(m_endpointProvider, operationName, CoreErrors, CoreErrors::ENDPOINT_RESOLUTION_FAILURE);
AWS_OPERATION_CHECK_PTR_DYNAMIC(m_telemetryProvider, operationName, CoreErrors, CoreErrors::NOT_INITIALIZED);
auto tracer = m_telemetryProvider->getTracer(serviceName, {});
auto meter = m_telemetryProvider->getMeter(serviceName, {});
AWS_OPERATION_CHECK_PTR_DYNAMIC(meter, operationName, CoreErrors, CoreErrors::NOT_INITIALIZED);
auto span = tracer->CreateSpan(Aws::String(serviceName) + "." + operationName,
{{TracingUtils::SMITHY_METHOD_DIMENSION, operationName},
{TracingUtils::SMITHY_SERVICE_DIMENSION, serviceName},
{TracingUtils::SMITHY_SYSTEM_DIMENSION, TracingUtils::SMITHY_METHOD_AWS_VALUE}},
smithy::components::tracing::SpanKind::CLIENT);
return Aws::Client::AsyncOperationState::MakeCallWithTiming<InvokeOperationOutcome>(
request, std::move(span),
[&]() -> InvokeOperationOutcome {
auto endpointResolutionOutcome = TracingUtils::MakeCallWithTiming<ResolveEndpointOutcome>(
[&]() -> ResolveEndpointOutcome { return m_endpointProvider->ResolveEndpoint(request.GetEndpointContextParams()); },
TracingUtils::SMITHY_CLIENT_ENDPOINT_RESOLUTION_METRIC, *meter,
{{TracingUtils::SMITHY_METHOD_DIMENSION, operationName}, {TracingUtils::SMITHY_SERVICE_DIMENSION, serviceName}});
AWS_OPERATION_CHECK_SUCCESS_DYNAMIC(endpointResolutionOutcome, operationName, CoreErrors, CoreErrors::ENDPOINT_RESOLUTION_FAILURE,
endpointResolutionOutcome.GetError().GetMessage());
return InvokeOperationOutcome{MakeRequest(request, endpointResolutionOutcome.GetResult(), httpMethod, Aws::Auth::SIGV4_SIGNER)};
},
TracingUtils::SMITHY_CLIENT_DURATION_METRIC, meter,
{{TracingUtils::SMITHY_METHOD_DIMENSION, operationName}, {TracingUtils::SMITHY_SERVICE_DIMENSION, serviceName}});
}
ContentTypeParametersOutcome JsonProtocolClient::ContentTypeParameters(const ContentTypeParametersRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? ContentTypeParametersOutcome(result.GetResultWithOwnership())
: ContentTypeParametersOutcome(std::move(result.GetError()));
}
DatetimeOffsetsOutcome JsonProtocolClient::DatetimeOffsets(const DatetimeOffsetsRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? DatetimeOffsetsOutcome(result.GetResultWithOwnership())
: DatetimeOffsetsOutcome(std::move(result.GetError()));
}
EmptyOperationOutcome JsonProtocolClient::EmptyOperation(const EmptyOperationRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? EmptyOperationOutcome(result.GetResultWithOwnership()) : EmptyOperationOutcome(std::move(result.GetError()));
}
EndpointOperationOutcome JsonProtocolClient::EndpointOperation(const EndpointOperationRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? EndpointOperationOutcome(result.GetResultWithOwnership())
: EndpointOperationOutcome(std::move(result.GetError()));
}
EndpointWithHostLabelOperationOutcome JsonProtocolClient::EndpointWithHostLabelOperation(
const EndpointWithHostLabelOperationRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? EndpointWithHostLabelOperationOutcome(result.GetResultWithOwnership())
: EndpointWithHostLabelOperationOutcome(std::move(result.GetError()));
}
FractionalSecondsOutcome JsonProtocolClient::FractionalSeconds(const FractionalSecondsRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? FractionalSecondsOutcome(result.GetResultWithOwnership())
: FractionalSecondsOutcome(std::move(result.GetError()));
}
GreetingWithErrorsOutcome JsonProtocolClient::GreetingWithErrors(const GreetingWithErrorsRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? GreetingWithErrorsOutcome(result.GetResultWithOwnership())
: GreetingWithErrorsOutcome(std::move(result.GetError()));
}
HostWithPathOperationOutcome JsonProtocolClient::HostWithPathOperation(const HostWithPathOperationRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? HostWithPathOperationOutcome(result.GetResultWithOwnership())
: HostWithPathOperationOutcome(std::move(result.GetError()));
}
JsonEnumsOutcome JsonProtocolClient::JsonEnums(const JsonEnumsRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? JsonEnumsOutcome(result.GetResultWithOwnership()) : JsonEnumsOutcome(std::move(result.GetError()));
}
JsonIntEnumsOutcome JsonProtocolClient::JsonIntEnums(const JsonIntEnumsRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? JsonIntEnumsOutcome(result.GetResultWithOwnership()) : JsonIntEnumsOutcome(std::move(result.GetError()));
}
JsonUnionsOutcome JsonProtocolClient::JsonUnions(const JsonUnionsRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? JsonUnionsOutcome(result.GetResultWithOwnership()) : JsonUnionsOutcome(std::move(result.GetError()));
}
KitchenSinkOperationOutcome JsonProtocolClient::KitchenSinkOperation(const KitchenSinkOperationRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? KitchenSinkOperationOutcome(result.GetResultWithOwnership())
: KitchenSinkOperationOutcome(std::move(result.GetError()));
}
NullOperationOutcome JsonProtocolClient::NullOperation(const NullOperationRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? NullOperationOutcome(result.GetResultWithOwnership()) : NullOperationOutcome(std::move(result.GetError()));
}
OperationWithOptionalInputOutputOutcome JsonProtocolClient::OperationWithOptionalInputOutput(
const OperationWithOptionalInputOutputRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? OperationWithOptionalInputOutputOutcome(result.GetResultWithOwnership())
: OperationWithOptionalInputOutputOutcome(std::move(result.GetError()));
}
PutAndGetInlineDocumentsOutcome JsonProtocolClient::PutAndGetInlineDocuments(const PutAndGetInlineDocumentsRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? PutAndGetInlineDocumentsOutcome(result.GetResultWithOwnership())
: PutAndGetInlineDocumentsOutcome(std::move(result.GetError()));
}
PutWithContentEncodingOutcome JsonProtocolClient::PutWithContentEncoding(const PutWithContentEncodingRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? PutWithContentEncodingOutcome(result.GetResultWithOwnership())
: PutWithContentEncodingOutcome(std::move(result.GetError()));
}
SimpleScalarPropertiesOutcome JsonProtocolClient::SimpleScalarProperties(const SimpleScalarPropertiesRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? SimpleScalarPropertiesOutcome(result.GetResultWithOwnership())
: SimpleScalarPropertiesOutcome(std::move(result.GetError()));
}
SparseNullsOperationOutcome JsonProtocolClient::SparseNullsOperation(const SparseNullsOperationRequest& request) const {
auto result = InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_POST);
return result.IsSuccess() ? SparseNullsOperationOutcome(result.GetResultWithOwnership())
: SparseNullsOperationOutcome(std::move(result.GetError()));
}