Writing content into WSO2 Registry through WSO2 ESB mediators
With
ESB 4.9.0
release we can achieve this directly using the property mediators registry scope.
In WSO2 ESB 4.8.1
there is no direct way to save content to registry through stock synapse mediators. This post describes two possible options we have with ESB 4.8.1
to save content to the registry. Those are by using either the Script Mediator or the Class Mediator.
Following examples shows how to store the value of property myProperty
of type String in message context into the registry path
conf:/store/myStore
Script Mediator
Achieving this with script mediator is relatively easy. Note that using the script mediator will have some performance impact on your mediation logic.
Here is a sample code snippet of a script mediator to save the value stored under myProperty
in message context to the registry.
Class Mediator
First of all, you need to create a class mediator. You can follow this guide to write your own class mediator. After that what you need is to write some Java code similar to following to store the content into the registry.
Retrieve content
To retrieve the stored content you can simply use the get-property
XPath function with registry
scope as follows.
<property name="regContent"
expression="get-property('registry', 'conf:/store/myStore')"/>
Cheers!
Written by Asitha Nanayakkara