com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

Exposing RDF Data as a Data Service

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

The RDF file (Movies.rdf), stored in the <EI_HOME>/samples/data-services/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:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cd="http://www.popular.movies/cd#">

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

<rdf:Description
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:year>2001</cd:year>
<cd:genre>Drama</cd:genre>
<cd:actor>John Clegg</cd:actor>
</rdf:Description>

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

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

<rdf:Description
rdf:about="http://www.popular.movies/cd/Austenland">
<cd:title>Austenland</cd:title>
<cd:director>Jerusha Hess</cd:director>
<cd:year>2013</cd:year>
<cd:genre>Adaptation</cd:genre>
<cd:actor>Georgia King</cd:actor>
</rdf:Description>

<rdf:Description
rdf:about="http://www.popular.movies/cd/Beginners">
<cd:title>Beginners</cd:title>
<cd:director>Mike Mills</cd:director>
<cd:year>2011</cd:year>
<cd:genre>Drama</cd:genre>
<cd:actor>Seth T Walker</cd:actor>
</rdf:Description>

<rdf:Description
rdf:about="http://www.popular.movies/cd/Flipped">
<cd:title>Flipped</cd:title>
<cd:director>Rob Reiner</cd:director>
<cd:year>2010</cd:year>
<cd:genre>Drama</cd:genre>
<cd:actor>Michele Messmer</cd:actor>
</rdf:Description>

<rdf:Description
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:year>2012</cd:year>
<cd:genre>Adaptation</cd:genre>
<cd:actor>Anthony Lawton</cd:actor>
</rdf:Description>

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

<rdf:Description
rdf:about="http://www.popular.movies/cd/Adventureland">
<cd:title>Adventureland</cd:title>
<cd:director>Greg Mottola</cd:director>
<cd:year>2009</cd:year>
<cd:genre>Drama</cd:genre>
<cd:actor>Ryan Mcfarland</cd:actor>
</rdf:Description>

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

<rdf:Description
rdf:about="http://www.popular.movies/cd/WALL-E">
<cd:title>WALL-E</cd:title>
<cd:director>Andrew Stanton</cd:director>
<cd:year>2008</cd:year>
<cd:genre>Adventure</cd:genre>
<cd:actor>Ben Burtt</cd:actor>
</rdf:Description>

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

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

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

<rdf:Description
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:year>2002</cd:year>
<cd:genre>Drama</cd:genre>
<cd:actor>Antoine Drolet Dumoulin</cd:actor>
</rdf:Description>

<rdf:Description
rdf:about="http://www.popular.movies/cd/Ratatouille">
<cd:title>Ratatouille</cd:title>
<cd:director>Jan Pinkava</cd:director>
<cd:year>2007</cd:year>
<cd:genre>Drama</cd:genre>
<cd:actor>Teddy Newton</cd:actor>
</rdf:Description>

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

</rdf:RDF>

See the following topics for instructions. Also, see the samples in /wiki/spaces/EI6xx/pages/49616348.


Creating a data service

Follow the steps given below.

  1. Download the product installer from here, and run the installer.
    Let's call the installation location of your product the <EI_HOME> directory. This is located in a place specific to your OS as shown below:

    OSHome directory
    Mac OS/Library/WSO2/EnterpriseIntegrator/6.6.0
    WindowsC:\Program Files\WSO2\EnterpriseIntegrator\6.6.0\
    Ubuntu/usr/lib/wso2/EnterpriseIntegrator/6.6.0
    CentOS/usr/lib64/EnterpriseIntegrator/6.6.0

  2. Start the ESB profile:

  3. Log in to the product's management console.
  4. Click Data Service → Create, to start creating a data service.
  5. Enter the following name for the data service.

    Data Service NameRDFDataService
  6. Click Next to enter the datasource connection details.

Connecting to the datasource

Follow the steps given below.

  1. Click Add New Datasource and enter the following details:

    Datasource IDRDF
    Datasource TypeRDF
    RDF File LocationEnter 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/data-services/resources/Movies.rdf.
  2. Save the datasource.
  3. Click Next, to start creating queries.

