Friday, December 4, 2015

How to use Local Entries in a WSO2 ESB Proxy Service.


In this blog post I am going to show you how to use local entries in a WSO2 ESB Proxy.

What is Local Entry?

In simply it is like a CONSTANT file. It stores text strings, XML strings, and URLs. These entries can be retrieved from a mediator.

Consider the following the example proxy.


 
Here the highlighted property values are hard coded. Since it is a bad practice in coding we can use local entries to store these property values and can be retrieved from a mediator.



How to add a Local Entry ?

Go to ESB management console and click on Main tag. 

 


Select Local Entries from the menu.

 

 
There are three types of local entries as shown in the below figure. In this example I used In-lined Text Entry.

 
 
Click on “Add In-lined Text Entry”.
Then you will receive the following console.

 


 
Enter a proper name for the local entry and enter a value for the local entry.
Here “ApiUrl” is the name and “http://wso2.com” is the value of the local entry.
Click on “Save”.

Like wise you can create local entries for all the properties appear in the above proxy service.

 
How to read a value stored in a local-entry?

Let's say I have a value stored in local-entry file 'apiUrl'.

<localEntry key="apiUrl" xmlns="http://ws.apache.org/ns/synapse"><![CDATA[https://wso2.com]]></localEntry>

This is how we can read this value into a mediator.

<property name="apiUrl" expression="get-property('apiUrl')" scope="default" type="STRING"/>

Here you can give any name as the “property name” and inside the get-property('.......') you should give the key of the local entry.
 

No comments:

Post a Comment