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

This tutorial will guide you on how to expose data in a CSV file as a data service by using the  Create New Data Service wizard. We will create a data service that can search for data on the file.

Note that you can only read data from CSV files. That is, the ESB profile of WSO2 EI does not support inserting, updating or modifying data in a CSV file.

We will use the Products.csv  file  that is shipped with WSO2 EI by default.  The Products.csv  file stored in the  <EI_HOME>/samples/data-services/resources  folder contains data about products (cars/motorocyles) that are manufactured in an automobile company. The data table has the following columns: "ID", "Name", "Classification" and "Price".

Follow the steps given below to create a data service for this datasource. Also, see the samples in Data Integration Samples.


Start the Create New Data Service wizard

Now, let's start creating the data service from scratch:

Add a CSV file as the datasource

You can add a CSV file as the datasource as explained below.

  1. Click  Add New Datasource  and enter values as shown below. 
  2. Follow the instructions below to fill the datasource details.
    • Datasource Id:  Enter an ID for you datasource. We will enter  CSV  as the datasource Id.
    • Datasource Type:  Select  CSV  as the datasource type from the list. You can now specify the details of the CSV file.
    • CSV File Location : Specify the path to your CSV file. In this tutorial, we are using a sample CSV file that is stored in the following location of your product distribution: ./samples/data-services/resources/Products.csv.
    • Column Separator: Add 'comma' as the column separator.
    • Start Reading From Row: Specify 2 to start reading from the second row.
    • Contains Column Header Row : Select true from the list.
    • Header row : Enter '1' as the value.
  3. Save the datasource. 
  4. Click Next to go to the Queries screen.

Define a query for the datasource

Now let's start writing a query for searching for data in the CSV datasource. The query will specify the data that should be fetched, and the format that should be used to display data when the query is invoked.

  1. Click Add New Query to open the Add New Query screen.
  2. In the Query ID field, enter an identifier for the query. We will enter Q1.
  3. In the  Datasource  field, select the datasource for which you are going to write a query. Select the CSV  datasource that you created previously.
  4. Now let's specify output mappings, which will determine how the result from your query will be presented when the query is invoked.  The sample CSV  datasource  we are using contains three columns: ID, Name, Category and Price. We will create an output mapping for each of these columns.  
    1. In the Output type field, specify the format in which the query results should be presented. You can select XML, JSON or RDF. We will use XML for this tutorial.
    2. In the Grouped by element field, specify a grouping for all the output mappings. This will be the XML element that will group the query result. We will enter Products.
    3. In the Row Name field, specify the XML element that should group each individual result. Enter Product  in this field.
    4. Click Add New Output Mapping to start creating the output mapping for the ID column. Enter values as shown below:
    5. Click Add to save the output mapping. You will now have one output mapping listed for the Q1 query as shown below.
    6. You can now create output mappings for the remaining columns given below.

      Mapping TypeElement NameDatasource TypeDatasource Column NameParameter TypeSchema Type
      ElementCategoryColumnClassificationSCALARstring
      ElementPriceColumnPriceSCALARstring
      ElementNameColumnNameSCALARstring
    7. Once you have created all the output mappings, click Main Configuration to return to the Edit Query screen.

      Find out more about defining Output Mappings.

  5. Click Save, to save the query.
  6. Click Next to go to the Operations screen.

Define an operation to invoke the query

You need to define an operation to expose data as a SOAP service.

  1. Click Add New Operation to open the following screen.
  2. In the  Operation Name  field, enter a name for the operation.
  3. In the Query ID  field, select the query that you created.
  4. Save the operation.

Finish creating the data service

In this tutorial, we are only defining a SOAP service to expose the data. Therefore, you can click Finish to complete the data service creation process, after defining the operation. You will now be taken to the  Deployed Services screen, which shows all the data services deployed on the server.

If you click Next after defining the operation, you will be taken to the Add Resources screen, which allows you to expose the data as a REST resource. If you want to create a REST resource, see Exposing Data as a REST Resource for information.


Invoking your data service

You can try the data service you created by using the TryIt tool that is in your product by default.

  1. Go to the Deployed Services screen.
  2. Click the Try this service link for the CSV data service. The TryIt tool will open with the CSV service.
  3. Select the operation that you created previously and click Send.
  4. The result of the Q1 query will be published.
  • No labels