JBoss.orgCommunity Documentation
Teiid Designer allows you to expose your VDBs via a SOAP or REST interface. JBossWS-CXF or RESTEasy wars can be generated based on models within your VDBs. This section describes these wizards in detail.
The Teiid Designer provides web service generation capabilities in the form of a JBossWS-CXF war. Once you have added your Web Service Models as described in Section 7.5, “Creating Web Service View Model” to your VDB, deployed the VDB to a running Teiid instance and created your VDB's data source, you are ready to expose the web service using the generated war.
To generate a new JBossWS-CXF war using the VDB:
Step 1 - Right-click on the VDB containing your web service model(s) and select the Modeling > Generate JBossWS-CXF War action.
Step 2 - Fill in missing properties in Web Service War Generation Wizard shown below.
Table 11.1. Field Descriptions
Field Name | Description |
---|---|
Name | The name of the generated war file. |
Host | The server host name (or IP). |
Port | The server port. |
Connection JNDI Name | The JNDI connection name to the deployed Teiid source VDB. |
Security options |
|
Target namespace | This is the target namespace that will be used in the generated WSDL and subsequent generated web service classes. |
War File Save Location | The folder where the generated WAR file should be saved. |
Step 3 - Click OK to generate the web service war. When war generation is complete, a confirmation dialog should appear. Click OK.
In Teiid Designer, it is also possible to expose your VDBs over REST using a generated RESTEasy war. Also, if your target virtual model has update, insert and delete SQL defined, you can easily provide CRUD capabilities via REST. Accepted inputs into the generated REST operations are URI path parameters and/or XML. The only output at this time is an XML document.
Step 1 In a virtual model, add a procedure(s) that returns an XMLLiteral object. The target of your procedure can be any models in your VDB. Here is an example procedure that selects from a virtual table (VirtualBooks) and returns the results as an XMLLiteral:
Notice the syntax used to convert the relation table result of the select from VirtualBooks, to an XMLLiteral. All XML functions are documented in the Scalar Functions chapter of the Teiid Reference Guide.
Here is an example of an update procedure that will insert a row and return an XMLLiteral object:
The input format for the REST procedure could be URI parameters, an XML document, or some combination of both. When using an XML document your root node should be <input> and the XML nodes should correspond to order of the procedure's input parameters. For example, here is the input for the above insert procedure:
Step 2 - Now we need to identify our procedure as REST eligible. To do this we add two extended properties to the procedure via the Modeling->Manage Extended Properties context menu option.
The two required properties are defined in the table below:
Table 11.2. Required Extended Properties for RESTful Procedures
Property Name | Description |
---|---|
REST-METHOD | The HTTP method that will determine the REST mapping of this procedure. Supported methods are: GET, PUT, POST and DELETE |
URI | The resource path to the procedure. For example, if you use “books/{isbn}” as your URI value for a procedure, http://{host}:{port}/{war_context}/{model_name}/books/123 would execute this procedure and pass 123 in as a parameter. |
Here's what the above example would look like in the Extended Properties dialog:
Note that the generated URI will have the model name included as part of the path, so full URL would look like this: http://{host}:{port}/{war_context}/{model_name}/books/123. If you wanted a REST service to return all books, you would write your procedure just as it is above, but remove the input parameter. The URI property would then just be 'books' (or whatever you want) and the URL would be http://{host}:{port}/{war_context}/{model_name}/books.
Once you have added all of your procedures along with the required extended properties, be sure and add the model to your VDB or synchronize if it's already included in the VDB. You will then need to re-deploy the VDB.
If you redeploy your VDB during development, you may receive an "Invalid Session Exception" due to a stale connection obtained for the pool. This can be corrected by flushing the data source or, alternatively, you could add a test query to your VDB connection's -ds.xml file. This will insure you get a valid connection after redeploying your VDB. The syntax for the test query is as follows: <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>"
Step 3 - 3. If you have not already done so, you will need to create a data source for your VDB. This can be done in the Teiid View of Designer. Right-click on your deployed VDB and select Create Data Source. The Generate REST WAR dialog will ask you for the JNDI name for your created source so that it can connect to your VDB.
Step 4 - Right-click on the VDB containing your virtual model(s) with REST eligible procedures and select the Modeling > Generate RESTEasy War action. If there are no procedures that are REST eligible, the "Generate RESTEasy War" option will not be enabled.
Step 5 - Fill in missing properties in the REST War Generation Wizard shown below.
Table 11.3. Field Descriptions
Field Name | Description |
---|---|
Name | The name of the generated war file. |
Connection JNDI Name | The JNDI connection name to the deployed Teiid source VDB. |
War File Save Location | The folder where the generated WAR file should be saved. |
Include RESTEasy Jars in lib Folder of WAR | If selected, the RESTEasy jars and there dependent jars will be included in the lib foled of the generated WAR. If not selected, the jars will not be included. This should be de-selected in environments where RESTEasy is installed in the classpath of the server installation to avoid conflicts. |
Step 6 - Click OK to generate the REST war. When war generation is complete, a confirmation dialog should appear. Click OK.