wso2esb-访问迭代器中介之外的变量

时间:2017-10-14 04:23:29

标签: ruby-on-rails wso2esb wso2carbon

基本上,在迭代器中,我使用Script(name:setValue)mediator设置一些变量。我试图在迭代器之外的Ruby脚本中访问它们。

根据文件:How to access property mediator outside iterator which is defined inside iterator?

我尝试了不同的选项:

1)在Ruby脚本中,我尝试使用

$mc.get-property('Operation','githubhosturl1');  I am getting syntax error at operation.

2)Iterator外部我尝试使用Property

访问它们
<property   expression="get-property('operation','githubhosturl')  name="githubhosturl1) 

在表达式上收到错误。

3)在Ruby脚本中我试过:

$ mc.get-property(&#39; githubhosturl1&#39;) - 返回空值

我该如何解决这个问题?

我的代码 - 代理服务 - 我只粘贴一小部分,存在问题。在setValue脚本中,我可以在控制台日志中打印该值。

<Iterator>
-------
--------
-------
<script description="setValue" language="js"><![CDATA[var log = mc.getServiceLog(); 
            var tool =  mc.getProperty('toolList');

           if( tool == "github")
           {    
                var vhosturl = mc.getProperty('catName');
                mc.setProperty('githubhosturl',vhosturl.toString());
                var vassetid = mc.getProperty('assetidval');
                mc.setProperty('gitassetid',vassetid.toString());
                var vbranch="qa";
                mc.setProperty('gitbranch',vbranch.toString());
           }
           if( tool == "dockercloud")
           {
                var vhosturl = mc.getProperty('catName');
                mc.setProperty('dockerhosturl',vhosturl.toString());
                var vassetid = mc.getProperty('assetidval');
                mc.setProperty('dockerid',vassetid.toString());
                var creid = mc.getProperty('jsondata');
                mc.setProperty('doccredid',creid.toString());
                var vprojName = mc.getProperty('projName');
                mc.setProperty('docproj',vprojName.toString());
           }]]></script>
        <property expression="get-property('githubhosturl')" name="githubhosturl1" scope="operation" type="STRING"/>
        <property expression="get-property('gitbranch')" name="gitbranch1" scope="operation" type="STRING"/>
        <property expression="get-property('gitassetid')" name="gitassetid1" scope="operation" type="STRING"/>
        <property expression="get-property('dockerhosturl')" name="dockerhosturl1" scope="operation" type="STRING"/>
        <property expression="get-property('doccredid')" name="doccredid1" scope="operation" type="STRING"/>
        <property expression="get-property('docproj')" name="docproj1" scope="operation" type="STRING"/>
    </sequence>
</target>
</iterate>
<script description="re" language="rb"><![CDATA[require 'erb'
     require 'erb'

     @giturl = $mc.getProperty('githubhosturl1');
      @gitbranch = $mc.getProperty('gitbranch1');
      @gitcredential = $mc.getProperty('gitassetid1');

      @dockerurl = $mc.getProperty('dockerhosturl1');
      @dockerCred = $mc.getProperty('doccredid1');
      @dockerprojectname = $mc.getProperty('docproj1');

      @template = File.read('C:\WS02\workspace\index.txt.erb')
      OutTemplate = ERB.new(@template).result( binding )

      File.open('C:\WS02\workspace\Jenkin.groovy',"w") do |f|
         f.puts OutTemplate
      end]]></script>

1 个答案:

答案 0 :(得分:0)

通过更改&#34;默认&#34;中的迭代内的所有范围到&#34;操作&#34;并使用get-property(&#39; operation&#39;,变量)在外部访问它们,然后将范围更改为&#34;默认&#34;