How to create a Global Variable in Wso2 ESB

3k views Asked by At

I am new to the WSO2 esb,Am working with wso2esb 4.7.0,wso2dss 3.0.0.

I want to create a global variable and call that variable into my proxy services

My proxy is as shown below

<proxy xmlns="http://ws.apache.org/ns/synapse" name="Get_details" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
 <target endpoint="Endpoint">
  <inSequence>
     <property name="messageType" value="application/json" scope="axis2" type="STRING"/>        
     <property name="username" expression="//username/text()" scope="default" type="STRING"/>
     <property name="password" expression="//password/text()" scope="default" type="STRING"/>
     <log>
        <property name="username" expression="get-property('username')"/>
        <property name="password" expression="get-property('password')"/>
     </log>
     <payloadFactory media-type="xml">
        <format>
           <p:select_login_op xmlns:p="http://ws.wso2.org/dataservice">
              <p:username>$1</p:username>
              <p:password>$2</p:password>
           </p:select_login_op>
        </format>
        <args>
           <arg evaluator="xml" expression="get-property('username')"/>
           <arg evaluator="xml" expression="get-property('password')"/>
        </args>
         </payloadFactory>
         <property name="Get"       expression="fn:concat('http://192.168.1.201:9764/services/', 'Get_details')"/>
            <header name="To" expression="get-property('Get')"/>
        <send>
        <endpoint>
           <default/>
        </endpoint>
     </send>
      </inSequence>
       <outSequence>
     <send/>
      </outSequence>
   </target>
   <description/>
   </proxy> 

In the above proxy i have used concat function to combine my Url and Service name,here what i want to do is i want to use a variable instead of url by creating a global variable and assign the url as its value and use that variable in the concat function instead of url in this proxy and several other proxy also.

How can this be done?

2

There are 2 answers

0
Sumedha Kodithuwakku On

You can save the value as a Local Registry Entry and use it from inside proxy services. For example if I have a Local Entry called 'MyURL' I can use it as below

synapse:get-property('MyURL')

Another example;

 <log level="custom">
    <property name="MyURL" expression="synapse:get-property('MyURL')"/>
 </log>
1
Rodrigo Nogueira On

A sample for ESB 5.0.0:

Suppose we have the current time in a property named nowTimeProp.

<property name="nowTimeProp" expression="get-property('SYSTEM_TIME')" scope="default"/>

Storing the property in the registry:

<property name="conf:/resource/yourResourceName" type="STRING" expression="$ctx:nowTimeProp" scope="registry"/>

Later, we'd like to read the property from the registry:

<property name="lastStoredInstantProp" expression="get-property('registry', 'conf:/resource/yourResourceName')"/>