Versions Compared

Key

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

...

  1. You can start creating a new data service in two ways:
    1. Open the dashboard (click Developer Studio -> Open Dashboard) and click Data Service.  
    2. Select the already created Data Service Project in the navigator, right click and go to New -> Data Service
    The New Data Service window will open as shown below.
  2. To start creating a data service from scratch, select Create New Data Service and click Next.

  3. Enter a name for the data service:

    Data Service NameRDBMSDataService
  4. Click Next and start adding the datasource connection details given below.

    Datasource IDDatasource
    Datasource TypeRDBMS
    Datasource Type (Default/External)Leave Default selected.
    Database EngineMySQL
    Driver Classcom.mysql.jdbc.Driver
    URLjdbc:mysql://localhost:3306/Employees
    User Nameroot
  5. Save the data service.

A data service file (DBS file) will now be created in your data service project. Shown below is the project directory.

...

  1. Select the data service you created in the previous step.
  2. Right-click and click Add Query.
  3. Enter the following query details:

    Query IDGetEmployeeDetails
    DatasourceDatasource
  4. Save the query. The query element is now added to the data service:
  5. Right-click the GetEmployeeDetails query and click Add SQL to add the following SQL statement:

    Code Block
    select EmployeeNumber, FirstName, LastName, Email from Employees where EmployeeNumber=:EmployeeNumber
  6. Save the SQL statement.
  7. Right-click the query again and click Add Input Mapping

  8. Enter the following input mapping details:

    Mapping NameEmployeeNumber
    Parameter TypeSCALAR
    SQL TypeSTRING
  9. Save the input mapping.
  10. Right-click the query again and click Add Output Mapping.

  11. Enter the following value to group the output mapping:

    Grouped by ElementEmployees
  12. Save the output mapping.

  13. Right-click the output mapping and go to Add Output Mapping → Add Element to create an element.

  14. Enter the following element details.

    Datasource Typecolumn
    Output Field NameEmployeeNumber
    Datasource Column NameEmployeeNumber
    Schema TypeString
  15. Save the element.
  16. Follow the same steps to create the following output elements:

    Datasource TypeOutput Field NameDatasource Column NameSchema Type
    columnFirstNameFirstNamestring
    columnLastNameLastNamestring
    columnEmailEmailstring
  17. Save the output elements.

...

  1. Right-click the data service and click Add Resource. Add the following resource details.

    Resource MethodGET
    Resource PathEmployee/{EmployeeNumber}
  2. Expand the GET resource, and click the GetEmployeeDetails (call-query). Connect the query to the resource by adding the following:

    Query IDGetEmployeeDetails
  3. Save the resource.

The data service should now have the resource added as shown below.

...

  1. You can start creating a registry resource in two ways:
    1. Open the dashboard (click Developer Studio -> Open Dashboard) and click Registry Resource.  
    2. Select the already created Registry Resource Project in the navigator, right click and go to New -> Registry Resource
    The New Registry Resource window will open as shown below.
  2. Select From existing template and click Next.

  3. Anchor
    step5
    step5
    Enter the following details:

    Resource NameSample_Policy
    Artifact NameSample_Policy
    TemplateWS-Policy
    Registrygov
    Registry pathws-policy/
  4. Click Finish and the policy file will be listed in the navigator.
    1. Let's use the Design View to enable the required security scenario. For example, enable the Sign and Encyrptand Encrypt security scenario as shown below.

      Tip

      Click the icon next to the scenario to get details of the scenario.


    2. You can also provide encryption properties, signature properties, and advanced rampart configurations as shown below.

      Localtabgroup
      Localtab
      titleEncryption/Signature Properties

      Localtab
      titleRampart Properties

      Info
      titleUsing role-based permissions?

      For certain scenarios, you can specify user roles. After you select the scenario, scroll to the right to see the User Roles button.

      Either define the user roles inline or retrieve the user roles from the server.

      Localtabgroup
      Localtab
      titleDefine Inline

      Localtab
      titleGet from the server

  5. Save the policy file.

...

  1. If you have already created a data service using Tooling, select the file from the Project Explorer. Alternatively, you can download this sample data service file and import it to your Tooling environment. 

  2. Once you have select the data service file, click the browse icon for the Policy field.

  3. Click workspace, to add the security policy from the current workspace. You can select the path to the sample_policy.xml file that you created in the previous steps.
  4. Click OK, and the security policy will be added to the data service.
  5. Save the data service.

...

  1. Package the data service file (.dbs file) and the security policy file into a Composite Application (CApp). See the instructions in Packaging Artifacts into Composite Applications.

    Warning

    Once you create the CApp project, note that the information about each of the projects and artifacts that you packaged into the CApp will be listed (under Dependencies in the Composite Application Project POM Editor).

    Be sure to set the server role to Enterprise Service Bus for the security policy file as shown below

  2. Add your WSO2 EI product instance to the Tooling environment and deploy the CApp in the server. See the instructions in Deploying Composite Applications in the Server.
  3. Start the ESB profile. The data service and the security policy is now deployed in WSO2 EI.

Filtering content by user role (Optional)

When you work with data services, you can control access to sensitive data for specific user roles. This facility is called role-based content filtering. It filters data where specific data sections are only accessible to a given type of users. Follow the instructions given below to add role-based filtering for output elements in your data service. 

  1. Open the data service file in WSO2 EI tooling.
  2. Add an output element to your data service:
    1. Right-click the data service and click Add Query to add a new query.
      Image Added
    2. Right-click the query and click Add Output Mapping to add an output mapping.
      Image Added
    3. Right-click the output mapping and go to Add Output Mapping → Add Element to add an element.
      Image Added
  3. Add the user roles as a comma-separated list in the Allowed User Roles field for the output element as shown below.
    Image Added

Creating a custom validator

...