简体   繁体   English

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

[英]Update Registry file content in WSO2 EI 6.1.1 dynamically

I am storing config file in Config registry like below.我将配置文件存储在配置注册表中,如下所示。

配置注册表文件

My use case here is, need to update accessToken tag content from wso2 ei service,because it expires within an hour.我的用例是,需要从 wso2 ei 服务更新accessToken标签内容,因为它会在一小时内过期。 how can i pass regenerated accesstoken to this file?我如何将重新生成的访问令牌传递给这个文件?

    <!-- 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 -->

Awaiting for your response.等待您的回复。

You can modify your ZohoAppConfig, for example using enrich mediator:您可以修改您的 ZohoAppConfig,例如使用丰富的中介:

<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>

This will update in your property ZohoAppConfig the token.这将在您的财产 ZohoAppConfig 中更新令牌。 Next to store back to registry you need use property:接下来要存储回注册表,您需要使用属性:

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

That should works in 6.1.1, I tested it on 6.3.0.这应该适用于 6.1.1,我在 6.3.0 上对其进行了测试。 but that way is caching the read in memory for 15sec, what could be in some cases problematic.但这种方式会将读取的内容缓存在内存中 15 秒,这在某些情况下可能会出现问题。 Another way is to store using script mediator , and set the cacheDuration to 0:另一种方法是使用脚本 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>

I have described it much more with an example, along with some encountered problem here我已经用一个例子对它进行了更多的描述,还有一些在这里遇到的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM