Generating Web Services for View Models in JBoss Data Virtualization 6.1

Vijay Chintalapati bio photo By Vijay Chintalapati Comment
Quick Index
Prerequisites
Web Service Requirements
Creating Web Services from a Relational Model
Differences between REST and SOAP web service generation

Prerequisites

Before attempting to generate webservices (REST or SOAP based) the following prerequisites should be met:

  1. Teiid Model project created
  2. One or more Source Models created
  3. One or more View Models created
  4. One or more Virtual View/Tables created for which the web services need to be generated

Web Service Requirements

In JBoss Data Virtualization, one can create both RESTful and SOAP based web services. Web services can be created from:

  • Existing WSDL file or URL
  • Relational Models
  • XML Document View Models

This article would focus on creating web services from relational models.

Sample project setup

The following steps would work thru a sample project as shown in the image below. The setup and the resources created in the sample project are self-explanatory as can be seen in the image below.


Creating Web Services from a Relational Model

For REST based only

  1. Create a Virtual Procedure that returns XML as output in the View Model exposed to the client
  2. Create a VDB, include the View Model to be exposed in it and Deploy it
  3. Using VDB, generate REST War
  4. Deploy the REST War file
  5. Test the REST War

For SOAP based only

  1. Create a Web Service on the View Model (for SOAP based web service)
  2. Create a VBD, include the View Model and Web Service Models and Deploy it
  3. Using VDB, generate SOAP War
  4. Deploy the SOAP War file
  5. Test the SOAP War

Creating a Virtual Procedure

Step 1 : Right click on the canvas of the View Model and create a New childProcedure

Step 2 : Choose Procedure and click on OK

Step 3 : In the Properties tab, fill the properties for the procedure. Also fill the REST options as shown

Step 4 : In the Parameters tab, add a Input parameter by the name, for example CustomerID, as shown below

Step 5 : In the Transformation SQL tab, add a transformation sql similar to the one shown below and click OK

Step 6 : Preview the procedure, right-click on the procedure and choose ModelingPreview Data. Put in a value for the input parameter and verify the output.

This step requires active connection between JBoss Developer Studio and JBoss Data Virtualization runtime. The blue glow on the left hand side under Default Server and in front of the Teiid Version indicates a successful connection.

Create/Deploy VDB exposing REST services

Step 1 : Create a new Teiid VDB

Right-click on the name of the project and choose NewTeiid VDB

Step 2 : Give the VDB a name, add the View Model and click Finish

Step 3 : Bind each Data Source to a JNDI name in the designer

This step requires a data source to be created in the JBoss Data Virtualization runtime for the same database and assigned a JNDI name as a prerequisite. For example, create a new data source with the same connection details as given to Local_MySQL (in the image below) in the runtime and assign a JNDI name java:/LocalMySQL.

Once the prerequisite is satisfied, in the designer choose the source model under Models tab and in the Source Binding Definition on the right side, pick the appropriate JNDI name from the drop-down as shown in the image below. Repeat the same steps for all data sources.

Uncheck the checkbox against each source model (in blue) in the second column that toggles the visibility of the model in the deployed VDB. The visibility should ideally be turned off for source models.

Step 4 : Save the VDB

Step 5 : Deploy the VDB

Right-click on the VDB name and choose ModelingDeploy, as shown below

On the next screen of the VDB deployment, provide a JNDI name for the VDB and click Create Source

Generate REST War file

Right click on the VDB and choose ModelingGenerate REST War

Considering no security for the web application, give it a context-path and the folder path to save as shown below and click OK

Deploy the REST War File

Copy/Move the dvdemo-rest.war file from its location into the deployments folder of the JBoss Data Virtualization runtime, as shown below

Test the REST War

Test the REST web service as shown below. The URL to use, if testing on the localhost is of the form :

http://{dv-ip}:{dv-port}/{rest-war-context}/{view-model-name}/{rest-uri}/{rest-path-param}


Create a SOAP Web Service

Right-click on the View Model and choose ModelingCreate Web Service, as shown below

In the next window, choose the folder you would like the resulting files to be created, as shown

Create/Deploy VDB exposing SOAP services

Step 1 : Create a new Teiid VDB

Right-click on the name of the project and choose NewTeiid VDB

Step 2 : Give the VDB a name, add the View Model, add associated Web Service Models (as shown) and click Finish

Step 3 : Bind each Data Source to a JNDI name in the designer

Similar to Step 3 of Create/Deploy VDB exposing SOAP services

Step 4 : Save the VDB

Step 5 : Deploy the VDB

Right-click on the VDB name and choose ModelingDeploy, as shown below

On the next screen of the VDB deployment, provide a JNDI name for the VDB and click Create Source

Generate SOAP War file

Right click on the VDB and choose ModelingGenerate SOAP War

Considering no security for the web application, give it a context-path and the folder path to save as shown below and click OK

Deploy the SOAP War File

Copy/Move the dvdemo-soap.war file from its location into the deployments folder of the JBoss Data Virtualization runtime, as shown below

Test the SOAP War

Test the SOAP web service with SOAP UI as shown below. The WSDL for the project can be found at a path of the form:

http://{dv-ip}:{dv-port}/{soap-war-context}/{view-model-name}_{virtual-table-name}?WSDL

Differences between REST and SOAP web service generation

Following are the differences between the two approaches to Web Service generation in their initial and default generation without customization.

REST SOAP
Requires one or more virtual stored procedures with XML as output No requirement for virtual stored procedures
The output of the web service is based on the virtual stored procedure definition By default, all of the columns of the view table are part of the output
The input parameters to the web service map to the input parameters to the virtual stored procedure The input parameters map to the columns that form the primary key
comments powered by Disqus