From fed15e889e1c3614bfaf7d8c6f6229535fceb331 Mon Sep 17 00:00:00 2001 From: Christopher Broderick Date: Tue, 1 Aug 2023 10:35:57 +0100 Subject: [PATCH] Support the use of properties in the basePollerConfig element attribute values. --- .../partner/XMLPartnershipFactory.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/org/openas2/partner/XMLPartnershipFactory.java b/Server/src/main/java/org/openas2/partner/XMLPartnershipFactory.java index 4421ed06..7f5d21a4 100644 --- a/Server/src/main/java/org/openas2/partner/XMLPartnershipFactory.java +++ b/Server/src/main/java/org/openas2/partner/XMLPartnershipFactory.java @@ -216,7 +216,13 @@ public void loadPartnership(Map partners, List part // Now check if we need to add a directory polling module Node pollerCfgNode = XMLUtil.findChildNode(node, Partnership.PCFG_POLLER); if (pollerCfgNode != null) { - // Load a poller configuration + /* Load a poller configuration. + * This will require fetching the base configuration for the pollers loaded from + * the config.xml and merging with the configured setup in the partnership + * overriding the base attribute values with any found in the partnership + * pollerConfig element then enhancing the attribute values to cater for embedded + * dynamic variables before activating the poller. + */ String[] requiredPollerAttributes = {"enabled"}; Map partnershipPollerCfgAttributes = XMLUtil.mapAttributes(pollerCfgNode, requiredPollerAttributes); if ("true".equalsIgnoreCase(partnershipPollerCfgAttributes.get("enabled"))) { @@ -236,10 +242,15 @@ public void loadPartnership(Map partners, List part } Element pollerConfigElem = pollerDoc.getDocumentElement(); // Merge the attributes from the base config with the partnership specific ones - partnershipPollerCfgAttributes.forEach((key, value) -> { + Map attributes = XMLUtil.mapAttributes(pollerConfigElem); + attributes.putAll(partnershipPollerCfgAttributes); + // Enhance the attribute values in case they are using dynamic variables + AS2Util.attributeEnhancer(attributes); + // Now update the XML with the attribute values + attributes.forEach((key, value) -> { pollerConfigElem.setAttribute(key, value); - }); - // replace the $parnertship.* placeholders + }); + // replace the $partnertship.* placeholders replacePartnershipPlaceHolders(pollerDoc, partnership); // Now launch a directory poller module for this config getSession().loadPartnershipPoller(pollerConfigElem, name, Session.PARTNERSHIP_POLLER); @@ -354,6 +365,7 @@ public void replacePartnershipPlaceHolders(Document doc, Partnership partnership for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); String val = node.getNodeValue(); + //logger.debug("Partnership place holder NODE processing: " + val); StringBuffer strBuf = new StringBuffer(); Matcher matcher = PATTERN.matcher(val); boolean hasChanged = false; @@ -392,6 +404,9 @@ public void replacePartnershipPlaceHolders(Document doc, Partnership partnership } else { hasChanged = true; matcher.appendReplacement(strBuf, Matcher.quoteReplacement(value)); + if (logger.isTraceEnabled()) { + logger.trace("Partnership place holder replaced: " + keys + " :: Replaced with: " + value); + } } } if (hasChanged) {