Expression Transformer in Mule





Expression Transformer in Mule


Expression transformer evaluates one or more expressions and return true if input matches with expression otherwise false.

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.

flow of expression transformer :



expression given in expression transformer :
 #[message.inboundProperties.'http.query.params'.name == 'himanshu']

output will be true if query parameter in input is name=himanshu


URL : http://localhost:8085/api/exptransformer

Method : GET


Input :

hit the url : http://localhost:8085/api/exptransformer?name=himanshu

Output :





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" basePath="/api" doc:name="HTTP Listener Configuration"/> <flow name="test_expressiontransformerFlow"> <http:listener config-ref="HTTP_Listener_Configuration" path="/exptransformer" doc:name="HTTP"/> <expression-transformer expression="#[message.inboundProperties.'http.query.params'.name == 'himanshu']" doc:name="Expression"/> <object-to-string-transformer doc:name="Object to String"/> </flow> </mule>