Skip to content

How to Use Inbound Endpoints

What you'll build

In this sample scenario, you will use an Inbound Endpoint to expose an already defined REST API through a different port. You can reuse the REST API that was defined in the Sending a Simple Message to a Service tutorial.

Let's get started!

Step 1: Set up the workspace

The following software and configurations are required to proceed with this tutorial:

  • Visual Studio Code (VS Code): with the Micro Integrator extension installed.
  • Java Development Kit (JDK): Ensure the JDK is properly configured in your system's PATH environment variable.
  • Apache Maven: Ensure Apache Maven is installed and its path is correctly set within the system's PATH environment variable.

Info

Follow the Install Micro Integrator for VS Code documentation for a complete installation guide.

Step 2: Develop the integration artifacts

Follow the instructions given in this section to create and configure the required artifacts.

Open the integration project

  1. Download the required project from here and extract.

  2. Launch VS Code with the Micro Integrator extension installed.

  3. Click on the Micro Integrator icon on the Activity Bar of the VS Code editor.

    MI VS Code Extension

  4. Click Open MI Project on Design View.

  5. Provide the location of the downloaded project path.

Develop the inbound endpoint

  1. Once you have opened the integration project described above, the Micro Integrator Project Explorer will appear with the previously created artifacts. Note that the HealthcareAPI is already included.

    Inbound project explorer

  2. Navigate to the MI Project Explorer > Inbound Endpoints.

    create inbound endpoint

  3. Hover over Inbound Endpoints and click the + icon that appears.

    add inbound endpoint

  4. On the Inbound EP Form, select HTTP as the inbound endpoint type.

  5. Enter the following details and click Add.

    Parameter Description
    Inbound Endpoint Name QueryDoctorInboundEndpoint
    Injecting Sequence Name TestIn
    Error Sequence Name fault
    Inbound HTTP port 8285
    Dispatch Filter Pattern /healthcare/querydoctor/.*

The endpoint will now be mapped to any URL that matches the pattern provided above. You will expose the healthcare API on a new port through this inbound endpoint.

Step 3: Build and run the artifacts

Prerequisites

Before you begin, install Micro Integrator on your machine:

  1. Go to the WSO2 Micro Integrator web page, click Download, provide necessary details, and then click Zip Archive to download the Micro Integrator distribution as a ZIP file.

  2. Extract the ZIP file. The extracted folder will be referred as the <MI_HOME> folder.

Once you have downloaded and set up the Micro Integrator locally, follow the steps given below. Use one of the below two methods.

  1. Click on the Command Palette on the top of the VS Code.

  2. Type > to show the available commands.

  3. Select MI: Add MI server.

  4. Select Add MI server.

  5. Select the folder where <MI_HOME> is located. This wll be set as the current server path.

    Current server path

  6. Run the project.

    Click the Build and Run icon located in the top right corner of the VS Code.

    Build and run

Step 4: Test the use case

Let's test the use case by sending a simple client request that invokes the service.

Start the backend service

  1. Download the JAR file of the back-end service from here.
  2. Open a terminal, navigate to the location where you saved the back-end service.
  3. Execute the following command to start the service:

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

Send the client request

Let's send a message to the healthcare REST API (through the inbound endpoint) on port 8285. You can use Postman or any other HTTP Client:

  1. Open the Postman application. If you do not have the application, download it from here : Postman

  2. Add the request information as given below and click the Send button.

    Method GET
    URL http://localhost:8285/healthcare/querydoctor/surgery





If you want to send the client request from your terminal:

  1. Install and set up cURL as your REST client.
  2. Open a command line terminal and execute the following command:

    curl -v http://localhost:8285/healthcare/querydoctor/surgery
    

You will get the response shown below. The inbound endpoint has successfully invoked the REST API, and further, the response received by the REST API has been routed back to the client through the inbound endpoint.

[
    {
        "name": "thomas collins",
        "hospital": "grand oak community hospital",
        "category": "surgery",
        "availability": "9.00 a.m - 11.00 a.m",
        "fee": 7000.0
    },
    {
        "name": "anne clement",
        "hospital": "clemency medical center",
        "category": "surgery",
        "availability": "8.00 a.m - 10.00 a.m",
        "fee": 12000.0
    },
    {
        "name": "seth mears",
        "hospital": "pine valley community hospital",
        "category": "surgery",
        "availability": "3.00 p.m - 5.00 p.m",
        "fee": 8000.0
    }
]