在WSO2 ESB中进行调解期间修改配置注册表资源内容

在WSO2 ESB中进行调解期间修改配置注册表资源内容,wso2,wso2esb,Wso2,Wso2esb,我有一个场景,需要将简单计数器存储在配置注册表中,并在序列流结束时递增它。我们需要存储在配置注册表中的原因是为了防止服务器重新启动,我们保留了最后一个计数器值。有人能建议如何在config registry中增加计数器吗?您可以在中介中使用的示例javascript将当前消息保存在注册表中: <script language="js"><![CDATA[ importPackage(Packages.org.apache.synapse.config); mc.

我有一个场景,需要将简单计数器存储在配置注册表中,并在序列流结束时递增它。我们需要存储在配置注册表中的原因是为了防止服务器重新启动,我们保留了最后一个计数器值。有人能建议如何在config registry中增加计数器吗?

您可以在中介中使用的示例javascript将当前消息保存在注册表中:

<script language="js"><![CDATA[
    importPackage(Packages.org.apache.synapse.config);
    mc.getConfiguration().getRegistry().newResource("gov:/trunk/mypath/MyResource.xml",false);
    mc.getConfiguration().getRegistry().updateResource("gov:/trunk/mypath/MyResource.xml",mc.getPayloadXML().toString());
]]></script>


newResource第一次用于创建资源

我为您提供了此解决方案

  <script language="nashornJs"><![CDATA[
                 
                var body = mc.getPayloadXML();
                print(body);
                var registryPath = "gov:/portales/date.xml";
                    
                    if(body != null && body != ''){
                        var existingProperty = mc.getConfiguration().getRegistry().getResource(registryPath);
                        print(body);
                        if(existingProperty == null){
                        print(body);
                            // Create the registry entry if no such entry exists.
                            mc.getConfiguration().getRegistry().newResource(registryPath, false);
                            mc.getConfiguration().getRegistry().updateResource(registryPath, body);
                            
                        } else {
                        print(body);
                            // Update the registry entry if it already exists.
                            mc.getConfiguration().getRegistry().updateResource(registryPath, body);
                        }
                    }]]></script>


这个想法来源于我用这种方式从POST请求中获取json负载,并以xml格式存储在注册表中

        <datamapper config="gov:datamapper/conversionToSaveInRegistry.dmc" description="conversionToSaveInRegistry" inputSchema="gov:datamapper/conversionToSaveInRegistry_inputSchema.json" inputType="JSON" outputSchema="gov:datamapper/conversionToSaveInRegistry_outputSchema.json" outputType="XML" xsltStyleSheet="gov:datamapper/conversionToSaveInRegistry_xsltStyleSheet.xml"/>
        <property name="messageType" scope="axis2" type="STRING" value="application/xml"/>
        <script language="nashornJs"><![CDATA[
            var body = mc.getPayloadXML();
            var registryPath = "gov:/generated/date.xml";
                
                if(body != null && body != ''){
                    var existingProperty = mc.getConfiguration().getRegistry().getResource(registryPath);
                    if(existingProperty == null){
                        // Create the registry entry if no such entry exists.
                        mc.getConfiguration().getRegistry().newResource(registryPath, false);
                        mc.getConfiguration().getRegistry().updateResource(registryPath, body);
                        
                    } else {
                        // Update the registry entry if it already exists.
                        mc.getConfiguration().getRegistry().updateResource(registryPath, body);
                    }
                }]]></script>
        <property name="NO_ENTITY_BODY" scope="axis2" type="BOOLEAN" value="true"/>
        <property name="HTTP_SC" scope="axis2" type="STRING" value="201"/>