WSO2 Enterprise Integrator (6.5) – how to Store and retrieve Registry data using dynamic registry path

WSO2 Enterprise Integrator (6.5) – how to Store and retrieve Registry data using dynamic registry path

Problem Description:

I have a sequence to utilise an API which issues time-constrained bearer tokens from an authorization endpoint based on client ID and Secret. The Bearer Token remains valid for 1 hour and so I’m storing the bearer token and its expiry time in the registry whenever I renew the token and on subsequent calls will use the stored token rather than request a new one – unless it’s expired.

This is all working as expected – however – it is feasible that this Sequence could be called from processes that have different client IDs – so for scalability I would like to modify the process so the Token and expiry are held under a registry branch for each client_id.

I’m unable to find a way to dynamically create the registry entries to incorporate the client_id in the registry path.

I can Read from a dynamic path successfully as follows:

<property expression="get-property('registry', fn:concat('conf:/resource/MyApplication/',$ctx:client_id,'/TokenExpiry'))" name="RegBearerExpiryStr" scope="default" type="STRING"/>

but I cannot work out how to successfully Write a registry entry in a similar fashion.

I have tried the following with no success – I can see from the wire logs that everything in the key name is being interpreted literally :

<property expression="json-eval($.access_token)" name="fn:concat('conf:/resource/MyApplication/',$ctx:client_id,'/TokenExpiry'))" scope="registry" type="STRING"/>

and

<property expression="json-eval($.access_token)" name="conf:/resource/MyApplication/{$ctx:client_id}/TokenExpiry" scope="registry" type="STRING"/>

I’m running EI 6.4 and 6.5

Any brilliant ideas – there must surely be a way to create a dynamic path for writing as well as reading ?

Solution – 1

I personally use jsonObject XML and use OM type for storing complex types as WSO2 has better xml type support.

<property expression="//jsonObject" name="token" scope="default" type="OM"/> 
<property name="conf:/storage/SampleToken.xml" scope="registry" expression="$ctx:token" type="OM"/>

But, there is one "pitfall", as WSO2 are cacheing the registry entries for default 15seconds. So you will read old values for some time. If that is a problem i use workaround. I use script mediator for better handling that, and with checking if that resource exist or not. I tested it on EI 6.5

<script language="js"><![CDATA[
 var regUrl = mc.getProperty('regUrl');
 var registry = mc.getConfiguration().getRegistry();
 
 if(registry.isResourceExists(regUrl) == false) {
    registry.newResource(regUrl, false);
 }   
 registry.updateResource(regUrl,mc.getProperty('token'));

 var regEntry = registry.getRegistryEntry(regUrl);
 regEntry.setCachableDuration(0);
 registry.updateRegistryEntry(regEntry);]]>
</script>

I also made some blog post, may be also useful::
Reading, modifying and writing data in WSO2 Enterprise Integrator registry on an example

Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject