Skip to content

Commit

Permalink
additional cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Klemm committed Sep 20, 2023
1 parent 724eecb commit 1d0acb2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 56 deletions.
76 changes: 35 additions & 41 deletions esp/services/esdl_svc_engine/esdl_binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1393,16 +1393,21 @@ EsdlServiceImpl::IUpdatableGateway* EsdlServiceImpl::createInlineGateway(const I
return new CLegacyUrlGateway(gw, gwName, gwUrl);
}

EsdlServiceImpl::IGatewayUpdater* EsdlServiceImpl::getGatewayUpdater(IPTree& gw, const UpdatableGateways& updatables, GatewayUpdaters& updaters, Secrets& secrets) const
void EsdlServiceImpl::applyGatewayUpdates(IPTreeIterator& gwIt, const UpdatableGateways& updatables, GatewayUpdaters& updaters, Secrets& secrets) const
{
const char* name = gw.queryProp("@name");
if (isEmptyString(name))
return nullptr;
std::string key(name);
UpdatableGateways::const_iterator it = updatables.find(key);
if (updatables.end() == it)
return nullptr;
return it->second->getUpdater(updaters, secrets);
ForEach(gwIt)
{
IPTree& gw = gwIt.query();
const char* name = gw.queryProp("@name");
if (isEmptyString(name))
continue;
UpdatableGateways::const_iterator ugIt = updatables.find(name);
if (updatables.end() == ugIt)
continue;
Owned<IGatewayUpdater> updater(ugIt->second->getUpdater(updaters, secrets));
if (updater)
updater->updateGateway(gw, "allowPublishedGatewayUsage");
}
}

void EsdlServiceImpl::transformGatewaysConfig( IPTreeIterator* inputs, IPropertyTree* forRoxie, const char* altElementName ) const
Expand Down Expand Up @@ -1776,27 +1781,22 @@ void EsdlServiceImpl::prepareFinalRequest(IEspContext &context,
reqProcessed.append("<soap:Body><").append(tgtQueryName).append(">");
reqProcessed.appendf("<_TransactionId>%s</_TransactionId>", context.queryTransactionID());

GatewaysCache::const_iterator mit = m_methodGatewaysCache.find(mthName);
GatewaysCache::const_iterator mgcIt = m_methodGatewaysCache.find(mthName);
Owned<IPTreeIterator> gwIt;
GatewayUpdaters updaters;
Secrets secrets;
if (tgtctx)
{
// The target context is based on a copy of the target configuration. One copy per
// transaction. It will have already been copied into the script context, so local
// secret and inline URL resolutions can be made in the given property tree.
if (mit != m_methodGatewaysCache.end() && !mit->second.targetContext.empty())
if (mgcIt != m_methodGatewaysCache.end() && !mgcIt->second.targetContext.empty())
{
// The target context is based on a copy of the target configuration. One copy
// per transaction. It will have already been copied into the script context,
// so gateway updates can be made in the given property tree.
IPTree* ctxGateways = tgtctx->queryBranch("Gateways");
if (ctxGateways)
{
Owned<IPTreeIterator> it(ctxGateways->getElements("Gateway"));
ForEach(*it)
{
IPTree& gw = it->query();
Owned<IGatewayUpdater> updater(getGatewayUpdater(gw, mit->second.targetContext, updaters, secrets));
if (updater)
updater->updateGateway(gw, "allowPublishedGatewayUsage");
}
gwIt.setown(ctxGateways->getElements("Gateway"));
applyGatewayUpdates(*gwIt, mgcIt->second.targetContext, updaters, secrets);
}
}
toXML(tgtctx.get(), reqProcessed);
Expand All @@ -1812,34 +1812,28 @@ void EsdlServiceImpl::prepareFinalRequest(IEspContext &context,
StringBuffer xpath(cfgGateways->queryProp("@legacyTransformTarget"));
if (!xpath.isEmpty())
{
Owned<IPTreeIterator> it;
if (mit != m_methodGatewaysCache.end() && !mit->second.legacyTransform.empty())
if (mgcIt != m_methodGatewaysCache.end() && !mgcIt->second.legacyTransform.empty())
{
// The target configuration is shared by all transactions. Local secret and
// inline URL resolutions must be made to a copy of the gateways, to avoid
// contaminating values used in subsequent transactions.
// The target configuration is shared by all transactions.gateway updates
// must be made to a copy of the gateways, to avoid contaminating values
// used in subsequent transactions.
Owned<IPTree> copy(createPTreeFromIPT(cfgGateways));
it.setown(copy->getElements("Gateway"));
ForEach(*it)
{
IPTree& gw = it->query();
Owned<IGatewayUpdater> updater(getGatewayUpdater(gw, mit->second.legacyTransform, updaters, secrets));
if (updater)
updater->updateGateway(gw, "allowPublishedGatewayUsage");
}
gwIt.setown(copy->getElements("Gateway"));
applyGatewayUpdates(*gwIt, mgcIt->second.legacyTransform, updaters, secrets);
}
else
it.setown(cfgGateways->getElements("Gateway"));
gwIt.setown(cfgGateways->getElements("Gateway"));

Owned<IPTree> gws = createPTree("gateways", 0);
StringBuffer rowName(cfgGateways->queryProp("@legacyRowName"));
if (rowName.isEmpty())
rowName.append("row");
transformGatewaysConfig(gwIt, gws, rowName);

// Temporarily add the closing </soap:Envelope> tag so we have valid
// XML to transform the gateways
Owned<IPTree> soapTree = createPTreeFromXMLString(reqProcessed.append("</soap:Envelope>"), ipt_ordered);
StringBuffer rowName(cfgGateways->queryProp("@legacyRowName"));

if (rowName.isEmpty())
rowName.append("row");
transformGatewaysConfig(it, gws, rowName);
xpath.replaceString("{$query}", tgtQueryName);
xpath.replaceString("{$method}", mthName);
xpath.replaceString("{$service}", srvdef.queryName());
Expand Down
21 changes: 6 additions & 15 deletions esp/services/esdl_svc_engine/esdl_binding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,23 +494,14 @@ class EsdlServiceImpl : public CInterface, implements IEspService
IUpdatableGateway* createInlineGateway(const IPTree& gw, const char* gwName, const char* gwUrl) const;

/**
* @brief Obtain an updater instance for use with a specific gateway.
*
* - Null is returned if the gateway does not contain `@name` or `updatables` does not include
* this key.
* - A new link to an existing updater (in `updaters`) is returned if the updatable handler
* (from `updatables`) can find a match. Matching logic is an imlementation detail of the
* updatable handler.
* - A new updater is created, cached in `updaters`, and returned the first time the gateway
* is evaluated.
* @brief Update all iterated nodes, as needed.
*
* @param gw
* @param updatables
* @param updaters
* @param secrets
* @return IGatewayUpdater*
* @param gwIt property tree nodes, presumed to be `Gateway` nodes, for possible updates
* @param updatables set of update handlers to be applied to nodes
* @param updaters cache of updaters used in the current transaction
* @param secrets cache of secrets used in the current transaction
*/
IGatewayUpdater* getGatewayUpdater(IPTree& gw, const UpdatableGateways& updatables, GatewayUpdaters& updaters, Secrets& secrets) const;
void applyGatewayUpdates(IPTreeIterator& gwIt, const UpdatableGateways& updatables, GatewayUpdaters& updaters, Secrets& secrets) const;

/**
* @brief Implementation of legacy gateway transformation invoked only during preparation of
Expand Down

0 comments on commit 1d0acb2

Please sign in to comment.