behzad
behzad

Reputation: 196

save a dynamic value in wso2 esb for next use

i need to save result of web service login method as a property in wso2 esb. and use it whenever i want. token will be expired in 20 min so i want to save token in wso2 esb and when it expire regenerate it. how can i save a property dynamic in wso2 esb and retrieve it. my sequence to generate tokekn is :

<sequence name="x" xmlns="http://ws.apache.org/ns/synapse">
<payloadFactory media-type="xml">
    <format>
        <p:login xmlns:p="http://corebankingservice.endpoint.webservicegateway.core.channelmanager.caspian.com/">
            <chUserInfoRequestBean xmlns="">
                <password>****</password>
                <username>user</username>
            </chUserInfoRequestBean>
            <channelServiceType xmlns="">***</channelServiceType>
        </p:login>
    </format>
</payloadFactory>
<send>
    <endpoint>
        <address uri="http://x.x.x.x:8280/services/..."/>
    </endpoint>
</send>
</property name="SessionId" value = ...>
</sequence>

result of this sequence is SessionId so i need to save SessionId in memory or db or .... and use it for another method until it will be expired. how can i save such a this property in registery or cashe or database and use it later.

Upvotes: 0

Views: 954

Answers (2)

Lotzy
Lotzy

Reputation: 726

With WSO2 Enterprise Integrator 6.x.x and up, it's possible to set a property with scope "registry" that will persist the value between calls and being globally visible.

For example to persist the access token received in the JSON response:

<property description="propAccessToken" expression="json-eval($.access_token)" name="access_token" scope="registry" type="STRING"/>

Then to get the property use the following expression:

get-property('registry', 'access_token')

Upvotes: 1

Martin Hald
Martin Hald

Reputation: 676

The only "official" way I know (which I used), is to use the dblookup mediator (retrieve the value later) and dbreport meditaor (to store the value) in a database.

Write value to a db:

<dbreport>
              <connection>
                 <pool>
                    <dsName>datasource_name</dsName>
                 </pool>
              </connection>
              <statement>
                 <sql>
                                insert into table (attributName1, attributName2) values ('value1','value2')</sql>
                       </statement>
           </dbreport>

The values can be passed from a property like in this example.

<sql>
                                insert into dbo.sais_config_db (serviceName, configKey, configValue) values ('staticVal1','staticVal2',?)</sql>
                 <parameter expression="get-property('myPropertyName')" type="CHAR"/>

Read value:

<dblookup>
              <connection>
                 <pool>
                    <dsName>sais_config_db</dsName>
                 </pool>
              </connection>
              <statement>
                 <sql>
                    SELECT value1 FROM tableName where ....</sql>
                 <result name="resultFromDb" column="value1"/>
              </statement>
           </dblookup>

Hope that helps. There is another option, but I don't know if that works (haven't tried it).

Link

Upvotes: 2

Related Questions