简体   繁体   English

如何从Mule中的.properties文件读取属性

[英]How to read properties from .properties file in Mule

I'm trying to use Mule Credentials Vault security feature. 我正在尝试使用Mule Credentials Vault安全功能。 I've created .properties file, Security Property Placeholder and defined the key and encryption algorithm. 我已经创建了.properties文件,安全属性占位符,并定义了密钥和加密算法。 Now I want to use some of the properties from the file when I return HTTP response. 现在,当我返回HTTP响应时,我想使用文件中的某些属性。

I have the file src/main/resources/data.properties that contains for example: 我有文件src / main / resources / data.properties ,其中包含例如:

In my canvas, under Configuration XML I added: 在我的画布中,在配置XML下添加了:

<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'. 在我的画布中,我具有构建xml“基于用户创建XML响应”的消息流。 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)? 有谁知道如何从.properties文件(凭证保险库)中读取属性? 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 . 如果只想获取属性number的值并将其添加到XML中,则可以使用.properties中的 $ {number}。 No need to define any other variables in Configuration XML. 无需在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. 为此,您将必须执行一些Java编码。 This SO post gives you some hints on how this can be achieved. 这样的SO帖子为您提供了一些有关如何实现的提示。 Based on those answers I have created a simple example on how this can be done with a very simple helper bean. 基于这些答案,我创建了一个简单的示例 ,说明如何使用非常简单的辅助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. Mule Credentials Vault是一项企业功能,因此,除非您是MuleSoft客户,否则通常您将无法访问源代码。

Even if you were a customer, the api you'd use would be sort of unsupported. 即使您是客户,您所使用的api仍然不受支持。 I suggest to manually create a custom java component levearing your code and Jasypt (not as a property placeholder but as a library). 我建议手动创建一个自定义的Java组件,使您的代码和Jasypt保持一致(不是作为属性占位符,而是作为库)。

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 在MEL中使用$ .property中的$ {propertyName}访问特定属性

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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