问题
Is there any way by which, I can update local entry from esb service. I have to store a token in global variable and need to update it when it is expired. I want to keep it in local entry. Looks like I can not update it from ESB service/sequence.
<localEntry key="TestLocalEntry" xmlns="http://ws.apache.org/ns/synapse"><![CDATA[TestValue]]></localEntry>
回答1:
If you requirement is to store a global variable and not really update a local entry, you can use esb registry
Try this js to create / update an entry in governance registry (and store current payload xml in this sample) :
<script language="js"><![CDATA[
importPackage(Packages.org.apache.synapse.config);
mc.getConfiguration().getRegistry().newResource("gov:/trunk/test/MyEntry.xml",false);
mc.getConfiguration().getRegistry().updateResource("gov:/trunk/test/MyEntry.xml",mc.getPayloadXML().toString());
]]></script>
Try this xpath expression in your mediation to read the entry :
get-property('gov:/trunk/test/MyEntry.xml')
回答2:
I have managed to fix this problem with java script.
To get property value use :
<script language="js"><![CDATA[var Token = mc.getEnvironment().getServerContextInformation().getProperty("TokenVal");
mc.setProperty("TokenVal",Token);]]></script>
<property expression="$ctx:TokenVal" name="TokenValue"
type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
and to update value use:
<script language="js"><![CDATA[var TokenValue = mc.getProperty("TokenValue");
mc.getEnvironment().getServerContextInformation().addProperty("TokenVal",TokenValue);
]]></script>
but even then, I want to use registry resources if we have any in wso2 esb
来源:https://stackoverflow.com/questions/46542477/update-local-entry-in-wso2-esb-via-servce