Expression Transformer for String validation in Mule
The Expression Transformer executes one or more expressions on the current message. The results of these expressions becomes the payload of the current message.
An Expression Transformer evaluates one or more expressions on the current message. Each evaluated expression equates to a parameter in the returned message. However, if the returned message encompasses more than one expression, then the results of those expressions are an Object array.
The Expression Transformer has the same advanced properties as all other transformers with the addition of an optional list of return arguments.
Click the General tab to specify an expression and an expression evaluator in the Expression attributes section.
Here in our flow we are using one of the string method contains( ) as expression
path : /exp
url : http://localhost:8085/api/exp
method : POST
Input & output :method : POST
XML project code :
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8085" doc:name="HTTP Listener Configuration" basePath="/api"/>
<flow name="test_expressionFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/exp" doc:name="HTTP"/>
<object-to-string-transformer doc:name="Object to String"/>
<expression-transformer doc:name="Expression" expression="#[payload.toString().contains('h')]">
</expression-transformer>
<set-payload value="#[payload]" doc:name="Set Payload"/>
</flow>
</mule>