This project implements a robust API-Led Connectivity solution to retrieve and transform hotel booking data. It follows a three-layer architecture (System, Process, Experience) to decouple data access from business logic and client consumption.
The solution is designed to be production-ready, featuring advanced error handling, caching, content negotiation, and structured logging.
The solution consists of three distinct API layers communicating via HTTP:
| Layer | API Name | Port | Description |
|---|---|---|---|
| System | sys-booking-api |
8081 | Data Access Layer: Reads raw XML data from bookings.xml and guests.xml, filters by Reference ID, and handles data validation. |
| Process | pro-booking-api |
8082 | Logic Layer: Orchestrates calls to the System API, aggregates guest data, transforms XML to JSON, and implements Caching. |
| Experience | exp-booking-api |
8083 | Channel Layer: Client-facing proxy handling Content Negotiation (XML/JSON), Global Error Mapping, and Request Logging. |
- Complex DataWeave: Transforms flat XML structures into nested JSON objects with type coercion (Strings to Numbers).
- Data Aggregation: Merges customer details and guest lists into a single booking object.
- Resilient Filtering: System API logic handles invisible whitespace (
trim) and empty datasets to prevent false positives.
- Global Error Handler: Implemented across all three layers.
- Status Code Mapping: Automatically maps downstream errors (e.g., empty XML results) to correct HTTP 404 Not Found responses instead of generic 500 Server Errors.
- Clean Responses: Returns user-friendly JSON error messages:
{ "error": { "code": "NOT_FOUND", ... } }.
- Structured Logging: Logs events at the start and end of every flow in JSON format.
- Correlation ID: Propagates
correlationIdacross the entire API chain for full traceability.
- Caching Strategy: The Process API caches responses for 5 minutes based on the Booking Reference ID. Repeated requests do not hit the System API or file system.
- Content Negotiation: The Experience API supports both JSON and XML output.
- Default: JSON
- Header
Accept: application/xml: Returns XML wrapped in<Booking>tags.
- Configuration Management: All HTTP ports (
8081,8082,8083) are externalized inconfig.yamlto avoid hardcoding.
- Anypoint Studio 7.x
- Mule Runtime 4.x
- Import the project into Anypoint Studio.
- Ensure the
src/main/resources/datafolder contains the source files:bookings.xmlguests.xml
- Right-click the project -> Run As -> Mule Application.
- URL:
http://localhost:8083/api/v1/bookings/BKG-1002 - Method: GET
- Result:
200 OKwith full JSON details.
- URL:
http://localhost:8083/api/v1/bookings/BKG-9999 - Method: GET
- Result:
404 Not Foundwith structured error JSON.
- Make a request to
BKG-1001. - Check Console: Logs appear for Experience, Process, and System APIs.
- Make the same request again immediately.
- Check Console: System API logs are missing, proving the response came from the Cache.
- URL:
http://localhost:8083/api/v1/bookings/BKG-1002 - Header:
Accept: application/xml - Result: Response is returned in XML format.
/src/main/mule:global.xml: Shared configuration (Error Handlers, Object Store).sys-booking-api.xml: System Layer flow.pro-booking-api.xml: Process Layer flow.exp-booking-api.xml: Experience Layer flow.
/src/main/resources:config.yaml: Externalized properties./data: XML source files.