wso2esb-访问迭代器调解器之外的变量 [英] wso2esb- accessing variable outside iterator mediator

查看:29
本文介绍了wso2esb-访问迭代器调解器之外的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,在迭代器内部,我正在使用脚本(名称:setValue)中介器设置一些变量.我试图在迭代器外的 Ruby 脚本中访问它们.

Basically, inside iterator, I am setting some variable using Script (name: setValue) mediator. I am trying to access them in the Ruby script outside the iterator.

根据文档:如何访问迭代器内部定义的迭代器外部的属性中介?

我尝试过的不同选项:

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

1) In Ruby script, I tried using

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

2) 在 Iterator 之外,我尝试使用 Property 访问它们

2) Outside Iterator I tried accessing them using Property

<property   expression="get-property('operation','githubhosturl')  name="githubhosturl1) 

在表达式中出错.

3) 在我尝试过的 Ruby 脚本中:

3) In Ruby script I tried:

$mc.get-property('githubhosturl1') - 返回空值

$mc.get-property('githubhosturl1') - Empty value returning

我该如何解决这个问题?

How can I solve this issue?

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

My code - proxy service - I am pasting only small portion, where there is an issue. In setValue script I am able to print the value in the console log.

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

推荐答案

通过将 Iteration 内的所有范围从default"更改为Operation"并使用 get-property('operation', variable) 在外部访问它们,然后将范围更改为默认"

By changing all the scope inside the Iteration from "default" to "Operation" and access them outside using get-property('operation', variable) and then change the scope to "Default"

这篇关于wso2esb-访问迭代器调解器之外的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