The following sections describe how WSO2 EI Tooling can be used to create artifacts for data integration.
Creating a data service project
- You can either use the link on the dashboard (click Developer Studio -> Open Dashboard) as shown below, or use the File-> New -> Other -> Data Service Project option.
- On the window that appears, specify a project name.
- If you want to customize the Maven options (such as including parent POM information in the file from another project in this workspace), click Next and specify the options.
- Click Finish.
Creating a data service
A data service provides a Web service interface to access data that is stored in relational databases, CSV files, Microsoft Excel sheets, Google spreadsheets, and more. You can create a new data service or import an existing data service from a data service descriptor (DBS) file.
Creating a new data service
Follow these steps to create a new data service. Alternatively, you can import an existing data service.
- You can either use the Data Service Project link on the dashboard (click Developer Studio -> Open Dashboard) or right-click on the Data Service project and click New -> Data Service.
- Select Create New Data Service and click Next.
- Type unique names for the project and data service.
- Optionally, specify the service group, namespace, description, location, and working set for this data service.
- Click Next and specify a unique ID for the data source.
- Specify the type of data source you are creating, and then configure the properties that appear for that type. For details on configuring various data source types, see the data integration tutorials.
- A Maven POM file will be generated automatically for this project. If you want to customize the Maven options (such as including parent POM information in the file from another project in this workspace), click Next and specify the options.
- Click Finish. The data service is created, and the data service is open in the editor. You can now right-click the data service in the outline and add queries, operations, additional data sources, and so on, or click the Source view to add components using XML.
Importing a data service
Follow these steps to import an existing data service from a data service descriptor (DBS) file. Alternatively, you can create a new data service.
- You can either use the Data Service link on the dashboard (click Developer Studio -> Open Dashboard) or right-click on the Data Service project and click New -> Data Service.
- Select Import Data Service and click Next.
- Specify the data service descriptor (DBS) file by typing its full pathname or clicking Browse and navigating to the file.
- Optionally specify the location and working sets for this project.
- A Maven POM file will be generated automatically for this project. If you want to customize the Maven options (such as including parent POM information in the file from another project in this workspace), click Next and specify the options.
- Click Finish. The data service is created, and the data service is open in the editor. You can now right-click the data service in the outline and add queries, operations, additional data sources, and so on, or click the Source view to add components using XML.
Applying security to a data service
WSO2 supports WS-Security, WS-Policy, and WS-Security Policy specifications and these specifications define a behavioral model for Web services. To enable a security policy for a data service, you need to first create a security policy file, and then add it to the data service.
Step 1: Create a security policy
Follow the instructions given below.
Open your data service in Developer Studio as explained in the Creating a new data service section given above. You can either create a new data service or import an existing DBS file.
- Now, open the Developer Studio Dashboard (click Developer Studio > Open Dashboard) and click Registry Resource Project.
- Enter a name for the project and click Next.
- Enter the Maven information about the project and click Finish.
- Right-click on the SecurityPolicyProject in the left navigation panel, click New and then select Registry Resource.
Enter a resource name and select the WS-Policy template along with the preferred registry path.
- Click Finish and the policy file will be listed in the navigator.
Double-click on the policy file to view the list of security policies. You can use the Design View or the Source View.
- Enable required scenario. Click the icon next to each scenario for more information.
- You can provide service information as a private store, and advanced configuration information as a rampart configuration.
- 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.
The security policy will now be saved to the resource project as shown below.
Step 2: Add the security policy to the data service
Once you have configured the policy file, you can add the security policy to the data service as explained below.
Select the sample data service (.dbs file) that is already stored in the workspace, and click the browse icon for the Policy field.
There are two ways to add a security policy to the data service: If you have a policy file already stored in your product registry, you can add it by clicking registry. If you want to use a new policy file that you have created and stored in your current workspace, you can add it by clicking workspace.
- 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. - Click OK, and the security policy will be added to the data service.
You now have a security policy added to your data service. When you creating a creating a CAR file to deploy this data service in your ESB server, be sure to set the server role to Enterprise Service Bus as explained below.
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.
- Open the data service file in WSO2 EI tooling.
- Add an output element to your data service:
- Right-click the data service and add a query.
- Right-click the query and an output mapping.
- Right-click the oupt mapping and add an element.
- Right-click the data service and add a query.
- Add the user roles as a comma-separated list in the Allowed User Roles field as shown below.
Adding multiple data services
It is possible to add multiple data services to a Data Service project by following the steps described above. The project structure will be as follows:
Creating a custom validator
An input validator allows a data service to validate the input parameters in a request and stop the execution of the request if the input doesn’t meet the required criteria. In addition to the default validators provided by Data Service Server, you can create your own custom validators by creating a Java class that implements the org.wso2.carbon.dataservices.core.validation.Validator
interface. You can create a new custom validator or import an existing validator project.
Creating a new custom validator
Follow these steps to create a new custom validator. Alternatively, you can import an existing validator project.
- You can either use the Data Services Validator Project link on the dashboard (click Developer Studio -> Open Dashboard) or click File-> New -> Other -> Data Services Validator Project option.
- Select Create New Data Services Validator Project and click Next.
- Type a unique name for the project and specify the package and class name for this validator.
- Optionally, specify the location and working set for this project.
- A Maven POM file will be generated automatically for this project. If you want to customize the Maven options (such as including parent POM information in the file from another project in this workspace), click Next and specify the options.
- Click Finish. The project is created, and the new validator class is open in the editor, where you can add your validation logic.
Importing a validator project
Follow these steps to import an existing custom validator project. Alternatively, you can create a new custom validator.
- You can either use the Data Services Validator Project link on the dashboard (click Developer Studio -> Open Dashboard) or click File-> New -> Other -> Data Services Validator Project option.
- Select Import Project From Workspace and click Next.
- Select the existing validator project, and optionally specify the location and working sets for the new project.
- A Maven POM file will be generated automatically for this project. If you want to customize the Maven options (such as including parent POM information in the file from another project in this workspace), click Next and specify the options.
- Click Finish. The project is imported, and the validator class is open in the editor, where you can modify the validation logic as needed.
Deploying the data service in WSO2 EI
Once you have created the data service artifacts as explained in the previous topics, you need to create a Composite Application project, and then create a CAR file to deploy it in the ESB server.
- Right-click the Project Explorer and click New -> Project.
- From the window that opens, click Composite Application Project.
- Give a name to the Composite Application project and select the projects that you need to group into your C-App from the list of available projects.
In the Composite Application Project POM Editor that opens, under Dependencies, note the information for each of the projects you selected earlier. If you have added a security policy to your data service using a registry resource as explained above, be sure that EnterpriseServiceBus is selected as the server role as shown below.
- To deploy the artifacts using the ESB's management console, you need to create a CAR file as follows:
- Right-click the C-App project and select Export Composite Application Project from the pop-up menu.
OR - Open the
pom.xml
file in the Composite Application Project POM Editor and click the button for creating an archive in the upper-right corner.
The CAR file is now saved in the location you specify. See Packaging Artifacts into Composite Applications, for more information on using CAR files
- Right-click the C-App project and select Export Composite Application Project from the pop-up menu.
- Next, deploy the CAR file in the server.