1#ifndef TENDUKE_CLIENT_EE_STATEFULCHECKOUTREQUESTTEMPLATE_H
2#define TENDUKE_CLIENT_EE_STATEFULCHECKOUTREQUESTTEMPLATE_H
4#include "../authz/LicensingRequest.h"
5#include "http/Unauthorized.h"
7#include "oidc/session/OIDCSession.h"
9namespace tenduke {
namespace ee {
namespace licensing {
namespace impl {
38 const std::shared_ptr<::tenduke::oidc::OIDCSession> &oidc
39 ) : oidc(oidc), request(std::move(request))
51 oidc->ensureValidSession();
54 std::unique_ptr<T> response =
nullptr;
58 response.reset(
new T(request->execute()));
64 catch (const ::tenduke::http::Unauthorized &e) {
66 return reEstablishOIDCSessionAndRetry();
76 if (response->failed()) {
77 ::tenduke::log::warning(
"StatefulCheckoutRequest::execute() ... failed. Doing heartbeat to check backend state...");
79 if (oidc->heartbeat()) {
80 ::tenduke::log::info(
"StatefulCheckoutRequest::execute() ... credentials were valid. Returning original response.");
84 return reEstablishOIDCSessionAndRetry();
95 T reEstablishOIDCSessionAndRetry()
97 ::tenduke::log::info(
"StatefulCheckoutRequest::reEstablishOIDCSessionAndRetry() Re-estalishing OIDC session...");
100 ::tenduke::log::info(
"StatefulCheckoutRequest::reEstablishOIDCSessionAndRetry() ... OIDC session re-established. Re-executing original request...");
101 auto response = request->execute();
103 ::tenduke::log::info(
"StatefulCheckoutRequest::reEstablishOIDCSessionAndRetry() ... ready, returning new response as-is.");
108 const std::shared_ptr<::tenduke::oidc::OIDCSession> oidc;
109 const std::unique_ptr<::tenduke::ee::licensing::authzapi::LicensingRequest<T>> request;
Licensing-related request.
Definition LicensingRequest.h:13
Common base for stateful checkout-like requests.
Definition StatefulCheckoutRequestTemplate.h:29
StatefulCheckoutRequestTemplate(std::unique_ptr<::tenduke::ee::licensing::authzapi::LicensingRequest< T > > request, const std::shared_ptr<::tenduke::oidc::OIDCSession > &oidc)
Constructs new instance.
Definition StatefulCheckoutRequestTemplate.h:36
T execute()
Executes the request.
Definition StatefulCheckoutRequestTemplate.h:48
void debug(const char *message)
Write message to global logger at DEBUG-level.
Definition log.cpp:26
void warning(const char *message)
Write message to global logger at WARNING-level.
Definition log.cpp:66
void info(const char *message)
Write message to global logger at INFO-level.
Definition log.cpp:46
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4