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

时间:2014-09-05 15:07:57

标签: wso2 wso2esb

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

3 个答案:

答案 0 :(得分:4)

您可以在中介中使用示例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来创建资源

答案 1 :(得分:0)

我有适合您的解决方案!

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

这个想法来自http://wso2-oxygen-tank.10903.n7.nabble.com/How-to-Store-Log-Message-in-a-Registry-File-in-EI-td159169.html

答案 2 :(得分:0)

我使用这种方式从 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"/>