This documentation is for WSO2 Enterprise Integrator version 6.0.0 . View documentation for the latest release.
Skip to end of metadata
Go to start of metadata

The request box feature allows you to invoke multiple operations (consecutively) to a datasource using a single operation. Follow the steps given below to define a data service that can invoke request box operations:


Setting up a datasource

Follow the steps given below to set up a MySQL database for this tutorial.

  1. Install the MySQL server.
  2. Download the JDBC driver for MySQL and copy it to your <EI_HOME>/lib directory.
  3. Create a database named Company.
  4. Create the following tables:

    • Offices table:

      CREATE TABLE `Offices` (`OfficeCode` int(11) NOT NULL, `AddressLine1` varchar(255) NOT NULL, `AddressLine2` varchar(255) DEFAULT NULL, `City` varchar(255) DEFAULT NULL, `State` varchar(255) DEFAULT NULL, `Country` varchar(255) DEFAULT NULL, `Phone` varchar(255) DEFAULT NULL, PRIMARY KEY (`OfficeCode`));
    • Employees table:

      CREATE TABLE `Employees` (`EmployeeNumber` int(11) NOT NULL, `FirstName` varchar(255) NOT NULL, `LastName` varchar(255) DEFAULT NULL, `Email` varchar(255) DEFAULT NULL, `JobTitle` varchar(255) DEFAULT NULL, `OfficeCode` int(11) NOT NULL, PRIMARY KEY (`EmployeeNumber`,`OfficeCode`), CONSTRAINT `employees_ibfk_1` FOREIGN KEY (`OfficeCode`) REFERENCES `OFFICES` (`OfficeCode`)); 
  5. Insert the following data into the Offices table:

    INSERT INTO Offices VALUES (1,"51","Glen Street","Norwich","London","United Kingdom","+441523624");
    INSERT INTO Offices VALUES (2,"72","Rose Street","Pasadena","California","United States","+152346343"); 

Define a data service to invoke request box operations

Let's create a data service using the Create Data Service wizard:

  1. Log into the management console of the ESB profile and click Create under Data Service.
  2. Add a name for the data service and select the Enable Boxcarring and Disable Legacy Boxcarring Mode check boxes.


    The Enable boxcarring option enables both the legacy boxcarring and the new request box methods. You can disable the legacy boxcarring method and use the request box method by selecting the Disable Legacy Boxcarring Mode option.

  3. Click Next and then click Add New Datasource.
  4. Connect to the Company database that you defined above. For instructions, see Exposing an RDBMS as a Data Service.
  5. Click Save, and then click Next to go to the Queries screen.
  6. Click  Add New Query  to specify the query details:

    1. Enter addEmployeeQuery as the query ID.

    2. Enter the following SQL dialect:

      insert into Employees (employeeNumber, lastName, firstName, email,officecode) values(:employeeNumber,'test','test',:email,:officecode)
  7. Click Generate Input Mapping and input mappings will be generated automatically:

  8. Click Save.

  9. Click  Add New Query to Create another query for the Company datasource:

    1. Enter selectOfficebyEmployee as the query ID.

    2. Enter the following SQL dialect:

      select officecode,addressline1,addressline2,city,state,country,phone from Offices where officecode=?
  10. Generate input and output mappings:

    1. Click Generate Input Mapping and input mappings will be generated automatically for the office code field:

    2. Click Generate Response to automatically generate the output mappings for the fields in the Offices table:

  11. Click Save.

  12. Click Next and then click Add New Operation to create an operation for the addEmployeeQuery query as shown below.

  13. Click Save.

  14. Click Add New Operation to create another operation to invoke the selectOfficebyEmployee query:

  15. Click Save and then click Finish.

Invoking the data service 

The Deployed Services  window allows you to manage data services. You can try the data service you created by using the TryIt tool in this screen, which is in your product by default.  

  1. In the Deployed Services screen, click Try this Service to open the data service from the TryIt tool. You will find that there is an additional request box operation.
  2. Select the request box operation and enter the following values:
    1. Enter values for the addEmployeeQueryOP query.

    2. Enter the same office code you used for the above query in the selectOfficebyEmpOp operation:

      <p:request_box xmlns:p="http://ws.wso2.org/dataservice">
            <!--Exactly 1 occurrence-->
            <addEmployeeQueryOp xmlns="http://ws.wso2.org/dataservice">
               <!--Exactly 1 occurrence-->
               <xs:employeeNumber xmlns:xs="http://ws.wso2.org/dataservice">110</xs:employeeNumber>
               <!--Exactly 1 occurrence-->
               <xs:email xmlns:xs="http://ws.wso2.org/dataservice">test@email.com</xs:email>
               <!--Exactly 1 occurrence-->
               <xs:officecode xmlns:xs="http://ws.wso2.org/dataservice">2</xs:officecode>
            </addEmployeeQueryOp>
            <selectOfficesbyEmpOp xmlns="http://ws.wso2.org/dataservice">
               <!--Exactly 1 occurrence-->
               <xs:param0 xmlns:xs="http://ws.wso2.org/dataservice">2</xs:param0>
            </selectOfficesbyEmpOp>
            <!--Exactly 1 occurrence-->
         </p:request_box>
  3. Execute the request box operation. 
    1. First, the addEmployeeQueryOp operation will be executed. The data will be successfully added to the database.

    2. Secondly, the selectOfficebyEmpOp operation will be executed and the details of the office attached to the employee will be returned in the result as shown below.

      <Entries xmlns="http://ws.wso2.org/dataservice">
            <Entry>
               <officecode>2</officecode>
               <addressline1>72</addressline1>
               <addressline2>Rose Street</addressline2>
               <city>Pasadena</city>
               <state>California</state>
               <country>United States</country>
               <phone>+152346343</phone>
            </Entry>
      </Entries>
  • No labels