You are on page 1of 11

FILTERS

How to filter the messages based


on message properties, payload
etc

WHAT IS FILTER ?
Filter is an special form of message processor.
It examines the Message
(Payload/Properties/Headers) If it matches
certain criteria then it will passes the
message to next processor otherwise it
simply discards the message.
We will see the Expression filter in upcoming
slides.

EXPRESSION FILTER
See below example

EXPRESSION FILTER
If you hit the url http://localhost:8081/app/sample?name=john
You will see the response as shown below.

WHAT IF NAME IS NOT GIVEN


hit the url http://localhost:8081/app/sample
You will see the response as shown below.

HOW TO AVOID
Add a expression filter to the flow
<expression-filter expression="#[message.inboundProperties['http.query.params']
['name'] !=null]" doc:name="Expression"/>

WHAT EXACTLY WE ARE DOING


HERE
We are expecting the get request with the parameter name
and sending a welcome message dynamically by using
the below mule expression
W elcom e,# [m essage.inboundProperties['http.query.param s']['nam e']

This expression will fails if the query parameter name is not


provided so we need to stop processing this kind of invalid
requests.
For avoiding invalid requests we are using an expression filter
before processing .
Expression filer will evaluate the configured mule expression,
if the result is true it will forward the message for further
processing otherwise it will simply rejects it .

COMPLETE CODE

< ?xm lversion= "1.0" encoding= "U TF-8"?>

< m ule xm lns:http= "http://w w w .m ulesoft.org/schem a/m ule/http"


xm lns= "http://w w w .m ulesoft.org/schem a/m ule/core"
xm lns:doc= "http://w w w .m ulesoft.org/schem a/m ule/docum entation"
xm lns:spring= "http://w w w .springfram ew ork.org/schem a/beans" version= "EE-3.6.1"
xm lns:xsi= "http://w w w .w 3.org/2001/XM LSchem a-instance"
xsi:schem aLocation= "http://w w w .springfram ew ork.org/schem a/beans
http://w w w .springfram ew ork.org/schem a/beans/spring-beans-current.xsd
http://w w w .m ulesoft.org/schem a/m ule/core http://w w w .m ulesoft.org/schem a/m ule/core/current/m ule.xsd
http://w w w .m ulesoft.org/schem a/m ule/http http://w w w .m ulesoft.org/schem a/m ule/http/current/m ulehttp.xsd">
< http:listener-confi
g nam e= "App_H TTP_Listener_C onfi
g uration" host= "localhost" port= "8081"
basePath= "app" doc:nam e= "H TTP Listener Confi
g uration"/>
< fl
ow nam e= "fi
lter-sam pleFlow ">
< http:listener confi
g -ref= "App_H TTP_Listener_Confi
g uration" path= "sam ple"
allow edM ethods= "G ET,PO ST" doc:nam e= "H TTP"/>
< expression-fi
lter expression= "# [m essage.inboundProperties['http.query.param s']['nam e'] != null]"
doc:nam e= "Expression"/>
< set-payload value= "W elcom e, # [m essage.inboundProperties['http.query.param s']['nam e']]"
doc:nam e= "Set Payload"/>
< /fl
ow >
< /m ule>

NOTES

1. Expression filter requires an mule expression.


2. This expression should result into Boolean value.
3. If configured expression results true it forwards the
message to next processor otherwise rejects the
message.

AVAILABLE FILTERS IN MULE

THANK YOU

You might also like