Apache camel simple operators contains - ldap

I'm working with apache camel V2.24.3,and I want to check if ${body} contains this 2 strings.
<choice id="ldap_response">
<when id="ldap_response_adding">
<simple>${body} contains 'adding' && 'modifying'</simple>
</when>
</choice>
this code returns an error:
'The identity name must immediately follow the "&" character in the
entity reference.'

Try <simple>${body} contains 'adding' and ${body} contains 'modifying'</simple>

Related

Mule : Use dynamic config-ref based on input values

I'm trying to connect to SQL Database with some configuration. But based on the input from the API we are supposed to hit different DB.
As of now, we have the code as
<choice doc:name="Check myFlag">
<when expression="#[flowVars.myFlag == 'true']">
<db:stored-procedure config-ref="Database_Configuration_1" doc:name="DB_config_1">
<db:dynamic-query><![CDATA[#[flowVars.callSPName]]]></db:dynamic-query>
</db:stored-procedure>
</when>
<otherwise>
<db:stored-procedure config-ref="Database_Configuration_2" doc:name="DB_config_2">
<db:dynamic-query><![CDATA[#[flowVars.callSPName]]]></db:dynamic-query>
</db:stored-procedure>
</otherwise>
</choice>
Instead of repeating <db:stored-procedure../> twice, is there a way where I can set a flow var with the DB config reference and use it?
Something like,
<db:stored-procedure config-ref="#[flowvars.db_config]" doc:name="DB_config_2">
<db:dynamic-query><![CDATA[#[flowVars.callSPName]]]></db:dynamic-query>
</db:stored-procedure>
In Mule 3, no. config-ref's are evaluated at application startup, not runtime.
In Mule 4 this is possible using Dynamic Configurations: https://docs.mulesoft.com/mule-sdk/1.1/static-dynamic-configs
Potential Mule 3 solutions documented here: https://help.mulesoft.com/s/article/How-to-configure-connector-with-dynamic-parameters
Put the DB call inside a sub-flow and call it from the rest of the flows with a <flow-ref>.

How I do check if the variable exist in Mule 3.2?

How do check if the variable exist in Mule 3.2?
How create or replace a variable?
My Flow Exception is
<choice doc:name="Choice">
<when expression="#[myVar==null]">
<processor-chain>
<set-variable variableName="myVar" value="value1" doc:name="myVar"/>
</processor-chain>
</when>
<otherwise>
<processor-chain>
<set-variable variableName="myVar" value="#[variable:myVar]" doc:name="myVar"/>
</processor-chain>
</otherwise>
</choice>
"myVar==null" does not work
if the variable is an invocation variable please try
flowVars['myVar'] == null
Worst case scenario you could do:
message.getProperty('myVar', org.mule.api.transport.PropertyScope.INVOCATION).
Please notice the scope is an enum so you should provide the canonical in a MEL expression.
HTH
You can use this MEL to print in log or use in Choice component
#[message.invocationProperties('myVar')] == null
There is a component "Message Property" which will help you remove or replace or create Mule message properties. You should use that to perform your operation.
To best find it use keyword "propert" in the search of pallets in the Mule studio and explore the various components there to suit your needs.

Mule:Retrieving object store in an MEL in Mule 3.5

Having a requirement to test a object store whether it contains a key or not in a choice router
<objectstore:config name="storeDownload" doc:name="ObjectStore" persistent="false" partition="test"/>
<choice>
<when expression="#[app.registry.storeDownload.contains('#[flowVars.startKey]').equals('false')]">
Getting an error
1. Expression Evaluator "registry" with expression "ON" returned null but a value was required. (org.mule.api.expression.ExpressionRuntimeException)
org.mule.expression.RegistryExpressionEvaluator:101 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)
2. Failed to invoke store. Message payload is of type: byte[] (org.mule.api.MessagingException)
The main issue is that you are embedding MEL into MEL which can't work. Also the boolean-as-string comparison is dodgy.
Replace this:
#[app.registry.storeDownload.contains('#[flowVars.startKey]').equals('false')]
with that:
#[!(app.registry.storeDownload.contains(flowVars.startKey))]
My use case was a bit different to Nazar's I needed to monitor a long running process which can take up to four hours.
In the first flow I generate a key value with a time stamp in it as the payload and then use it to set the ProcessState to the static value 'Started' in an ObjectStore as shown below. After which I fire a Quartz Outbound Endpoint with a four hour delay.
<objectstore:store config-ref="MonitoredProcess" value-ref="Started" key="#[payload]" doc:name="ObjectStore"/>
<quartz:outbound-endpoint jobName="ProcessMonitor" responseTimeout="10000" doc:name="Quartz"
repeatInterval="0" repeatCount="0" startDelay="${process.monitor.event.start.delay}">
<quartz:scheduled-dispatch-job>
<quartz:job-endpoint address="vm://processMonitorQueue"/>
</quartz:scheduled-dispatch-job>
</quartz:outbound-endpoint>
And I got the same exception.
After scratching my head and lots of searches the name of the variable 'value-ref' in combination with David's answer above finally revealed my problem namely the MEL is always invoked for this ref field.
As soon as I changed the field to an expression #['Started'] that MEL could evaluate my problem went away.
<objectstore:store config-ref="MonitoredProcess" value-ref="#['Started']" key="#[payload]" doc:name="ObjectStore"/>
For completeness I've included the code that retrieves the ProcessState from the ObjectStore. Note the defaultValue-ref also needs to use MEL
<vm:inbound-endpoint exchange-pattern="one-way" path="processMonitorQueue" doc:name="VM" />
<objectstore:retrieve config-ref="MonitoredProcess" defaultValue-ref="#['DoesNotExist']" key="#[payload]" targetProperty="processState" doc:name="ObjectStore"/>

Message Splitter

I needed to split a message into 3 different payloads and transform and send to 3 routers. So the payload initially will have a header a body or detail and a footer. These 3 different payloads need to be extracted and send to 3 different routers. What would be the most efficient way to do it.
It depends on your body/payload type. If your payload is XML, you can easily split it using xpath and route it using content based routing similar to:
<splitter expression="#[xpath('//nodes/node)']" />
<choice>
<when expression="#[xpath('//node/id').text ='myid']">
<!-- Route somewhere -->
</when>
<otherwise>
<!-- Route somewhere else -->
</otherwise>
</choice>
The expression splitter above can take any MEL expression to split up your payload. There are many other splitters, for example if your payload is already a java Collection, you can simply use the collection-splitter.
Other splitter info can be found here: http://www.mulesoft.org/documentation-3.2/display/32X/Message+Splitting+and+Aggregation
Also there are other routers that can help you with fork and join patterns if you need to process messages asynchronously as well. Here's a good post on that: http://java.dzone.com/articles/aggregation-mule-%E2%80%93-%E2%80%9Cfork-and

Mule Performing a string manipulation

What is the best way to perform a string manipulation. I wish to perform a substring on a email address to extract the domain detail and populate this to a variable.
a java transformer is a possibilty, but i was hoping if i could use a message enricher with a expression to perform this operation.
pardon me but i am still a greenhorn on Mule.
here is the excerpt from my mule flow which is failing with error cannot resolve method string length.
<enricher target="#[flowVars['FromAddressDomain']]" doc:name="Message Enricher">
<expression-transformer expression="#[ payload.fromAddr.substring(payload.fromAddr.lastIndexOf('#')+ 1,payload.fromAddr.lenth())]" doc:name="Expression"></expression-transformer>
</enricher>
Simply use:
<set-variable variableName="FromAddressDomain"
value="#[org.mule.util.StringUtils.substringAfter(payload.fromAddr, '#')]" />
You can use dataweave transform on payload and use the operator splitby and spilt on # character. Please take a look at below link for more information on splitby operator
https://docs.mulesoft.com/mule-user-guide/v/3.9/dataweave-operators#split-by