Due to a known issue do not use JDK1.8.0_151 with WSO2 products. Use JDK 1.8.0_144 until JDK 1.8.0_162-ea is released.
This documentation is for WSO2 Data Services Server version 3.5.1. For the latest documentation, see the documentation for WSO2 Enterprise Integrator.
Skip to end of metadata
Go to start of metadata

This tutorial will guide you on how to expose an RDF datasource as a data service using WSO2 Data Services Server. To demonstrate this feature, we will use a sample RDF file that is shipped with WSO2 DSS by default. Given below are the details of this datasource: 

The RDF file (Movies.rdf), stored in the <DSS_HOME>/samples/resources/ folder contains data about some popular movies. Each movie data has the following sub elements: "title", "director", "year", "genre" and "actor".

 Movies.rdf file

<?xml version="1.0"?>

rdf:about="http://www.popular.movies/cd/Roman Holiday">
<cd:title>Roman Holiday</cd:title>
<cd:director>William Wyler</cd:director>
<cd:actor>Gorella Gori</cd:actor>

rdf:about="http://www.popular.movies/cd/Bridget Jones's Diary">
<cd:title>Bridget Jones's Diary</cd:title>
<cd:director>Cilla Ware</cd:director>
<cd:actor>John Clegg</cd:actor>

rdf:about="http://www.popular.movies/cd/The Proposal">
<cd:title>The Proposal</cd:title>
<cd:director>Anne Fletcher</cd:director>
<cd:actor>Alexis Garcia</cd:actor>

rdf:about="http://www.popular.movies/cd/The Princess Diaries">
<cd:title>The Princess Diaries</cd:title>
<cd:director>Garry Marshall</cd:director>
<cd:actor>John McGivern</cd:actor>

<cd:director>Jerusha Hess</cd:director>
<cd:actor>Georgia King</cd:actor>

<cd:director>Mike Mills</cd:director>
<cd:actor>Seth T Walker</cd:actor>

<cd:director>Rob Reiner</cd:director>
<cd:actor>Michele Messmer</cd:actor>

rdf:about="http://www.popular.movies/cd/Silver Linings Playbook">
<cd:title>Silver Linings Playbook</cd:title>
<cd:director>David O. Russell</cd:director>
<cd:actor>Anthony Lawton</cd:actor>

rdf:about="http://www.popular.movies/cd/Begin Again">
<cd:title>Begin Again</cd:title>
<cd:director>John Carney</cd:director>
<cd:actor>Eric Burton</cd:actor>

<cd:director>Greg Mottola</cd:director>
<cd:actor>Ryan Mcfarland</cd:actor>

rdf:about="http://www.popular.movies/cd/The Spectacular Now">
<cd:title>The Spectacular Now</cd:title>
<cd:director>James Ponsoldt</cd:director>
<cd:actor>Andre Royo</cd:actor>

<cd:director>Andrew Stanton</cd:director>
<cd:actor>Ben Burtt</cd:actor>

rdf:about="http://www.popular.movies/cd/Love Actually">
<cd:title>Love Actually</cd:title>
<cd:director>Richard Curtis</cd:director>
<cd:actor>Tiffany Boysell</cd:actor>

rdf:about="http://www.popular.movies/cd/Kicking and Screaming">
<cd:title>Kicking and Screaming</cd:title>
<cd:director>Jesse Dylan</cd:director>
<cd:actor>Willie Amakye</cd:actor>

rdf:about="http://www.popular.movies/cd/Harold and Maude">
<cd:title>Harold and Maude</cd:title>
<cd:director>Hal Ashby</cd:director>
<cd:actor>G Wood</cd:actor>

rdf:about="http://www.popular.movies/cd/Catch Me If You Can">
<cd:title>Catch Me If You Can</cd:title>
<cd:director>Steven Spielberg</cd:director>
<cd:actor>Antoine Drolet Dumoulin</cd:actor>

<cd:director>Jan Pinkava</cd:director>
<cd:actor>Teddy Newton</cd:actor>

rdf:about="http://www.popular.movies/cd/The Dark Knight">
<cd:title>The Dark Knight</cd:title>
<cd:director>Christopher Nolan</cd:director>
<cd:actor>Andy Luther</cd:actor>


