1

I have a Mule flow in which there is a session variable "servicerequested" and this variable can have different values like - customerservice,accountservice,transferservice,etc.

There is a property file mule.dev.properties which has information of ports based on this service options:

customerservice=9914 
accountservice=9918
transferservice=9919

I want an http outbound endpoint to choose the port from this properties file based on the variable requestedservice. I tried using the MEL as below:

${#[header:session:servicerequested]}

<http:outbound-endpoint exchange-pattern="request-response" host="localhost" 
port="${#[header:session:servicerequested]}" path="services" method="GET"/>

but it throws the exception

Template Endpoint "http://localhost:session:servicerequested]/services" resolved 
into a Malformed endpoint "http://localhost:session:servicerequested]/services"

Please let me know how we can read property file dynamically using MEL.

David Dossot
  • 33,403
  • 4
  • 38
  • 72
user2254601
  • 164
  • 2
  • 8

2 Answers2

0

From your post I could see that the session variable is the condition based on which the value from properties file is picked.

But the problem is the property file is loaded once your application is deployed. But the session varaible is available only during the flow execution.

So the expression ${#[header:session:servicerequested]} will not work because at the time the properties file is referred for value, the #[MEL] is not yet available.

Possible solution could be to load your properties into some flow varaibles and then based on the session varaible value pick one of those flow varaibles.

Also all this could not happen in a single MEL statement.

Try storing properties as flow variables like below

<set-variable variableName="prop1" value="${property key from properties file}" />
<set-variable variableName="prop2" value="${property key from properties file}" />

and then build a custom component or groovy to evaluate the session varaible and pick one of the flow varaibles and then use that value at your port attribute.

Hope this helps :)

David Dossot
  • 33,403
  • 4
  • 38
  • 72
user1760178
  • 6,277
  • 5
  • 27
  • 57
  • Your suggestion is good David!Thanks. But in my case we don't know how many properties will be there in the property file. So how many variables should be created is dynamic. – user2254601 Jun 05 '13 at 06:19
  • If you are not sure of how many properties will be existing in the properties file, then I am not sure of something that can help in such a case. But if you have too many properties to be declared as flow variables. Then prepare pojo bean with all those properties as constants loaded from properties file and then try accessing the constants from bean based on your session property. – user1760178 Jun 05 '13 at 12:18
0

You can create java component and read properties directly.It's most simplest solution. Alternative can be to configure ReloadableResourceBundleMessageSource in Spring to read properties.

babkamen
  • 3
  • 1
  • 2