This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Transforming Message Content
Message transformation is necessary when the message format sent by the client is different from the message format expected by the back-end service. The Message Translator architectural pattern in WSO2 Enterprise Integrator (WSO2 EI) describes how to translate from one data format to another.
In this tutorial , you send a request message to a back-end service where the payload is in a different format when compared to the request payload expected by the back-end service. Data Mapper mediator in WSO2 EI is used to transform the request message payload to the format expected by the back-end service.
See the following topics for a description of the concepts that you need to know when creating WSO2 EIartifacts:
Before you begin,
Install Oracle Java SE Development Kit (JDK) version 1.8.* and set the JAVA_HOME environment variable.
Download the WSO2 EI ZIP file from here, and then extract the ZIP file.
The path to this folder will be referred to as<EI_HOME>through out this tutorial.Select and download the relevant WSO2 EI tooling 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>through out this tutorialIf you did not try the Routing Requests Based on Message Content tutorial yet, open the WSO2 EI Tooling environment, 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 Routing Requests Based on Message Content 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/microservicesfolder. The back-end service is now deployed in the MSF4J profile of WSO2 EI.
Let’s assume this is the format of the request sent by the client:
{
"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": "2017-04-02"
}
However, the format of the message must be as follows to be compatible with the backend service.
{
"patient": {
"name": "John Doe",
"dob": "1990-03-19",
"ssn": "234-23-525",
"address": "California",
"phone": "8770586755",
"email": "johndoe@gmail.com"
"cardNo": "7844481124110331",
},
"doctor": "thomas collins",
"hospital": "grand oak community hospital"
"appointment_date": "2017-04-02"
}
The client message format must be transformed to the back-end service message format within the In sequence.
Let's get started!
This tutorial contains the following sections:
Creating the deployable artifacts
The Data Mapper mediator transforms the message within the In sequences. The Data Mapper mediator is a data mapping solution that can be integrated into a mediation sequence. It converts and transforms one data format to another, or changes the structure of the data in a message.
In WSO2 EI Tooling, add a Data Mapper mediator just after the Property mediator in the In sequence of the API resource.
Double click the Data Mapper mediator icon and provide the following name for the data mapping configuration file that will be created.
Configuration Name: RequestMapping
Click OK. You view the data mapping editor.
Create a JSON file by copying the following sample content of the request message sent to the API Resource, and save it in your local file system.
{ "name": "John Doe", "dob": "1990-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": "2017-04-02" }Right-click on the top title bar of the Input box and click Load Input as shown below .
Select JSON as the Resource Type as shown below.
Click the file system link in Select resource from, select the JSON file you saved in your local file system in step 5, and click Open.
You view the input format loaded in the Input box in the editor as shown below.Create another JSON file by copying the following sample content of the request message expected by the backend service, and save it in your local file system.
{ "patient": { "name": "John Doe", "dob": "1990-03-19", "ssn": "234-23-525", "address": "California", "phone": "8770586755", "email": "johndoe@gmail.com" }, "doctor": "thomas collins", "hospital": "grand oak community hospital", "appointment_date": "2017-04-02" }Right-click on the top title bar of the Output box and click Load Output as shown below.

Select JSON as the resource type
Click the file system link in Select resource from, select the JSON file you saved in your local file system in step 7, and click Open.
You view the input format loaded in the Output box in the editor as shown below.
Do the mapping by dragging arrows from field values in the input box to the relevant field values in the output box. The final mapping is as follows:
Save and close the configuration.
Go back to the Design View of the API Resource and select the Data Mapper Mediator and edit the following in the Properties tab:
Input Type: JSON
Output Type: JSON
Save the REST API configuration.
We are now ready to package and deploy the C-App and send the request.
Packaging the artifacts
Since we created a new Registry Resource project, this will need to be packaged into our existing C-App.