This documentation is for WSO2 Enterprise Integrator version 6.1.1 . View documentation for the latest release in the 6.x.x family and the latest release in the 7.x.x family.

All docs This doc
Skip to end of metadata
Go to start of metadata

Note that WSO2 EI is shipped with the following changes to what is mentioned in this documentation:

  • <PRODUCT_HOME>/repository/samples/ directory that includes all Data Integration samples is changed to <EI_HOME>/samples/data-services/.
  • <PRODUCT_HOME>/repository/samples/resources/ directory that includes all artifacts related to the Data Integration samples is changed to <EI_HOME>/samples/data-services/resources/.

About the sample

A popular data format used with RESTful services is JSON. This sample contains a data service with JSON output mapping templates. See Exposing Data in JSON Format for details on how to use JSON templates for output mapping in a data service. Also, see Using JSON Messages with RESTful services, for details on sending JSON payloads in a message.

The service contains the following resources:

  • Resource: "offices"
  • Method: POST 
  • Description: Lists all the offices in the database. When office information is printed, all the employees that belong to an office are also printed using a nested query (which uses the employeesInOfficeSQL query).

  • Resource: "boston_customers"
  • Method: GET
  • Description: Returns all the customers in Boston. 

  • Resource: "employee/{employeeNumber}"
  • Method: GET
  • Description: Returns employee information for the given employee number.

  • Resource: "employee"
  • Method: POST
  • Description: Insert a new employee with the given information. 

  • Resource: "employee" with batch request 
  • Method: POST
  • Description: Insert a set of new employees with the given information.

  • Resource: "employee"
  • Method: PUT
  • Description: Updates an existing user with new information. 

  • Resource: "employee"
  • Method: GET
  • Description: Retrieve an existing employee. 

Building the sample

The sample data service named JSONSample should be deployed using the instructions in Samples Setup.

Running the sample

The sample service can be run using any client that can do REST calls. For example, use tools such as cURL or Advanced REST Client Chrome browser extension. The HTTP header "Accept" should be set to "application/json", and also, if a JSON payload is sent to the server, the HTTP header "Content-Type" should be set to "application/json".

The HTTP requests sent for each of the resources using cURL would be as follows:

  • "offices" (method=GET)

    curl -X GET -H "Accept: application/json" http://localhost:8280/services/samples/JSONSample/offices
  • "boston_customers" (method=GET)

    curl -X GET -H "Accept: application/json" http://localhost:8280/services/samples/JSONSample/boston_customers
  • "employee/{employeeNumber}" (method=GET)

    curl -X GET -H "Accept: application/json" http://localhost:8280/services/samples/JSONSample/employee/1002
  • "employee" (method=POST): A sample payload named employee-payload.json, which can be used when sending the data is given below.

    {
      "_postemployee": {
        "employeeNumber" : 14001,
        "lastName": "Smith",
        "firstName": "Will",
        "email": "[email protected]",
        "salary": 15500.0
      }
    }

    The HTTP request sent using CURL would be as follows:

    curl -X POST -H 'Accept: application/json'  -H 'Content-Type: application/json' --data "@employee-payload.json" http://localhost:8280/services/samples/JSONSample/employee
  • "employee" (method=POST) with batch-request: A sample payload named employee-payload.json, which can be used when sending the data is given below.

    Note that you need to enable batch requesting for the data service before proceeding:

    1. Log in to the management console of WSO2 EI using the following URL: https://localhost:9443/carbon.

    2. Select the JSONSample data service that is listed in the Services → List menu.
    3. Click Edit Data Service (Wizard) to open the wizard and select the Enable Batch Request check box.
    4. Click Next and save the changes.

    Batch requesting is now enabled for the data service.

    {
        "_postemployee_batch_req": {
            "_postemployee": [
                {
                    "employeeNumber": 5012,
                    "lastName": "Smith",
                    "firstName": "Will",
                    "email": "[email protected]",
                    "salary": 13500.0
                },
                {
                    "employeeNumber": 5013,
                    "lastName": "Peter",
                    "firstName": "Parker",
                    "email": "[email protected]",
                    "salary": 15500.0
                }
            ]
        }
    }

    The HTTP request sent using CURL would be as follows:

    curl -X POST -H 'Accept: application/json'  -H 'Content-Type: application/json' --data "@employee-payload.json" http://localhost:8280/services/samples/JSONSample/employee_batch_req
  • "employee" (method=PUT) -  A sample payload named employee-payload-update.json, which can be used when sending the data is given below.

    {
      "_putemployee": {
        "employeeNumber" : 14001,
        "lastName": "Smith",
        "firstName": "Will",
        "email": "[email protected]",
        "salary": 78500.0
      }
    }

    The HTTP request sent using CURL would be as follows:

    curl -X PUT -H 'Accept: application/json'  -H 'Content-Type: application/json' --data "@employee-payload-update.json" http://localhost:8280/services/samples/JSONSample/employee
  • "employee" (method=GET)

    curl -X GET -H 'Accept: application/json'  http://localhost:8280/services/samples/JSONSample/employee/14001
  • No labels