Reputation: 174
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.
Upvotes: 1
Views: 5699
Reputation: 13
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.
Upvotes: 0
Reputation: 6697
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 :)
Upvotes: 0