Payload Filter in Mule
Payload filter is used to find type of payload.Whether the payload is of type integer or string or any other type.We can identify and filter the payload by payload type.In our example if payload is integer then only it will allow to pass.
flow of payload filter :
Payload filter configuration :
As shown above i have defined the type as Integer.
URL : http://localhost:8085/api/payloadfilter
Input :
Output :
XML project code :
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" 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://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.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_payloadfilterFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/payloadfilter" doc:name="HTTP"/>
<object-to-string-transformer doc:name="Object to String"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[try{
int result = Integer.parseInt(payload);
}catch(Exception e){
System.out.println('Payload is not Integer');
} ]]></scripting:script>
</scripting:component>
<payload-type-filter expectedType="java.lang.Integer" doc:name="Payload"/>
<object-to-string-transformer doc:name="Object to String"/>
</flow>
</mule>
No comments:
Post a Comment