Hemant
Hemant

Reputation: 61

Calling property file from a session variable in mulesoft

I have stored a record type id in a property file in my application, now I want to define a session variable which can call this property file to read the id written in it, so that I can use this session variable in my query.

Could anyone help me what should I declare in value in session variable as a {$} does not allow doing this. Also let me know if session variable is good for doing this task or need to take something else.

Upvotes: 0

Views: 644

Answers (3)

siva
siva

Reputation: 1

my.properties id=1234

To read the above id in session variable: 1. Create a Property Placeholder in GlobalElements: In proeprty place holder component: Location: file:/my.proeprties

  1. Drag a session variable into your flow In session variable Name: myid Value: {id}

.mflow:

.... /my.proeprties"/>

Output: --Id value is 1234

Upvotes: 0

Anirban Sen Chowdhary
Anirban Sen Chowdhary

Reputation: 8311

I am not sure what is causing the issue ...
I am able to read from properties file and execute that session variable in SQL query :-
For example let my properties file be test.properties and it has following values :-

id=44

So, now I am able to fetch the value from properties file and store into session variable as ${id} as you see in the code :-

<set-session-variable variableName="abc" value="${id}" doc:name="Session Variable"/>

... also I am able to use that session variable in DB SQL query

 <context:property-placeholder location="classpath:test.properties"/>
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8088" doc:name="HTTP Listener Configuration"/>
    <flow name="testFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <set-session-variable variableName="abc" value="${id}" doc:name="Session Variable"/>
        <db:select config-ref="Generic_Database_Configuration" doc:name="Database">
            <db:parameterized-query><![CDATA[Select * from table1 where ID=#[sessionVars['abc']];]]></db:parameterized-query>
         </db:select>
        <object-to-string-transformer doc:name="Object to String"/>

    </flow>

And I am able to get the value from DB as follows :- enter image description here

Upvotes: 1

Ryan Carter
Ryan Carter

Reputation: 11606

You can access a property and store in a session variable like so:

#[${my.property}]

Upvotes: 1

Related Questions