GithubHelp home page GithubHelp logo

estebanwasinger / mule-app-with-error-handling-and-http-security Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 1.0 140 KB

Mule App with error handling and HTTP Basic Auth Security

License: Apache License 2.0

Java 100.00%

mule-app-with-error-handling-and-http-security's Introduction

Implementing a Choice Exception Strategy

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

Example use case

JSON sales data is sent through the HTTP endpoint. The input data is validated and in case of missing or invalid data, an appropriate exception is thrown. A series of custom filters then catch the exception in the JSON data and route the message to the error handling flow. The input data is validated and in case of missing or invalid data, an appropriate exception is thrown.

Set up and run the example

  1. Run the example project as a mule application

  2. Use Postman to make the following JSON POST request:

     {
     "email": "[email protected]", 
     "item name": "aa", 
     "item units": 10,  
     "item price per unit": 1,
     "membership": "free"
     } 
    

    This message throws no error and returns the following messsage:

     Input data validation passed.
    
  3. Use Postman to make the following JSON POST request:

     {
     "item name": "aa", 
     "item units": 10, 
     "item price per unit": 1,
     "membership": "free"
     }
    

    This message throws an exception as the email field is missing. Status code 400 is returned with the following message:

     Missing input data: {item name=aa, membership=free, item price per unit=1, item units=10}
    
  4. Use Postman to make the following JSON POST request:

     {
     "email": "[email protected]", 
     "item name": "aa", 
     "item units": 10, 
     "item price per unit": -1,
     "membership": "free"
     }
    

    This message throws an exception as the item price per unit is negative, and the following error message is returned. This applies to negative item units as well.

    Invalid input data: {item name=aa, membership=free, item price per unit=-1, [email protected], item units=10}
    

Go further

  • Read the documentation about choice exception strategy here

mule-app-with-error-handling-and-http-security's People

Contributors

estebanwasinger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.