Creating a query to GET data

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 and enter the following details:

    Query IDGetMoviebyGenre
    DatasourceRDF
    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.
    }
  2. The input mapping section is used to specify the type of input that should be given in order to get the output result. Click Add New Input Mapping to start creating the input mapping. We will create an input mapping for 'genre', which will allow us to query for data based on the genre of the movie.

    Mapping Namegenre
    Sparql TypeString
  3. 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. Start by giving the following information:

      Output typeYou can select XML, JSON or RDF. We will use XML for this tutorial. This specifies the format in which the query results should be presented. 
      Grouped by elementEnter Movies. This will be the XML element that will group the query result.
      Row NameEnter Movie. This is the XML element that should group each individual result.
    2. Click Add New Output Mapping to start creating the output mapping for the title column. 
    3. Click Add to save the output mapping. You will now have one output mapping listed for the GetMoviesbyGenre query.
    4. Now, add the following output mappings:

      Mapping TypeElement NameDatasource TypeDatasource Column NameParameter TypeSchema Type
      ElementtitleColumntitleSCALARstring
      ElementdirectorColumndirectorSCALARstring
      ElementyearColumnyearSCALARstring
      ElementgenreColumngenreSCALARstring
      ElementactorColumnactorSCALARstring
    5. Click Main Configuration to return to the Query screen.
  4. Save the query, and click Next to go to the Operations screen.

Creating a SOAP operation to invoke the query

To invoke the query, you need to define an operation.

  1. Click Add New Operation and enter the following information.

    Operation NameGetMoviesbyGenreOp
    Query IDGetMoviesbyGenre
  2. Save the operation.

You can now invoke the data service query using SOAP.

Creating a REST resource to invoke the query

Now, let's create REST resources to invoke the query created above. Alternatively, you can create SOAP operations to invoke the queries. See the previous section for instructions.

  1. Click Add New Resource and enter the following information.

    Resource PathMovies/{genre}
    Resource MethodGET
    Query IDGetMoviesbyGenre
  2. Save the resource.

You can now invoke the data service query using REST.

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 using SOAP 

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">
       <Movie>
          <title>Ratatouille</title>
          <director>Jan Pinkava</director>
          <year>2007</year>
          <genre>Drama</genre>
          <actor>Teddy Newton</actor>
       </Movie>
       <Movie>
          <title>Catch Me If You Can</title>
          <director>Steven Spielberg</director>
          <year>2002</year>
          <genre>Drama</genre>
          <actor>Antoine Drolet Dumoulin</actor>
       </Movie>
       <Movie>
          <title>The Spectacular Now</title>
          <director>James Ponsoldt</director>
          <year>2013</year>
          <genre>Drama</genre>
          <actor>Andre Royo</actor>
       </Movie>
       <Movie>
          <title>Adventureland</title>
          <director>Greg Mottola</director>
          <year>2009</year>
          <genre>Drama</genre>
          <actor>Ryan Mcfarland</actor>
       </Movie>
       <Movie>
          <title>Begin Again</title>
          <director>John Carney</director>
          <year>2014</year>
          <genre>Drama</genre>
          <actor>Eric Burton</actor>
       </Movie>
       <Movie>
          <title>Flipped</title>
          <director>Rob Reiner</director>
          <year>2010</year>
          <genre>Drama</genre>
          <actor>Michele Messmer</actor>
       </Movie>
       <Movie>
          <title>Beginners</title>
          <director>Mike Mills</director>
          <year>2011</year>
          <genre>Drama</genre>
          <actor>Seth T Walker</actor>
       </Movie>
       <Movie>
          <title>Bridget Jones's Diary</title>
          <director>Cilla Ware</director>
          <year>2001</year>
          <genre>Drama</genre>
          <actor>John Clegg</actor>
       </Movie>
    </Movies>

Invoking your data service using REST

You can send an HTTP GET request to invoke the data service using cURL as shown below.

curl -X GET http://localhost:8280/services/RDFDataService.HTTPEndpoint/Movies/Drama

This will return the response in XML.

com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.