10Duke Enterprise C++ SDK
Toggle main menu visibility
Loading...
Searching...
No Matches
AbstractAuthzApiRequest.h
1
#ifndef TENDUKE_EE_LICENSING_AUTZHAPI_ABSTRACTAUTHZAPIREQUEST_H
2
#define TENDUKE_EE_LICENSING_AUTZHAPI_ABSTRACTAUTHZAPIREQUEST_H
3
4
#include "../LicensingRequest.h"
5
#include "http/HTTPClient.h"
6
#include "http/HTTPRequestAuthenticator.h"
7
#include "http/HTTPResponseToException.h"
8
#include "log/log.h"
9
10
#include <memory>
11
#include <string>
12
13
14
namespace
tenduke
{
namespace
ee
{
namespace
licensing
{
namespace
authzapi
{
15
16
22
template
<
class
T>
23
class
AbstractAuthzApiRequest
:
public
::tenduke::ee::licensing::authzapi::LicensingRequest
<T>
24
{
25
public
:
26
virtual
~AbstractAuthzApiRequest
() =
default
;
27
34
AbstractAuthzApiRequest
(
35
const
std::shared_ptr<const ::tenduke::http::HTTPClient> &httpClient,
36
const
std::shared_ptr<const ::tenduke::http::HTTPRequestAuthenticator> &httpRequestAuthenticator,
37
const
std::shared_ptr<const ::tenduke::http::HTTPResponseToException> &throwException,
38
const
std::shared_ptr<::tenduke::log::Logger> &logger
39
) : http(httpClient)
40
, httpRequestAuthenticator(httpRequestAuthenticator)
41
, throwException(throwException)
42
, log(logger)
43
{}
44
45
public
:
50
T
execute
()
override
51
{
52
// Build the HTTP-request
53
auto
request = http->request();
54
auto
urlBuilder = request.createURL();
55
buildRequestUrl
(urlBuilder);
56
std::string url = urlBuilder.buildString();
57
58
if
(this->log->isDebugEnabled()) {
59
this->log->debug(
"AbstractAuthzApiRequest::execute() Executing HTTP request with URL "
+ url +
" ..."
);
60
}
61
62
// Build and execute the request:
63
auto
httpCall = request.get()
64
.authenticateWith(httpRequestAuthenticator)
65
.url(url)
66
.call();
67
auto
httpResponse = httpCall->execute();
68
69
if
(! httpResponse->isSuccessful()) {
70
this->log->warning(
"AbstractAuthzApiRequest::execute() ...HTTP request failed with status code "
+ std::to_string(httpResponse->getStatusCode()));
71
throwException->basedOn(*httpResponse);
72
}
73
74
this->log->debug(
"AbstractAuthzApiRequest::execute() ...HTTP request successfully executed"
);
75
76
return
parseResponsePayload
(httpResponse->getPayloadAsString());
77
}
78
79
protected
:
85
virtual
T
parseResponsePayload
(
const
std::string &payload)
const
= 0;
86
91
virtual
void
buildRequestUrl
(
::tenduke::net::URLBuilder
&url)
const
= 0;
92
93
private
:
94
const
std::shared_ptr<::tenduke::log::Logger> log;
95
const
std::shared_ptr<const ::tenduke::http::HTTPClient> http;
96
const
std::shared_ptr<const ::tenduke::http::HTTPRequestAuthenticator> httpRequestAuthenticator;
97
const
std::shared_ptr<const ::tenduke::http::HTTPResponseToException> throwException;
98
};
99
100
101
}}}}
102
103
#endif
// TENDUKE_EE_LICENSING_AUTZHAPI_ABSTRACTAUTHZAPIREQUEST_H
tenduke::ee::licensing::authzapi::AbstractAuthzApiRequest::parseResponsePayload
virtual T parseResponsePayload(const std::string &payload) const =0
Parses the response payload to tenduke::ee::licensing::LicenseCheckoutResponse.
tenduke::ee::licensing::authzapi::AbstractAuthzApiRequest::buildRequestUrl
virtual void buildRequestUrl(::tenduke::net::URLBuilder &url) const =0
Builds request URL.
tenduke::ee::licensing::authzapi::AbstractAuthzApiRequest::AbstractAuthzApiRequest
AbstractAuthzApiRequest(const std::shared_ptr< const ::tenduke::http::HTTPClient > &httpClient, const std::shared_ptr< const ::tenduke::http::HTTPRequestAuthenticator > &httpRequestAuthenticator, const std::shared_ptr< const ::tenduke::http::HTTPResponseToException > &throwException, const std::shared_ptr<::tenduke::log::Logger > &logger)
Constructs new instance.
Definition
AbstractAuthzApiRequest.h:34
tenduke::ee::licensing::authzapi::AbstractAuthzApiRequest::execute
T execute() override
Executes the request.
Definition
AbstractAuthzApiRequest.h:50
tenduke::ee::licensing::authzapi::LicensingRequest
Licensing-related request.
Definition
LicensingRequest.h:13
tenduke::net::URLBuilder
Very simple URL-builder.
Definition
URLBuilder.h:23
tenduke::ee::licensing::authzapi
Low-level client for licensing operations using 10Duke authz-API.
Definition
AuthzLicensingClient.h:13
tenduke::ee::licensing
Classes, functions and globals related to 10Duke Enterprise licensing.
Definition
AuthzLicensingClient.h:13
tenduke::ee
Classes, functions and globals of 10Duke Enterprise C++ Client.
Definition
APIRequest.h:4
tenduke
Root for classes, functions and globals of 10Duke C++ Client.
Definition
APIRequest.h:4
client
enterprise
api
src
licensing
authz
impl
AbstractAuthzApiRequest.h
Generated by
1.17.0