使用脚本中介在 JavaScript 中获取属性值

2022-01-17 00:00:00 javascript wso2 wso2esb synapse

有没有办法在 WSO2 ESB 的脚本中介的 javascript 代码中,当该属性的范围不同于默认"时获取该属性的值?

Is there a way, inside the javascript code from WSO2 ESB's Script mediator, to get a property's value when this property has a scope different from "default" ?

如果属性具有默认范围:

get-property('MyProperty') 

<script language="js">
   mc.getProperty("MyProperty");
</script>

如果属性具有运输"范围:

get-property('transport','FILE_NAME')

<script language="js">
   mc.????????
</script>

推荐答案

您可以使用以下代码获取属性:

You can get property using this code:

<property name="ComingRoles" expression="your property or value" scope="default"  />
<script language="js">var rolelist = mc.getProperty('ComingRoles');</script>

我用 WSO2ESB 4.9.0 测试它

I test it with WSO2ESB 4.9.0

更新:

如果你的属性没有在默认范围内定义,首先你必须在默认范围内定义它.

If your property is not define in default scope, first you must define it in default scope.

例如:

<property name="authheader" expression="get-property('transport','X-JWT-Assertion')"></property>
<script language="js"> var temp_auth = mc.getProperty('authheader')
</script>

它应该适用于 ESB 4.5.0 及更高版本

It should works with ESB 4.5.0 and above

相关文章