Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Tip

Before you begin,

  1. Install Oracle Java SE Development Kit (JDK) version 1.8.* and set the JAVA_HOME environment variable.
  2. Go to the product page of WSO2 Enterprise Integrator, select Other Installation Options, and download the Binary distribution. Extract the ZIP file of the binary. This will be your <EI_HOME> directory.
  3. 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.

    Note

    Getting an error message? See the troubleshooting tips given under Installing WSO2 Integration Studio.

  4. If you did not try the Routing Requests Based on Message Content tutorial yet, open 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 Routing Requests Based on Message Content tutorial so that you do not have to repeat those steps.
  5. 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.

...

Code Block
languagexml
{
  "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"
}

...

  1. In WSO2 Integration Studio, add a Data Mapper mediator just after the Property mediator in the In Sequence of the API resource.

  2. 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

    Note

    The SampleServicesRegistry project is created at the time of creating the ESB Solution project and will get auto-picked here.

    Click OK. You view the data mapping editor.

  3. Create a JSON file (e.g., input.json) by copying the following sample content of the request message sent to the API Resource, and save it in your local file system.

    Code Block
    languagexml
    { "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": "2025-04-02"
    }
    Info

    You can create a JSON schema manually for input and output using the Data Mapper Diagram editor.

  4. Right-click on the top title bar of the Input box and click Load Input as shown below. 

  5. Select JSON as the Resource Type as shown below.

  6. Click the file system link in Select resource from, select the JSON file (i.e., input.json) 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. 

    the input format 

    Anchor
    step 7
    step 7

  7. Create another JSON file (e.g., out put.json ) by copying the following sample content of the request message expected by the backend service, and save it in your local file system.  

    Code Block
    languagexml
    {
      "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": "2025-04-02"
    }
  8. Right-click on the top title bar of the Output box and click Load Output as shown below. 
  9. Select JSON as the resource type.
  10. 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. 

    Info

    Check the Input and Output boxes with the sample messages, to see if the element types (i.e. (Arrays, Objects and Primitive values) are correctly identified or not. Following signs will help you to identify them correctly. 

    • {} - represents object elements
    • [] - represents array elements
    • <> - represents primitive field values
    • A - represents XML attribute value
  11. 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:
  12. Save and close the configuration.
    Input and output can be tested as below.

  13. 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



  14. Save the REST API configuration.


...