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" ?
In case of a property with default scope :
get-property('MyProperty')
OR
<script language="js">
mc.getProperty("MyProperty");
</script>
In case of a property with 'transport' scope :
get-property('transport','FILE_NAME')
OR
<script language="js">
mc.????????
</script>
I don't think
mc
haveget-property
method.Script Mediator use the Apache
Bean Scripting Framework
for scripting language support. And themc
variable represents an implementation of theMessageContext
, namedScriptMessageContext.java
.[Here is the Class of
ScriptMessageContext
][1][1]: https://synapse.apache.org/apidocs/org/apache/synapse/mediators/bsf/ScriptMessageContext.html
You can check any DEFAULT scope property(method) in there.
If not, you may need to put these scope property in custom property. Like:
Then use the getProperty("CustomAction") in JS to get them.
It seems that you can not get properties of other scopes than synapse using
since mc is instance of Synapse.MessageContext in order to get other message context properties I do something like this in java, I don't know that if it is applicable in javascript or not. I do this for axis2 message context properties. Here "context" is the instance of Synapse.MessageContext.
You can get property using this code:
I test it with WSO2ESB 4.9.0
Update:
If your property is not define in default scope, first you must define it in default scope.
for example:
It should works with ESB 4.5.0 and above
I did something like below