See the following topics for instructions:

Start the Create New Data Service wizard

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

Add and RDF file as the datasource

You can add an RDF 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 RDF as the ID for the datasource. 
    • Datasource Type: Select RDF as the datasource type from the list. You can then specify the location of your RDF file: ./samples/resources/Movies.rdf
    • RDF File Location: Enter the path to the RDF file. In this tutorial we are using a sample RDF file that is shipped with your product. The file location is ./samples/resources/Movies.rdf.
  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 getting data from the Movies.rdf file. The query will specify the data that should be fetched by this query, 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. Enter the following values:
    • Query ID: Enter GetMoviesbyGenre as the query ID.
    • Datasource: Select the datasource for which you are going to write a query. Select the RDF datasource that you created previously.
    • SPARQL: In this field, enter the sparql query describing the data that should be retrieved from the RDF datasource. We will use the following query:

      PREFIX cd: <http://www.popular.movies/cd#>
      SELECT ?title ?director ?year ?genre ?actor 
      WHERE {   
            ?movie cd:title ?title. 
            ?movie cd:director ?director. 
            ?movie cd:year ?year. 
            ?movie cd:genre ?genre. 
            ?movie cd:actor ?actor.

Create input mapping

The input mapping section is used to specify the type of input that should be given in order to get the output result.

  1. Click Add New Input Mapping to start creating the input mapping.
  2. We will create an input mapping for 'genre', which will allow us to query for data based on the genre of the movie. Enter the values as shown below.
  3. The new input mapping will be listed as shown below.

Find out more about defining Input Mappings in WSO2 DSS.

Create output mapping

Now let's specify output mappings to specify how the data fetched from the query should be displayed. We will create output mappings for all the types of data in the RDF file:  title, director, year, genre and actor. Follow the steps given below.

  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 Movies in this field. 
  3. In the Row Name field, specify the XML element that should group each individual result. Enter Movie in this field.
  4. Click Add New Output Mapping to start creating the output mapping for the title column. Enter values as shown below:
  5. Click Add to save the output mapping. You will now have one output mapping listed for the GetMoviesbyGenre query as shown below.
  6. Now, add the following output mappings:

    Mapping TypeElement NameDatasource TypeDatasource Column NameParameter TypeSchema Type

Find out more about defining Output Mappings in WSO2 DSS.

Define an operation to invoke the query

Follow the steps given below.

  1. Once you have defined the query, click Next to go to the Operations screen.
  2. Click Add New Operation and enter the following values:
    • Operation Name: Enter GetMoviesbyGenre as the operation name.
    • Query ID: Select the GetMoviesbyGenre query in this field.
  3. Save the operation. 

Finish creating the data service 

Once you have defined the operation, click Finish to complete the data service creation process. You will now be taken to the Deployed Services screen, which shows all the data services deployed on the server.

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 Excel data service. The TryIt Tool will open with the RDF service.
  3. Enter Drama as the genre: <xs:Genre xmlns:xs="http://ws.wso2.org/dataservice">Drama</xs:Genre>
  4. Select the GetMoviesbyGenre operation and click Send.
  5. The following XML response will be published on the TryIt tool:

    Movies xmlns="http://ws.wso2.org/dataservice">
          <director>Jan Pinkava</director>
          <actor>Teddy Newton</actor>
          <title>Catch Me If You Can</title>
          <director>Steven Spielberg</director>
          <actor>Antoine Drolet Dumoulin</actor>
          <title>The Spectacular Now</title>
          <director>James Ponsoldt</director>
          <actor>Andre Royo</actor>
          <director>Greg Mottola</director>
          <actor>Ryan Mcfarland</actor>
          <title>Begin Again</title>
          <director>John Carney</director>
          <actor>Eric Burton</actor>
          <director>Rob Reiner</director>
          <actor>Michele Messmer</actor>
          <director>Mike Mills</director>
          <actor>Seth T Walker</actor>
          <title>Bridget Jones's Diary</title>
          <director>Cilla Ware</director>
          <actor>John Clegg</actor>
  • No labels