简体   繁体   中英

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

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.

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.

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

从Dataweave中,您可以按照p('variablename')的说明读取它,其中变量名在属性文件中定义,例如:variablename = 15

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM