Versions Compared

Key

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

This tutorial will guide you on how to expose a web resource as a data service using the ESB profile of WSO2 Enterprise Integrator (WSO2 EI). You can create a data service that can fetch selected data from a web resource and display the data in XML, JSON or RDF form. 

Follow the instructions below. Also, see the samples in Data Integration Samples.

Table of Contents

...

Start the Create New Data Service wizard

...

  1. Click Add New Query to open the Add New Query screen.
  2. Enter the following values:
    • Query ID: In this field, enter webquery as the query ID.
    • Datasource: In this field, select the datasource for which you are going to write a query. Select the web datasource that you created previously.
    • Scrapper Variable: When you add a query to a Web datasource, you must enter a Scraper Variable. This scraper variable must be the same as the output name in the web datasource configuration, which returns the output from the configuration. In this example, the var-def name in the configuration is weatherInfo AppInfo (< var-def name = 'AppInfo' >).
  3. Define Output Mapping: Now, let's specify how the data fetched from the datasource should be displayed in the output. We will create output mappings for the following data in the web resource: Title and Description
    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. Enter AppInfo in this field. 
    3. In the Row Name field, specify the XML element that should group each individual result.  Enter App in this field.
    4. Click Add New Output Mapping to start creating the output mapping for the Title field. Enter values as shown below:
    5. Click Add to save the output mapping. 
    6. Now, add another output mapping for the Description column.

    7. You will now have the following output mappings listed for the webquery query:

    8. Once you have created all the output mappings, click Main Configuration to return to the Edit Query screen.

      Info

      Find out more about defining Output Mappings.

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

Defining and operation to invoke the query

Follow the steps given belowYou need to define an operation, to expose data as a SOAP service.

  1. Click Add New Operation to open the Add New Operation screen. 
  2. In the Operation Name field, enter GetResource.
  3. In the Query ID field, select WebQuery.
  4. Save the operation.

Finish creating the data service

Once you have defined the operation, 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.

Info

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

...