Contact Us 1-800-596-4880

Filtering Invalid Requests

Sometimes you need to prevent your Mule application from processing requests known to be invalid or that have invalid data. This example shows you how to use filters to reject such invalid requests.

What You Will Learn

  • How to use filters to control which requests are processed

  • How to configure a particular kind of filter, the "Wildcard" filter

    Watch a video

    See this example built and run in Mule Studio

Build It Now! (10 minutes)

Prerequisites

This example adds a new filter to the existing 'core-concepts' project created in the Adding Business Logic to a Flow example.

Building the Example

  1. Make sure the "Message Flow" view is open in Mule Studio:

    studioStartingConfiguration
  2. Select the "Filters" panel and drag the "Wildcard" filter, dropping it on top of the arrow leaving the HTTP inbound end-point:

    studioAddWildcardFilter
  3. Double click the Wildcard filter you just added and enter "/Mule-" in the pattern field and "Mule- Filter" in the name field. Be sure to check the "Case Sensitive" check box:

    studioConfigureWildcardFilter
  4. Click the Documentation tab and fill in the description field:

    studioConfigureWildcardFilterDoc

Running the Example

To run the example, right click in the project tree, select Run As.. -→ Mule Application. You’ll see logging information in the console window as the application starts.

In a browser window go to http://localhost:8082/Fred and you should see the following on screen:

studioBrowserOutputUnmatched

The application quite rudely refused to greet Fred. Now go to go to http://localhost:8082/Mule-Fred instead. You should see the following:

studioBrowserOutputMatched

Notice that the application now has a Mule bias.

What Just Happened?

  • You added a filter to a flow. The filter conditionally controls which data is allowed to pass through to the flow

  • You modified an HTTP inbound end-point to reject requests that do not start with "Mule-". Rejected requests are not passed on.