How to retrieve datetime minus 4 hours in Mule 3 - mule

I'm trying to get the current time minus 4 hours using the dateTime function.
With the next expression:
#[server.dateTime.plusHours(-4)format("yyyy-MM-dd'T'HH:mm:ss'Z'")]
Flow:
<sub-flow name="retrieve-time-last-run-os">
<objectstore:retrieve config-ref="ObjectStore_Connector" key="timeNow" defaultValue-ref="#[server.dateTime.plusHours(-4)format("yyyy-MM-dd'T'HH:mm:ss'Z'")]" doc:name="Retrieve Time Now"/>
<set-variable variableName="time" value="#[payload]" doc:name="Save time"/>
</sub-flow>
locally it works fine. The problem is when I deploy this function seems not to work. Does anyone know how to fix this?
Thank you

In the flow there seem to be a missing dot between plusHours() and format().

Related

How to get the value using 'http.uri.params' in mule

I am trying to get the value through URI params in mule. I am using
`#[message.inboundProperties.'http.uri.params'.Id]`
to get the value. When I pass a value, (for eg 16) it is returning as Id=16. Since I am passing this value into a database stored procedure, I need the value alone. Could anyone help me out in this.
This works for me in Mule 3.7.3:
<http:listener-config name="listener2" host="0.0.0.0" port="8083"/>
<flow name="uri">
<http:listener path="uri/{param}/resource" config-ref="listener2" />
<expression-transformer expression="#[message.inboundProperties.'http.uri.params'.param]" />
</flow>
Running curl http://127.0.0.1:8083/uri/value/resource returns value which is the expected according to the documentation.
What about storing "id=16" as a string variable and splitting it on the =?
Using
#[message.inboundProperties.'http.uri.params'[0]['Id']
will retrieve only the value of the id. This will surely work.

How to send array in url in mule esb?

I need to send array in url. I have tried different ways like
http://localhost:8081/?RedundedItems[]=[00,11]
http://localhost:8081/?RedundedItems[]=00,11
http://localhost:8081/?RedundedItems=00&RedundedItems=11
http://localhost:8081/?RedundedItems[]=00&RedundedItems[]=11
Please assist me.
Sorry but I really dont think this is possible or even if by some miracle it is, I dont see it as practical...
One solution would be to send your data as normal and maybe process it into an array via datamapper?
Hope I have been of some help.
JB
The following works using your third option:
<flow name="request-testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<set-payload value="#[message.inboundProperties.'http.query.params'.getAll('RedundedItems')]" doc:name="Set Payload"/>
<object-to-string-transformer doc:name="Object to String"/>
</flow>
So hitting http://localhost:8081/?RedundedItems=00&RedundedItems=11 the output is: [00, 11].
HTH.
The right way is http://localhost:8081/?RedundedItems=00,11 . You can't specify the parameter is an array.

How to Extract the Flow Name and MessageProcessor Name using MEL - MULE ESB

I'm not sure, how can we extract the flow-name and message-processor Name through MEL. For example I have multiple message processor. For logging, i need to extract the flow Name and Message-processor, so that I can find out transaction has crossed this particular flow and its message processor. Is there any simple way to find out. Please guide me. Please find the screenshot below. Here i need to Extract - set payload and its flowName (flow1)
Thanks in advance.
For mule 3.8+ version onwards #[flow.name] don't work.
Use #[mule:context.serviceName] expression in logger or component to extract the name of the flow
I know this post is old but I have been trying to find a way to do this in MEL for error handling emails.
For the flow name you can use #[exception.event.flowConstruct.name]
for the failing message processor you can use #[exception.failingMessageProcessor].
Both of these work in MEL without the need to use an flowVar.
Please note however, that the failing processor does not always come back with a value but comes back with null, I'm not sure why.
You can extract the flow-name with MEL : #[flow.name]
<flow name="name" doc:name="name">
<http:inbound-endpoint address="http://localhost:8090/resources" doc:name="HTTP" />
<logger message="name of flow: #[flow.name]" level="INFO" doc:name="Logger"/>
<set-payload value="name" doc:name="Set Payload"/>
</flow>
or
flowConstruct.getName() in a Message Processor
Two ways to acthive this (from current flow name)
First one is -
<logger message="Current flowName: #[flow.name]" level="INFO" doc:name="Logger"/>
and the second one is -
<logger message="Current flowName: #[context:serviceName]" level="INFO" doc:name="Logger"/>

to fetch a specific value from resultset in Mule

I have a flow that calls a MS SQL stored procedure which returns a value. The output that i get from the DB is {resultset1=[{id=30}]} i would like to store the value of id to flow variable
couldn't find a successful way to do this, Could somebody please help me in this
I'am using mule server 3.4.0 EE
Thank you in Advance
First place a json-to-object-transformer and then try the following :-
<json:json-to-object-transformer returnClass="java.util.HashMap" />
<set-variable variableName="id" value="#[payload.resultset1[0].id]" doc:name="Variable"/>

Mule Message Enricher Target Expression

I have a flow that takes a pair of dates inbound and then uses a message enricher to get a list of employees that worked on a specific job between those two dates. The result is a simple list of maps returned from a JDBC database. I got that saved into a flow variable without any trouble. The next enrichment is causing me trouble. I setup a for each loop that uses the employees list from the flow variable. This works great and I then need to execute another JDBC query for each of these employees to get all the time tickets they turned in between the two dates passed to the flow. The query works but I am having trouble defining the target expression to hold the result. I would like to see the target be a map with the employee id as the key and the tickets for the period (list of maps) be the value. Is there any way to do this? Is there a better way to save these results? After I get all the tickets, I need to summarize them in various ways and generate a report showing the detail as well as the analysis.
I am currently developing this in mule studio for the community runtime version 3.4.
Is this like something that you are looking for?
<set-variable variableName="maplistmap" value="#[new java.util.HashMap()]"/>
<foreach>
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="selekt" queryTimeout="-1" connector-ref="Database">
<jdbc-ee:query key="selekt" value="select * from mytable where id = #[payload]"/>
</jdbc-ee:outbound-endpoint>
<scripting:component>
<scripting:script engine="Groovy"><![CDATA[
flowVars["maplistmap"].put(payload[0].id, payload)
]]></scripting:script>
</scripting:component>
</foreach>
<logger message="#[flowVars.maplistmap]" level="INFO"/>