In this sample scenario, you will use a Sequence Template and reuse it in multiple places of the medation flow. You can reuse the mediation flow that was defined in the /wiki/spaces/EI6xx/pages/49614279 tutorial and then replace its sections with the sequence template. See Creating Templates for details on how to work with templates using WSO2 Integration Studio.
Before you begin,
- Install Oracle Java SE Development Kit (JDK) version 1.8.* and set the JAVA_HOME environment variable.
- Download the product installer from here, and run the installer.
Let's call the installation location of your product the <EI_HOME> directory. This is located in a place specific to your OS as shown below:OS Home directory Mac OS /Library/WSO2/EnterpriseIntegrator/6.6.0
Windows C:\Program Files\WSO2\EnterpriseIntegrator\6.6.0\
Ubuntu /usr/lib/wso2/EnterpriseIntegrator/6.6.0
CentOS /usr/lib64/EnterpriseIntegrator/6.6.0
Select and download the relevant WSO2 Integration Studio ZIP file based on your operating system from here and then extract the ZIP file.
The path to this folder will be referred to as<EI_TOOLING>
throughout this tutorial.Getting an error message? See the troubleshooting tips given under /wiki/spaces/EI6xx/pages/49612293.
- If you did not try the /wiki/spaces/EI6xx/pages/49614337 tutorial yet, open the WSO2 Integration Studio, click File, and then click Import. Next, select Existing WSO2 Projects into workspace under the WSO2 category, click Next and upload the pre-packaged project. This contains the configurations of the /wiki/spaces/EI6xx/pages/49614337 tutorial so that you do not have to repeat those steps.
- Download the MSF4J service from here and copy the JAR file to
<EI_HOME>/wso2/msf4j/deployment/microservices
folder. The back-end service is now deployed in the MSF4J profile of WSO2 EI.
Let's get started!
Configuring a sequence template
Once you have exported the ESB project as described above, the project directory will appear with the artifacts as shown below.
Right-click on SampleServices and navigate to New -> Template. The New Template Artifact dialog will open.
Select the Create a New Template and click Next.
Enter the following details and click Finish.
Template Name HospitalRoutingSeq Template Type Sequence Template The template artifact will open in the canvas as shown below.
Open the Properties tab of the sequence template by clicking on the canvas (outside the sequence box).
Click the icon to start adding parameters.
In the Template Parameter dialog that opens, enter 'sethospital' as the parameter name and click Finish.
Add a Log mediator to the sequence template as shown below. This will print a message indicating to which hospital a requested message is routed.
Open the Properties tab of the log mediator and specify the following:
Log Category INFO Log Level CUSTOM Click the icon to start defining a property. Then add the following details for the property:
Name message Type EXPRESSION Property Expression fn:concat('Routing to ', get-property('Hospital')) We select EXPRESSION because the required properties for the log message must be extracted from the request, which we can do using an XPath expression.
Add a Property mediator just after the Log mediator to store the value for uri.var.hospital.
With the Property mediator selected, access the Properties tab and enter the information given below:
Property Name
Select New Property
New Property Name
uri.var.hospital
URI Template
Select set
Value Type
Select EXPRESSION
Property Data Type
Select STRING
Value Expression
$func:sethospital
Description
Set Hospital Variable
Using the sequence template in the REST API
Open the design view of the HealthcareAPI.xml and delete 'GrandOak'Log mediator by right clicking the mediator and selecting Delete from Model.
Delete the 'Set Hospital Variable' Property mediator.
Add a Call Template mediator to the sequence as shown below.
Open the Properties tab of the Call Template mediator and select 'HospitalRoutingSeq' from the list of available templates.
Click the icon to start adding parameters. Enter the following parameter details and click Finish.
Parameter Name
sethospital
Parameter Type
value
Value/Expression
grandoaks
Repeat the above steps to add Call Templates for 'Clemency' and 'Pine Valley' hospitals. Add clemency and pinevalley as the respective parameter values.
Save the configuration.
Deploying the artifacts
Open the
pom.xml
file under the SampleServicesCompositeApplication project from the project explorer.See that the newly added 'HospitalRoutingSeq' artifact is listed under Dependencies. Select this artifact to add it to the composite application project.
Save your changes.
Open the Getting Started view and click Miscellaneous →Add New Server to open the New Server dialog.
- In the New Server dialog, expand the WSO2 folder and select the version of your server.
- Click Next. In the CARBON_HOME field, provide the path to your product's home directory, and then click Next again.
Review the default port details for your server and click Next.
To deploy the CApp project to your server, select the SampleServicesCompositeApplication project from the list, click Add to move it into the configured list, and then click Finish.
On the Servers tab, note that the server is currently stopped. Click the 'play' icon on the tool bar. If prompted to save changes to any of the artifact files you created earlier, click Yes.
As the server starts, the Console tab appears. Note messages indicating that the composite app was successfully deployed.
Invoking the ESB sequence
Send a request to the ESB as shown below and see that the response is successfully received.
Open a command line terminal and execute the following command from the location where the request.json file you created is 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 in the command line terminal.