动态更新 WSO2 EI 6.1.1 中的注册表文件内容

Update Registry file content in WSO2 EI 6.1.1 dynamically

我将配置文件存储在 配置注册表 中,如下所示。

我的用例是,需要从 wso2 ei 服务更新 accessToken 标签内容,因为它会在一小时内过期。我如何将重新生成的 accesstoken 传递给这个文件?

    <!-- Reading config registry file content -->
    <property name="ZohoAppConfig" expression="get-property('registry','conf:/ZohoConfig/ZohoAppConfigFile.xml')" scope="default" type="OM" />
           <property description="accessToken" expression="$ctx:ZohoAppConfig//*[local-name()='accessToken']" name="accessToken" scope="default" type="STRING"/>
            <property description="refreshToken" expression="$ctx:ZohoAppConfig//*[local-name()='refreshToken']" name="refreshToken" scope="default" type="STRING"/>
            <property description="AllPortalsEP" expression="$ctx:ZohoAppConfig//*[local-name()='AllPortals']" name="uri.var.AllPortalsEP" scope="default" type="STRING"/>
            <log level="custom">
                <property name="===ZohoAppConfig===" expression="get-property('ZohoAppConfig')"/>
                <property expression="get-property('accessToken')" name="===accessToken===="/>
                <property expression="get-property('uri.var.AllPortalsEP')" name="===uri.var.AllPortalsEP===="/>
            </log>
<!-- Need to update registry content here -->

等待您的回复。

您可以修改 ZohoAppConfig,例如使用 enrich mediator:

<enrich>
   <source clone="true" property="someNewAccesToken" type="property"/>
   <target action="replace" xpath="$ctx:ZohoAppConfig//accessToken" type="custom" xmlns:ns="http://org.apache.synapse/xsd"/>
</enrich>

这将在您的 属性 ZohoAppConfig 中更新令牌。接下来要存储回注册表,您需要使用 属性:

<property expression="$ctx:ZohoAppConfig" name="conf:/ZohoConfig/ZohoAppConfigFile.xml"
        scope="registry" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>

这在 6.1.1 中应该有效,我在 6.3.0 上测试过。但这种方式是在内存中缓存读取 15 秒,在某些情况下可能会出现问题。 另一种方法是使用 script mediator 存储,并将 cacheDuration 设置为 0:

    <script language="js"><![CDATA[
mc.getConfiguration().getRegistry().updateResource('conf:/ZohoConfig/ZohoAppConfigFile.xml',mc.getProperty('sample'));
var regEntry = mc.getConfiguration().getRegistry().getRegistryEntry('conf:/ZohoConfig/ZohoAppConfigFile.xml');
regEntry.setCachableDuration(0);
mc.getConfiguration().getRegistry().updateRegistryEntry(regEntry);
]]></script>

我已经用一个例子描述了更多,还有一些遇到的问题here