KerenSi
KerenSi

Reputation: 389

How to read properties from .properties file in Mule

I'm trying to use Mule Credentials Vault security feature. I've created .properties file, Security Property Placeholder and defined the key and encryption algorithm. Now I want to use some of the properties from the file when I return HTTP response.

I have the file src/main/resources/data.properties that contains for example:

In my canvas, under Configuration XML I added:

<secure-property-placeholder:config name="Secure_Property_Placeholder" key="24681357" location="data.properties" doc:name="Secure Property Placeholder" encryptionAlgorithm="DES"/>

<set-variable variableName="card.number" value="${number}" />

In my canvas I have message flow that builds xml 'Create XML response based on User'. The value in settings is:

This doesn't work. The error I get is:

-> org.mule.module.launcher.DeploymentInitException: IllegalArgumentException: Could not resolve placeholder 'key' in string value "${key}"

-> Caused by: org.mule.api.lifecycle.InitialisationException: Invalid bean definition with name 'org.mule.autogen.bean.13' defined in null: Could not resolve placeholder 'key' in string value "${key}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'key' in string value "${key}"

-> Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'key' in string value "${key}"

Does anyone know how can I read the properties from .properties file (credentials vault)? And then use it in my flow?

Thanks, Keren

Upvotes: 1

Views: 7669

Answers (4)

Srinivas
Srinivas

Reputation: 92

From Dataweave you can read it as given below p('variablename') where variablename is defined in property files ex: variablename = 15

Upvotes: 0

Adithya
Adithya

Reputation: 1

The property placeholder is used resolve at startup so you will not be able to dynamically retrieve a property based on some user input.

Use ${propertyName} from .properties in MEL to access particular property

Upvotes: 0

Pontus Ullgren
Pontus Ullgren

Reputation: 705

If you simply want to get the value for the property number and add it into the XML you can use ${number} from .properties. No need to define any other variables in Configuration XML.

<set-payload value="&lt;user&gt;&lt;name&gt;Royal Bank of Canada&lt;/name&gt;&lt;id&gt;Royal_Bank_Of_Canada&lt;/id&gt;&lt;cc&gt;&lt;company&gt;&gt;Visa&lt;/company&gt;&lt;number&gt;${number}&lt;/number&gt;&lt;secret&gt;123&lt;/secret&gt;&lt;/cc&gt;&lt;/user&gt;" doc:name="Set Payload"/>

However note that the property placeholder is resolved at startup so you will not be able to dynamically retrieve a property based on some user input. For this you will have to do some Java coding. This SO post gives you some hints on how this can be achieved. Based on those answers I have created a simple example on how this can be done with a very simple helper bean.

Upvotes: 1

V&#237;ctor Romero
V&#237;ctor Romero

Reputation: 5115

I'm afraid you just can't. The Mule Credentials Vault is an enterprise feature and therefore tipically you won't have access to the source code unless you are a MuleSoft customer.

Even if you were a customer, the api you'd use would be sort of unsupported. I suggest to manually create a custom java component levearing your code and Jasypt (not as a property placeholder but as a library).

The other option, if you are a customer (I guess you are given you are using the credentials vault) is to contact the official support so they take care of it for you.

Upvotes: 0

Related Questions