wso2esb-访问迭代器调解器之外的变量
wso2esb- accessing variable outside iterator mediator
基本上,在迭代器内部,我使用脚本(名称:setValue)调解器设置一些变量。我试图在迭代器外的 Ruby 脚本中访问它们。
根据文档:
我试过的不同选项:
1) 在 Ruby 脚本中,我尝试使用
$mc.get-property('Operation','githubhosturl1'); I am getting syntax error at operation.
2) 在 Iterator 之外我尝试使用 属性
访问它们
<property expression="get-property('operation','githubhosturl') name="githubhosturl1)
表达式出错。
3) 在 Ruby 脚本中我试过:
$mc.get-属性('githubhosturl1') - 返回空值
我该如何解决这个问题?
我的代码 - 代理服务 - 我只粘贴了一小部分,那里有问题。在 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>
通过将迭代内的所有范围从 "default" 更改为 "Operation" 并使用 get-属性('operation', variable) 在外部访问它们,然后更改范围 "Default"
基本上,在迭代器内部,我使用脚本(名称:setValue)调解器设置一些变量。我试图在迭代器外的 Ruby 脚本中访问它们。
根据文档:
我试过的不同选项:
1) 在 Ruby 脚本中,我尝试使用
$mc.get-property('Operation','githubhosturl1'); I am getting syntax error at operation.
2) 在 Iterator 之外我尝试使用 属性
访问它们<property expression="get-property('operation','githubhosturl') name="githubhosturl1)
表达式出错。
3) 在 Ruby 脚本中我试过:
$mc.get-属性('githubhosturl1') - 返回空值
我该如何解决这个问题?
我的代码 - 代理服务 - 我只粘贴了一小部分,那里有问题。在 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>
通过将迭代内的所有范围从 "default" 更改为 "Operation" 并使用 get-属性('operation', variable) 在外部访问它们,然后更改范围 "Default"