Skip to content

A complete end-to-end MuleSoft application implementing API-Led Connectivity. Features include System/Process/Experience layers, DataWeave XML-to-JSON transformation, Caching strategies, Global Error Handling, and Content Negotiation.

Notifications You must be signed in to change notification settings

OmarAhmedAdel/Hotel-Booking-Integration-Using-MuleSoft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hotel Booking Integration using MuleSoft

Overview

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.

Architecture

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.

Key Features

1. Core Logic & Transformation

  • 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.

2. Advanced Error Handling

  • 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", ... } }.

3. Observability

  • Structured Logging: Logs events at the start and end of every flow in JSON format.
  • Correlation ID: Propagates correlationId across the entire API chain for full traceability.

4. Bonus Features (Implemented)

  • 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 in config.yaml to avoid hardcoding.

Setup & Usage

Prerequisites

  • Anypoint Studio 7.x
  • Mule Runtime 4.x

Installation

  1. Import the project into Anypoint Studio.
  2. Ensure the src/main/resources/data folder contains the source files:
    • bookings.xml
    • guests.xml
  3. Right-click the project -> Run As -> Mule Application.

Testing Endpoints

1. Happy Path (Valid Booking)

  • URL: http://localhost:8083/api/v1/bookings/BKG-1002
  • Method: GET
  • Result: 200 OK with full JSON details.

2. Sad Path (Missing Booking)

  • URL: http://localhost:8083/api/v1/bookings/BKG-9999
  • Method: GET
  • Result: 404 Not Found with structured error JSON.

3. Caching Test

  • 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.

4. XML Output Test

  • URL: http://localhost:8083/api/v1/bookings/BKG-1002
  • Header: Accept: application/xml
  • Result: Response is returned in XML format.

File Structure

  • /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.

About

A complete end-to-end MuleSoft application implementing API-Led Connectivity. Features include System/Process/Experience layers, DataWeave XML-to-JSON transformation, Caching strategies, Global Error Handling, and Content Negotiation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages