Exposing Several Services as a Single Service
com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

Exposing Several Services as a Single Service

This scenario is commonly referred to as Service Chaining. Here, several services are integrated based on some business logic and exposed as a single aggregated service. 

In this tutorial, you send a message through the ESB profile to the back-end service using the Call mediator, instead of the Send mediator. You can build a service chaining scenario with the Call mediator as it allows you to specify all service invocations one after the other within a single sequence.

You then use the PayloadFactory mediator to take the response from one back-end service and change it to the format that is accepted by the other back-end service.

See the following topics for descriptions of the concepts that you need to know when creating ESB artifacts:

Before you begin,

  • Download the product installer from here, and run the installer.

  • Select the relevant WSO2 Integration Studio based on your operating system and download it from here.
    The path to this folder is referred to as <EI_TOOLING> throughout this tutorial.

  • If you did not try the Transforming Message Content tutorial yet,

    1. Download the pre-packaged project that contains the configurations of the Transforming Message Content tutorial.

    2. Open WSO2 Integration Studio, click File, and click Import.

    3. Next, expand the WSO2 category and select Existing WSO2 Projects into workspace, click Next, and upload the project file.

Let's get started!

Connecting to the back-end services

Let's create HTTP endpoints representing the back-end services to which you need to connect. These services process information related to channelling fees and payment settlements.

  1. Right click SampleServices in the Project Explorer and navigate to New -> Endpoint. Ensure Create a New Endpoint is selected and click Next.

  2. Fill in the following information:

  3. Click Finish.

  4. Create another endpoint for the Settle Payment service and fill in the information as in the following table: 

  5. Click Finish.

You have now created the additional endpoints that are required for this tutorial. 

Creating the deployable artifacts

  1. In WSO2 Integration Studio, add a Property mediator just after the Get Hospital Property mediator in the In sequence of the API resource. This is used for retrieving and storing the card number that is sent in the request payload.

     With the Property mediator selected, access the Properties tab and fill in the information as in the following table:

  2. Go to the first case box of the Switch mediator. Add a Property mediator just after the Log mediator to store the uri.var.hospital variable value that will be used when sending requests to ChannelingFeeEP.

     With the Property mediator selected, access the Properties tab and fill in the information as in the following table:

  3. Similarly, add Property mediators in the other two case boxes in the Switch mediator. Change only the Value field as follows:

    • Case 2: clemency

    • Case 3: pinevalley

  4. Delete the Send mediator by right-clicking the mediator and selecting Delete from Model. Replace this with a Call mediator from the Mediators palette and add GrandOakEP from the Defined Endpoints palette to the empty box adjoining the Call mediator. 

    Replace the Send mediators in the following two case boxes as well and add ClemencyEP and PineValleyEP to the respective boxes adjoining the Call mediators.

    Let's use Property mediators to retrieve and store the values that you receive as responses from GrandOakEP, ClemencyEP, or PineValleyEP.

  5. Next to the Switch mediator, add a Property mediator to retrieve and store the value sent as appointmentNumber.

     With the Property mediator selected, access the Properties tab and fill in the information as in the following table:

  6. Similarly, add two more Property mediators as follows. They retrieve and store the doctor details and patient details respectively from the response that is received from GrandOakEP, ClemencyEP, or PineValleyEP.

  7. Add a Call mediator and add ChannelingFeeEP from Defined Endpoints palette to the empty box adjoining the Call mediator. 

  8. Add a Property mediator adjoining the Call mediator box to retrieve and store the value sent as actualFee. Access the Property tab of the mediator and fill in the information as in the following table:

    Let's use the PayloadFactory mediator to construct the following message payload for the request sent to SettlePaymentEP. 

    {"appointmentNumber":2, "doctor":{ "name":"thomas collins", "hospital":"grand oak community hospital", "category":"surgery", "availability":"9.00 a.m - 11.00 a.m", "Fee":7000.0 }, "patient":{ "name":"John Doe", "Dob":"1990-03-19", "ssn":"234-23-525", "address":"California", "phone":"8770586755", "email":"johndoe@gmail.com" }, "fee":7000.0, "Confirmed":false, "card_number":"1234567890" }
  9. Add a PayloadFactory mediator next to the Property mediator, from the mediators palette to construct the above message payload. 

     With the PayloadFactory mediator selected, access the Properties tab of the mediator and fill in the information as in the following table:

    We will look at adding the value for the Args field in the following steps.

  10. To add Args values for the PayloadFactory mediator, click Add (+) in the Args field and enter the information given below. It provides the argument that defines the actual value of the first variable that is used in the format definition (in the previous step).

  11. Similarly, click Add and add more arguments to define the other variables that are used in the message payload format definition. Use the following as the Value for each of them: 

    $ctx:doctor_details
    $ctx:patient_details
    $ctx:actual_fee
    $ctx:card_number

  12. Add a Call mediator and add SettlePaymentEP from the Defined Endpoints palette to the empty box adjoining the Call mediator.

  13. Add a Respond mediator to send the response to the client. 
    You should now have a completed configuration that looks like this:

  14. Save the updated REST API configuration.

Packaging the artifacts

Package the artifacts you created above in the SampleServicesCompositeApplication project: 

  1. Open the pom.xml file of the SampleServicesCompositeApplication project, which is already included in the project explorer.

  2. Select the artifact that needs to be included into the CAR file.

Ensure the following artifact check boxes are selected in the Composite Application Project POM Editor.

  • SampleServices

    • HealthcareAPI

    • ClemencyEP

    • GrandOakEP

    • PineValleyEP

    • ChannelingFeeEP

    • SettlePaymentEP

  • SampleServicesRegistry

Starting the ESB profile and deploying the artifacts

If you do not already have an ESB server added to WSO2 Integration Studio, follow the instructions in a previous tutorial.

If you have already added the ESB profile server and deployed SampleServicesCompositeApplication (in a previous tutorial):

  1. Go to the Servers tab and click 

     to start the server. 

  2. Right-click SampleServicesCompositeApplication and click Redeploy as shown below.

The server Console will indicate that the CApp has been redeployed successfully.

Starting the back-end service

Download and start the back-end service that will process appointment requests:

  1. Download the JAR file of the back-end service.

  2. Open a terminal and navigate to the location where your saved the back-end service.

  3. Execute the following command to start the service:

    java -jar Hospital-Service-JDK11-2.0.0.jar

The Healthcare service is now active and you can start sending requests to the service.

Sending requests to the ESB

  1. Create a JSON file named request.json with the following request payload.

    { "name": "John Doe", "dob": "1940-03-19", "ssn": "234-23-525", "address": "California", "phone": "8770586755", "email": "johndoe@gmail.com", "doctor": "thomas collins", "hospital": "grand oak community hospital", "cardNo": "7844481124110331", "appointment_date": "2025-04-02" }
  2. Open a command line terminal and execute the following command from the location where the request.json file was saved:

    curl -v -X POST --data @request.json http://localhost:8280/healthcare/categories/surgery/reserve --header "Content-Type:application/json"

    You will see the response as follows:

    { "appointmentNo":1, "doctorName":"thomas collins", "patient":"John Doe", "actualFee":7000.0, "discount":20, "discounted":5600.0, "paymentID":"480fead2-e592-4791-941a-690ad1363802", "status":"Settled" }

You have now explored how the ESB profile of WSO2 EI can do service chaining using the Call mediator and transform message payloads from one format to another using the PayloadFactory mediator.

com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.