According to the following ticket: https://www.mulesoft.org/jira/browse/MULE-6427 For NullPayload I should be able to use :
<when expression="#[payload == null]">
but that doesn't work. It fails. I am using Mule 3.5.1
Here is an example flow:
<flow name="testNull">
<poll frequency="10000">
<logger />
</poll>
<set-payload value="#[org.mule.transport.NullPayload.getInstance()]" />
<choice>
<when expression="#[payload == null]">
<logger level="ERROR" message="NullPayload is same as null" />
</when>
<otherwise>
<logger level="ERROR" message="Doesnt work" />
</otherwise>
</choice>
</flow>
This will always print 'Doesn't work'. However message.payload == null works. Whats the difference between "payload" and "message.payload"?
There seems to be an issue with the #[payload] alias. Use the real thing and it will work: #[message.payload].
Related
I have a flow which queries SalesForce. The query is wrapped in an enricher. Here is the flow.
<flow name="ProcessEmployee">
<enricher doc:name="Message Enricher" target="#
[variable:IDRec]">
<sfdc:query config-ref="Salesforce_Config"
doc:name="Check if Employee Id exists"
query="select id from employee where
deptId='#[payload["deptId"]]' &&
empId='#[payload["empId"]]'" />
</enricher>
<choice>
<when expression="#[flowVars.IDRec.hasNext()]">
<logger level="INFO"
message="Employee exists, #[payload]" />
</when>
<otherwise>
<logger level="INFO" message="Employee does not exist"/>
</otherwise>
</choice>
</flow>
However, I get the following error
: Execution of the expression "flowVars.IDRec.hasNext()" failed.
(org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: LinkedHashMap
Type: org.mule.api.MessagingException
Code : MULE_ERROR--2
The returned value is a map. You can try this approach,
<choice>
<when expression="#[flowVars.IDRec.size() > 0]">
<logger level="INFO" message="Employee exists, #[payload]" />
</when>
<otherwise>
<logger level="INFO" message="Employee does not exist"/>
</otherwise>
</choice>
I want to move files to location D:\target dynamically from the query select filepath from emp where status='y':
This is my table:
emp_Name File Path File Name Status
ABC D:\emp abc.txt y
xyz D:\emp xyz.txt y
bcs D:\emp bcs.txt n
Following is my source code :
<flow name="testdbFlow1">
<http:listener config-ref="HTTP_Listener_Configuration"
path="/" doc:name="HTTP" />
<jdbc-ee:outbound-endpoint queryKey="allEmps"
queryTimeout="-1" connector-ref="JDBCConnector" exchange-pattern="request-response"
doc:name="Database" />
<foreach doc:name="Foreach">
<choice doc:name="Choice">
<when expression="#[payload.status == 'Y']">
<processor-chain doc:name="Processor Chain">
<set-variable variableName="filePath" value="#[payload.filepath]"
doc:name="Variable" />
<set-variable variableName="filename" value="#[payload.filename]"
doc:name="Variable" />
<logger message="#[filePath]" level="INFO"
doc:name="Logger" />
<logger message="#[filename]"
level="INFO" doc:name="Logger" />
<file:inbound-endpoint path="#[filePath]" name="input" doc:name="File"
pollingFrequency="12000" responseTimeout="10000"> <file:filename-wildcard-filter
pattern="#[filename]" /> </file:inbound-endpoint>
<file:outbound-endpoint name="output" path="D:\target" doc:name="File"/>
</processor-chain>
</when>
<otherwise>
<processor-chain doc:name="Processor Chain">
<set-variable variableName="filePath" value="#[payload.filepath]"
doc:name="Variable" />
<set-variable variableName="filename" value="#[payload.filename]"
doc:name="Variable" />
<logger message="#[filePath]" level="INFO"
doc:name="Logger" />
<logger message="#[filename]"
level="INFO" doc:name="Logger" />
</processor-chain>
</otherwise>
</choice>
</foreach>
</flow>
But it's not working.
Inbound doesn't work out of the box in the middle of the flow. I would suggest a simpler solution using Groovy because you know exactly the file you need to consume.
Instead of using file:inbound create a input stream manually:
<set-payload value="#[groovy: new java.io.FileInputStream(new java.io.File(filename))]"/>
You will have to delete the file with another groovy script after consumed.
I need to read values from a configuration file and I keep running into issues with an embedded MEL statement; chased multiple dead ends and am out of ideas. I distilled it down to a fairly simple example using a session variable.
Thank you,
- Don
The below code fails with:
Message : [Error: Missing left node]
[Near : {... message.payload.contains(#[sessionVars['valueToMatch']]) ....}]
<set-session-variable variableName="valueToMatch" value="Now we are engaged in a great civil war" />
<choice doc:name="Choice">
<when expression="#[message.payload.contains(#[sessionVars['valueToMatch']])]">
<set-session-variable variableName="success" value="true" />
</when>
<otherwise>
<set-session-variable variableName="success" value="false" />
</otherwise>
</choice>
Whereas the following code works:
<choice doc:name="Choice">
<when expression="#[message.payload.contains('Now we are engaged in a great civil war')]">
<set-session-variable variableName="success" value="true" />
</when>
<otherwise>
<set-session-variable variableName="success" value="false" />
</otherwise>
</choice>
My guess is that the problem is that you are putting an expression delimited inside of an expression, try this:
"#[message.payload.contains(sessionVars['valueToMatch'])]"
instead of this
"#[message.payload.contains(#[sessionVars['valueToMatch']])]"
Try this #[message.payload contains valueToMatch] ... It will work perfectly and simple:-
<set-session-variable variableName="valueToMatch" value="Now we are engaged in a great civil war" />
<choice doc:name="Choice">
<when expression="#[message.payload contains valueToMatch]">
<set-session-variable variableName="success" value="true" />
</when>
<otherwise>
<set-session-variable variableName="success" value="false" />
</otherwise>
</choice>
Suppose I have a main flow and there are several sub-flows. I need to call a particular sub-flow if I have the right parameter without using choice component.
Basically, I want to ask if sub-flows can be parametrized.
Yes you can. Here's an example:
<flow name="testFlow1" doc:name="testFlow1">
<poll doc:name="Poll">
<logger level="INFO" doc:name="Logger" />
</poll>
<set-variable variableName="flowName" value="testFlow2"
doc:name="Variable" />
<flow-ref name="#[flowVars.flowName]" />
</flow>
<sub-flow name="testFlow2" doc:name="testFlow2">
<logger level="INFO" doc:name="Logger" message="sub" />
</sub-flow>
I'm trying to get my choice branch in Mule to branch on number of parameters in http.query.params is that possible?
How do I return the value of the MULE_JDBC_UDATE_COUNT variable to the client?
My config.xml
<spring:beans>
<spring:bean id="InformixDatasource" name="InformixDatasource" class="org.enhydra.jdbc.standard.StandardDataSource">
<spring:property name="password" value="xxxxx"></spring:property>
<spring:property name="driverName" value="com.informix.jdbc.IfxDriver"></spring:property>
<spring:property name="user" value="informix"></spring:property>
<spring:property name="url" value="jdbc:informix-sqli://browning.frett.ehf:1527/dev:informixserver=ol_brown"></spring:property>
</spring:bean>
</spring:beans>
<jdbc-ee:connector name="InformixConnector" dataSource-ref="InformixDatasource" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"></jdbc-ee:connector>
<flow name="postdrefing_fetch_dataFlow1" doc:name="postdrefing_fetch_dataFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8084" doc:name="HTTP" path="postdreifing"></http:inbound-endpoint>
<logger message="before db Choice #[message.payload]" level="INFO" doc:name="Logger"></logger>
<choice doc:name="Choice">
<when expression="message.inboundProperties['dreifing'] != null and message.inboundProperties['dags'] != null or message.inboundProperties['dags'] != null">
<logger message="delete #[message.inboundProperties['http.query.params']]" level="INFO" doc:name="Logger"></logger>
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="deleteById" queryTimeout="-1" connector-ref="InformixConnector" doc:name="Delete from nafnadreifing by id">
<jdbc-ee:query key="deleteById" value="DELETE FROM fdr_nafnadreifing WHERE dreifing = #[message.inboundProperties['dreifing']] and dags = TO_DATE(#[message.inboundProperties['dags']],'%d%m%Y')"></jdbc-ee:query>
</jdbc-ee:outbound-endpoint>
<logger message="Deleted #[flowVars['MULE_JDBC_UDATE_COUNT']] rows" level="INFO" doc:name="Logger"></logger>
<set-payload value="Deleted #[flowVars['MULE_JDBC_UDATE_COUNT']] rows" doc:name="Set Payload"/>
</when>
<otherwise>
<logger message="default" level="INFO" doc:name="Logger"></logger>
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="selectStatement" queryTimeout="-1" connector-ref="InformixConnector" doc:name="Select all from ibudaskra">
<jdbc-ee:query key="selectStatement" value="SELECT skyring,gata,gata_thgf,husnumer,auka,pnr,hverfi,ibudafjoldi,fjolpostur,athugasemdir,breytt,bannmerki,uppfaert,sortnr,pakki,active,tegund,ibud FROM fdr_ibudaskra"></jdbc-ee:query>
</jdbc-ee:outbound-endpoint>
<json:object-to-json-transformer doc:name="Object to JSON"></json:object-to-json-transformer>
</otherwise>
</choice>
</flow>
Yes, this is possible, with something like #[message.inboundProperties['http.query.params']['myQueryParamName']]. Be sure to use #[ ] around your expression and also use '&&' and '||' for boolean operations.
<when expression="#[message.inboundProperties['dreifing'] != null && message.inboundProperties['dags'] != null || message.inboundProperties['dags'] != null]">
It also seems you're missing parenthesis around the part of this expression.
Use set-payload:
<set-payload value="#[flowVars['MULE_JDBC_UDPATE_COUNT']]" />