97008 48403
+91 40-27177600


Custom Filter in Mule ESB


From the technical center of excellence of Massil Technologies, our technology leaders make it easy to understand the complex situations you come across in Mule ESB from the experience of Massil Technologies to have countered them in their experience of working on client projects in real time. This blog talks about applying custom filering logic in Mule ESB. This blog is a part of series of blogs being authored and published by Massil Technologies for the benefit of the IT community globally.

We have come across an interesting aspect with one of our clients while working on Mule ESB. The use case talks about applying custom filter logic in Mule ESB. While applying standard filters in Mule ESB, we can also generate a custom filter with exact set of conditions that needs to fulfilled before executing a flow. We have explained this use case with an example below:


Consider an example of a user-implemented custom filter. The minimum configuration needed is related to the particular class where filter is being implemented. With Use of a Custom filter to reference a user-applied filter. Note that the reference is to a class implementing the Filter interface. The Filter Class is essential if this has been a global filter.

Step 1:-Make a project and find HTTP listener in Mule Palette and move it to the Message flow and configure as given below

Step 2:- Look for Object to String Transformer in Mule Palette and transform it to the Message flow afterward the Http listner

Step 3:- Generate a java class in src/main/java for custom filtering as shown

PayloadFilter.java :

package com.filter;

import org.mule.api.MuleMessage;

import org.mule.api.routing.filter.Filter;

public class PayloadFilter implements Filter {


* This class implements a custom Mule filter.



public boolean accept(MuleMessage input) {

boolean msgValidated = false;

try {

String payloadStr = input.getPayloadAsString();

if (payloadStr != null && (payloadStr.trim().length() > 0)) {

if (payloadStr.contains(“@”)) {

msgValidated = true;

} else

return false;

} else {

return false;


} catch (Exception e) {


msgValidated = false;


return msgValidated;



Step 4:- Currently, Search for message filter in Mule Palette and change it to the Message flow & configure as follows

Step 5:- Put the set payload to print the success message if the filtering is done.

Step 6:- Total flow is depicted as follows:

Step 7: Run the project and on successful deployment hit certain data which covers “@”, “.” from postman to understand the results

INPUT1 : krishna.p@massil.tech


INPUT2 : Krishna massil

Hence, we have gone through the step by step process to depict the way Massil Technologies team has addressed the client need. Hope this article from Massil Technologies was useful for you. If you have any further queries on this topic, please reach out to info@massil.tech.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Get in touch with us

Scroll to top