In the Mule MEL, how to get a property value ?
In the java code, I did this:
eventContext.getMessage().setInvocationProperty("amount", 100);
I have tried these options
#[message.invocationProperty.invocation]
#[message.invocationProperty('invocation')]
#[message.getInvocationProperty().get('invocation')]
I realize that message is an instance of org.mule.el.context.MessageContext, then what is the correct syntax ?
Try #[message.inboundProperties['propertyName']] or #[message.invocationProperties['propertyName']]
If you set a variable with scope INVOCATION (with Message Enricher or Variable), you can get the variable with the syntax below:
#flowVars['your_Variable_Name']
Although the sintaxis is almost the same, it depends on the scope of the property variable, but the most usual way is:
#[flowVars['flow_var_name']]
In my personal opinion I don't recommend to use:
#[flowVars.variable]
Because in some complex environment with many messageContext switches the variable could get lost. I recommend to take a look on the next post from Mulesoft oficial blog that shows how to handle Properties and variables.
This answer for your comment
<set-variable variableName="amount" value="message.invocationProperties['amount']" />
Solution is
<set-variable variableName="amount" value="#[message.invocationProperties['amount']]" />
To get the Invocation properties of a message follow this syntax:
#[flowVars.parameter] or #[flowVars['paramater']]
Related
I have defined the object store as following:
<objectstore:config name="objectStore" objectStore-ref="_defaultUserObjectStore"/>
And am trying to modify the watermark variable defined by name "lastmodified" in object store via a flow which call
<objectstore:store key="lastmodified" value-ref="#[payload.lastmodified]" overwrite="true" config-ref="objectStore" doc:name="Default User Object Store"/>
Note: payload.lastmodified has appropriate value of "2016-06-29T15:08:45.000Z" in it.
I am not seeing any error on console but when the next time the Poll executes it doesn't read the updated value of the watermark.
Any pointer would be surely helpful.
Thanks.
Instead of the method used above, try using poll-watermarking. Can set you update expression in poll-watermarking and if needed, can use object store also.
I fixed it by making changing the object store config to: <objectstore:config name="objectStore" partition="mule.watermark" doc:name="ObjectStore: Connector"/>
I need to capture current flow name into a variable.
I tried with #[flow.name] but no luck in mule 3.8.0
can anybody please assist me?
Based on the answer in this post: How to get caller flow name in private flow in Mule
There is a simplest way to get the flow name and put it into a variable:
<expression-component doc:name="Expression"><![CDATA[flowVars.flowName = flow.name;]]></expression-component>
Alternately, you can directly use expression #[mule:context.serviceName] in a variable :-
<set-variable variableName="myFlowName" value="#[mule:context.serviceName]" doc:name="Variable"/>
<!-- Print the value of variale in logger -->
<logger message="#[flowVars.myFlowName]" level="INFO" doc:name="Logger"/>
This will set your current flow name directly in variable
In mule 3.8.5 using Groovy script component,
flowVars.currentFlowName = eventContext.getFlowConstruct().getName();
I have been using #[flow.name] in 3.7.3 and just tried in 3.8.0 to make sure it had not been removed and it worked fine for me in logger and setting a flowVars value. I suggest posting up at least a snippet of your flow and maybe we can spot the issue you are having.
PS, not sure why flow.name is not in standard forms or really documented by Mule, and as it is not there continues to be some worries they will remove it. I have seen it stated more than just here that it is not accessible in MEL, but #[flow.name] is a MEL expression and does work. To use if for something like I Parse Template in exception strategies, I use sulthony's form, set a flowVars value in an expression and refer to that flowVars in my template.
You can access flow name in logger by using #[flow.name] but its not accessible in MEL. Use flowconstruct for getting flow name. Refer this answer
Hope this helps.
Actually what I am trying to do is whenever exception/error occurs in application it will come to catch exception strategy, here I'm trying to create a xml request which contains application name, timestamp and error details and calling one rest service with this xml as input. Could you please help me in doing this..?? Thanks in Advance
There nothing you can do access those expressions in dataweave, you might need to store those in flowVars then access the flowVars in dataweave like flowVars."name_of_var".
Regards,
Ralph
You can find error handling block in your flow.
Inside that you can catch the exception with the MEL syntax.
#[Exception.causedBy(corresponding class)]
once if there is an exception based on some class then inside that you can define your strategy.
In general you can catch any exception by #[Exception!=null]
If there is any exception occurs automatically the control will be passed here.
In that you can setpayload #[app.name], #[server.dateTime],#[Exception.getMessage()]
Then you can proceed as you want.
Thanks!
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="<user><name>Royal Bank of Canada</name><id>Royal_Bank_Of_Canada</id><cc><company>>Visa</company><number>${number}</number><secret>123</secret></cc></user>" 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
From Dataweave you can read it as given below
p('variablename')
where variablename is defined in property files ex: variablename = 15
My simple question is how to set quartz repeatInterval variable from a property file?
I try with:
<quartz:inbound-endpoint repeatInterval="#[Integer.parseInt(message.inboundProperties['SCHEDULE_FREQUENCY'])]" responseTimeout="10000" connector-ref="quartzConnector_vm" doc:name="Event_generator" jobName="chicken">
but doesn't work. I made many tries but I always get the same message: "Value must be an integer or a Mule espression".
Actually I managed to let only integer values work.
Any clue on this?
Thanks
I found as a workaround to parameterize the cronExpression, which is a String, instead of the repeatInterval.