3
0

HttpRequestorSystemComponent.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Serialization/SerializeContext.h>
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include "HttpRequestorSystemComponent.h"
  11. namespace HttpRequestor
  12. {
  13. void HttpRequestorSystemComponent::AddRequest(const AZStd::string& URI, Aws::Http::HttpMethod method, const Callback& callback)
  14. {
  15. if(m_httpManager != nullptr)
  16. {
  17. m_httpManager->AddRequest( Parameters(URI, method, callback) );
  18. }
  19. }
  20. void HttpRequestorSystemComponent::AddRequestWithClientConfiguration(
  21. const AZStd::string& URI,
  22. Aws::Http::HttpMethod method,
  23. const Callback& callback,
  24. const Aws::Client::ClientConfiguration clientConfiguration)
  25. {
  26. if (m_httpManager != nullptr)
  27. {
  28. m_httpManager->AddRequest(Parameters(URI, method, callback, clientConfiguration));
  29. }
  30. }
  31. void HttpRequestorSystemComponent::AddRequestWithHeaders(
  32. const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers& headers, const Callback& callback)
  33. {
  34. if (m_httpManager != nullptr)
  35. {
  36. m_httpManager->AddRequest(Parameters(URI, method, headers, callback));
  37. }
  38. }
  39. void HttpRequestorSystemComponent::AddRequestWithHeadersAndClientConfiguration(
  40. const AZStd::string& URI,
  41. Aws::Http::HttpMethod method,
  42. const Headers& headers,
  43. const Callback& callback,
  44. const Aws::Client::ClientConfiguration clientConfiguration)
  45. {
  46. if (m_httpManager != nullptr)
  47. {
  48. m_httpManager->AddRequest(Parameters(URI, method, headers, callback, clientConfiguration));
  49. }
  50. }
  51. void HttpRequestorSystemComponent::AddRequestWithHeadersAndBody(
  52. const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers& headers, const AZStd::string& body, const Callback& callback)
  53. {
  54. if (m_httpManager != nullptr)
  55. {
  56. m_httpManager->AddRequest(Parameters(URI, method, headers, body, callback));
  57. }
  58. }
  59. void HttpRequestorSystemComponent::AddRequestWithHeadersBodyAndClientConfiguration(
  60. const AZStd::string& URI,
  61. Aws::Http::HttpMethod method,
  62. const Headers& headers,
  63. const AZStd::string& body,
  64. const Callback& callback,
  65. const Aws::Client::ClientConfiguration clientConfiguration)
  66. {
  67. if (m_httpManager != nullptr)
  68. {
  69. m_httpManager->AddRequest(Parameters(URI, method, headers, body, callback, clientConfiguration));
  70. }
  71. }
  72. void HttpRequestorSystemComponent::AddTextRequest(const AZStd::string& URI, Aws::Http::HttpMethod method, const TextCallback& callback)
  73. {
  74. if (m_httpManager != nullptr)
  75. {
  76. m_httpManager->AddTextRequest( TextParameters(URI, method, callback));
  77. }
  78. }
  79. void HttpRequestorSystemComponent::AddTextRequestWithClientConfiguration(
  80. const AZStd::string& URI,
  81. Aws::Http::HttpMethod method,
  82. const TextCallback& callback,
  83. const Aws::Client::ClientConfiguration clientConfiguration)
  84. {
  85. if (m_httpManager != nullptr)
  86. {
  87. m_httpManager->AddTextRequest(TextParameters(URI, method, callback, clientConfiguration));
  88. }
  89. }
  90. void HttpRequestorSystemComponent::AddTextRequestWithHeaders(
  91. const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers& headers, const TextCallback& callback)
  92. {
  93. if (m_httpManager != nullptr)
  94. {
  95. m_httpManager->AddTextRequest(TextParameters(URI, method, headers, callback));
  96. }
  97. }
  98. void HttpRequestorSystemComponent::AddTextRequestWithHeadersAndClientConfiguration(
  99. const AZStd::string& URI,
  100. Aws::Http::HttpMethod method,
  101. const Headers& headers,
  102. const TextCallback& callback,
  103. const Aws::Client::ClientConfiguration clientConfiguration)
  104. {
  105. if (m_httpManager != nullptr)
  106. {
  107. m_httpManager->AddTextRequest(TextParameters(URI, method, headers, callback, clientConfiguration));
  108. }
  109. }
  110. void HttpRequestorSystemComponent::AddTextRequestWithHeadersAndBody(
  111. const AZStd::string& URI,
  112. Aws::Http::HttpMethod method,
  113. const Headers& headers,
  114. const AZStd::string& body,
  115. const TextCallback& callback)
  116. {
  117. if (m_httpManager != nullptr)
  118. {
  119. m_httpManager->AddTextRequest(TextParameters(URI, method, headers, body, callback));
  120. }
  121. }
  122. void HttpRequestorSystemComponent::AddTextRequestWithHeadersBodyAndClientConfiguration(
  123. const AZStd::string& URI,
  124. Aws::Http::HttpMethod method,
  125. const Headers& headers,
  126. const AZStd::string& body,
  127. const TextCallback& callback,
  128. const Aws::Client::ClientConfiguration clientConfiguration)
  129. {
  130. if (m_httpManager != nullptr)
  131. {
  132. m_httpManager->AddTextRequest(TextParameters(URI, method, headers, body, callback, clientConfiguration));
  133. }
  134. }
  135. AZStd::chrono::milliseconds HttpRequestorSystemComponent::GetLastRoundTripTime() const
  136. {
  137. if (m_httpManager != nullptr)
  138. {
  139. return m_httpManager->GetLastRoundTripTime();
  140. }
  141. return {};
  142. }
  143. void HttpRequestorSystemComponent::Reflect(AZ::ReflectContext* context)
  144. {
  145. if (auto serialize = azrtti_cast<AZ::SerializeContext*>(context))
  146. {
  147. serialize->Class<HttpRequestorSystemComponent, AZ::Component>()->Version(1);
  148. if (AZ::EditContext* ec = serialize->GetEditContext())
  149. {
  150. ec->Class<HttpRequestorSystemComponent>("HttpRequestor", "Will make HTTP Rest calls")
  151. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  152. // ->Attribute(AZ::Edit::Attributes::Category, "") Set a category
  153. ->Attribute(AZ::Edit::Attributes::AutoExpand, true);
  154. }
  155. }
  156. }
  157. void HttpRequestorSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  158. {
  159. provided.push_back(AZ_CRC("HttpRequestorService"));
  160. }
  161. void HttpRequestorSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  162. {
  163. incompatible.push_back(AZ_CRC("HttpRequestorService"));
  164. }
  165. void HttpRequestorSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  166. {
  167. (void)required;
  168. }
  169. void HttpRequestorSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  170. {
  171. (void)dependent;
  172. }
  173. void HttpRequestorSystemComponent::Init()
  174. {
  175. }
  176. void HttpRequestorSystemComponent::Activate()
  177. {
  178. m_httpManager = AZStd::make_shared<Manager>();
  179. HttpRequestorRequestBus::Handler::BusConnect();
  180. }
  181. void HttpRequestorSystemComponent::Deactivate()
  182. {
  183. HttpRequestorRequestBus::Handler::BusDisconnect();
  184. m_httpManager = nullptr;
  185. }
  186. }