Implementing an Exception Strategy

Implementing an Exception Strategy

(0 reviews)

This example illustrates the concept of error handling in Mule. This particular example deals with exception strategy.

ed3ebd50-implementing-exception-strategy.png

Example use case

The Mule application reads a CSV file and returns exception messages for two types of error:

  • The request specifies an invalid path.
  • The request specifies a file that read permissions are not granted on.

Set up and run the example

  1. Open the Implementing a Exception Strategy example project in Anypoint Studio from Anypoint Exchange.
  2. In your application in Studio, click the Global Elements tab. Double-click the HTTP Listener global element to open its Global Element Properties panel. Change the contents of the port field to required HTTP port (e.g., 8081).
  3. Run the example project as a Mule application
  4. In your browser, access the URL http://localhost:8081/?filePath=invalidPath. This message specifies an invalid path, and the application returns this error message: {"message": "Your path is invalid"}
  5. In your browser, access the URL http://localhost:8081/?filePath=path, substituing the path to the file input.csv for the path variable. The application returns the following payload: [{ "orderId": "1", "name": "T-shirt", "pricePerUnit": "25.0", "units": "2"},{ "orderId": "2", "name": "Jacket", "pricePerUnit": "40.5", "units": "3"}]
  6. In your browser, access the URL http://localhost:8081/?filePath=path, replacing the path variable this time with the path to a file that does not allow read access. The application returns the following error message: {"message": "Access to file denied"}

Go further

  • Read the documentation about exception strategy here.

Examples to Try Next

If you understood this example
Import Contacts Into Salesforce - Learn how to take a CSV file of contacts and upload them to Salesforce.View
If you struggled with this example
Content Based Routing - Learn how to route messages based on the logic you supply in the Choice Router.View
Filtering a Message - Learn how to use filter components to filter an incoming message.View

Reviews

Download
Log into Anypoint Platform to download this asset
Type
Example
Organization
MuleSoft
Created by
MO
MuleSoft Organization
Published onJul 28, 2018

Versions

VersionRuntime version
2.1.44.1.1
2.1.34.1.1
2.1.24.1.1
1.4.03.x
Show more