Using Inbound Endpoints¶
What you'll build¶
In this tutorial, 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. See Creating an Inbound Endpoint for details on how to work with inbound endpoints using WSO2 Integration Studio.
Let's get started!¶
Step 1: Set up the workspace¶
Set up WSO2 Integration Studio as follows:
- Download the relevant WSO2 Integration Studio based on your operating system. The path to the extracted/installed folder is referred to as
MI_TOOLING_HOME
throughout this tutorial. - If you did not try the Sending a Simple Message to a Service tutorial yet:
- Download the pre-packaged project.
- Open WSO2 Integration Studio and go to File -> Import.
- Select Existing WSO2 Projects into workspace under the WSO2 category, click Next, and then upload the prepackaged project.
Optionally, you can set up the CLI tool for artifact monitoring. This will later help you get details of the artifacts that you deploy in your Micro Integrator.
- Go to the WSO2 Micro Integrator website.
- Click Download -> Other Resources and click CLI Tooling to download the tool.
- Extract the downloaded ZIP file. This will be your
MI_CLI_HOME
directory. - Export the
MI_CLI_HOME/bin
directory path as an environment variable. This allows you to run the tool from any location on your computer using themi
command. Read more about the CLI tool.
Step 2: Develop the Inbound Endpoint¶
-
Once you have exported the ESB project as described in above, the project directory will appear with the artifacts as shown below. Note the 'HealthcareAPI' that is already included.
-
Right-click on SampleServices and navigate to New -> Inbound Endpoint. Select Create A New Inbound Endpoint and click Next.
-
Enter the following details and click Finish.
Parameter Description Inbound Endpoint Name QueryDoctorInboundEndpoint Inbound Endpoint Creation Type HTTP -
Go to the Properties tab in the Design view and enter the following:
Parameter Description Inbound HTTP port 8285 Dispatch Filter Pattern /healthcare/querydoctor/.*
The endpoint will now get mapped to any URL that matches the above pattern provided. You will be exposing the health care API on a new port through this inbound endpoint.
Step 3: Package the artifacts¶
Package the artifacts in your composite application project (SampleServicesCompositeApplication project) to be able to deploy the artifacts in the server.
- Open the
pom.xml
file in the composite application project POM editor. -
Ensure that the following artifacts are selected in the POM file.
HealthcareAPI
QueryDoctorInboundEndpoint
-
Save the project.
Step 4: Build and run the artifacts¶
To test the artifacts, deploy the packaged artifacts in the embedded Micro Integrator:
- Right-click the composite application project and click Export Project Artifacts and Run.
- In the dialog that opens, select the artifacts that you want to deploy.
- Click Finish. The artifacts will be deployed in the embedded Micro Integrator and the server will start. See the startup log in the Console tab.
Step 5: Test the use case¶
Let's test the use case by sending a simple client request that invokes the service.
Start the backend service¶
- Download the JAR file of the back-end service from here.
- Open a terminal, navigate to the location where your saved the back-end service.
- Execute the following command to start the service:
java -jar Hospital-Service-2.0.0-EI7.jar
Get details of deployed artifacts (Optional)¶
Let's use the CLI Tool to find details of the inbound endpoint and REST API.
Tip
Be sure to set up the CLI tool for your work environment as explained in the first step of this tutorial.
-
Open a terminal and execute the following command to start the tool:
mi
-
Log in to the CLI tool. Let's use the server administrator user name and password:
mi remote login admin admin
You will receive the following message: Login successful for remote: default!
-
Execute the following commands:
-
To find the Inbound Endpoint artifacts deployed in the server:
mi inboundendpoint show
You will receive the following information:
Name : QueryDoctorInboundEndpoint
Type : http -
To find the REST API deployed in the server:
mi api show
You will receive the following information:
NAME : HealthcareAPI
URL : http://localhost:8290/healthcare
-
Similarly, you can get details of other artifacts deployed in the server. Read more about using the CLI tool.
Send the client request¶
Let's send a message to the healthcare REST API (through the inbound endpoint) on port 8285. You can use the embedded HTTP Client of WSO2 Integration Studio as follows:
-
Open the HTTP Client of WSO2 Integration Studio.
Tip
If you don't see the HTTP Client tab, go to Window -> Show View - Other and select HTTP Client to enable the client.
-
Enter the request information as given below and click the Send icon ().
Method GET
URL http://localhost:8285/healthcare/querydoctor/surgery
If you want to send the client request from your terminal:
- Install and set up cURL as your REST client.
-
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
}
]
Top