AWS SDK for C++

AWS SDK for C++ Version 1.11.440

Loading...
Searching...
No Matches
XmlOutcomeSerializer.h
1
5#pragma once
6#include <aws/core/AmazonWebServiceResult.h>
7#include <aws/core/client/AWSError.h>
8#include <aws/core/utils/Outcome.h>
9#include <aws/core/utils/xml/XmlSerializer.h>
10#include <smithy/tracing/TracingUtils.h>
11#include <smithy/tracing/TelemetryProvider.h>
12
13namespace smithy
14{
15 namespace client
16 {
17 using TracingUtils = components::tracing::TracingUtils;
25
27 {
28 public:
29 explicit XmlOutcomeSerializer(const std::shared_ptr<TelemetryProvider>& telemetryProvider)
30 : m_telemetryProvider(telemetryProvider)
31 {
32 }
33
35 XmlOutcomeSerializer(XmlOutcomeSerializer&& other) noexcept = default;
38 virtual ~XmlOutcomeSerializer() = default;
39
40
42 const Aws::String& serviceName,
43 const Aws::String& requestName) const
44 {
45 if (!httpOutcome.IsSuccess())
46 {
47 return TracingUtils::MakeCallWithTiming<XmlOutcome>(
48 [&]() -> XmlOutcome {
49 return {std::move(httpOutcome)};
50 },
52 *m_telemetryProvider->getMeter(serviceName, {}),
54 }
55
56 if (httpOutcome.GetResult()->GetResponseBody().good() &&
57 httpOutcome.GetResult()->GetResponseBody().tellp() > 0)
58 {
59 return TracingUtils::MakeCallWithTiming<XmlOutcome>(
60 [&]() -> XmlOutcome {
61 XmlDocument xmlDoc = XmlDocument::CreateFromXmlStream(httpOutcome.GetResult()->GetResponseBody());
62
63 if (!xmlDoc.WasParseSuccessful())
64 {
65 AWS_LOGSTREAM_ERROR("XmlOutcomeSerializer", "Xml parsing for error failed with message " << xmlDoc.GetErrorMessage().c_str());
66 return AWSError(CoreErrors::UNKNOWN,
67 "Xml Parse Error",
68 xmlDoc.GetErrorMessage(),
69 false);
70 }
71
72 return {XmlServiceResult(std::move(xmlDoc),
73 httpOutcome.GetResult()->GetHeaders(),
74 httpOutcome.GetResult()->GetResponseCode())};
75 },
77 *m_telemetryProvider->getMeter(serviceName, {}),
79 }
80
81 return {XmlServiceResult(XmlDocument(), httpOutcome.GetResult()->GetHeaders())};
82 }
83 private:
84 std::shared_ptr<TelemetryProvider> m_telemetryProvider;
85 };
86
87 } // namespace client
88} // namespace smithy
Aws::String GetErrorMessage() const
static XmlDocument CreateFromXmlStream(Aws::IOStream &)
XmlOutcomeSerializer(const XmlOutcomeSerializer &other)=delete
XmlOutcomeSerializer(const std::shared_ptr< TelemetryProvider > &telemetryProvider)
XmlOutcome Deserialize(HttpResponseOutcome &&httpOutcome, const Aws::String &serviceName, const Aws::String &requestName) const
XmlOutcomeSerializer(XmlOutcomeSerializer &&other) noexcept=default
XmlOutcomeSerializer & operator=(const XmlOutcomeSerializer &other)=delete
XmlOutcomeSerializer & operator=(XmlOutcomeSerializer &&other) noexcept=default
static const char SMITHY_CLIENT_DESERIALIZATION_METRIC[]
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition AWSString.h:97
components::tracing::TracingUtils TracingUtils
Aws::AmazonWebServiceResult< XmlDocument > XmlServiceResult
Aws::Utils::Xml::XmlDocument XmlDocument
Aws::Client::AWSError< CoreErrors > AWSError
Aws::Client::CoreErrors CoreErrors