 | Developing Universal Services
If you want to modify the Universal Services, the easiest way of doing
so is through IBM Data Studio Developer. Maybe you want to add a
parameter or create additional operations like dedicated XPath
queries. Included as part of the tutorial
download is a zip file containing the Web
service that can be imported into Data Studio for modification.
IBM Data Studio Developer is an integrated Eclipse-based development
environment for creating and testing database applications with most
functions available for download free of charge, including data Web
services. (See Resources for a link to
download Data Studio Developer.)
This section includes detailed instructions on how to import and
configure the Data Studio project. For more information on developing
Web services using Data Studio, refer to some of the articles listed
in the Resources section.
Import Universal Services project to Data Studio
This tutorial assumes that Data Studio has been installed and that it
has been started using the data perspective.
- Right-click on the space in the Data Project Explorer, and select
Import:
Figure 47.
Import project into Data Studio, step 1
- Select Existing Projects into Workspace, and click on
Next:
Figure 48.
Import project into Data Studio, step 2
- Enter the destination of the file or browse to find it, and click
on Finish:
Figure 49.
Import project into Data Studio, step 3
- The project will appear in the Data Project Explorer. Click on the
project. You will be asked if you want to edit the connection
profile. Click on Edit now:
Figure 50.
Configure database connection, step 1
- You then get a list of connections to choose from. Select
Universal Services Database Connection1, and click on
Edit:
Figure 51.
Configure database connection, step 2
- In the "Properties for Universal Database Connection1" window,
select Driver Properties from menu on the left:
Figure 52.
Configure database connection, step 3
- Enter your own values for the Database (DB2 location name), Host,
Port number, User name, and Password fields, then click on Test
Connection:
Figure 53.
Configure database connection, step 4
- Click OK to the receipt.
- Click OK in the "Universal Services Database Connection1
Properties" window.
- Click on Finish in the Connection window.
- Expand the project folder, and in your "Data Project Explorer",
you should see the following contents: A folder structure with
main folders SQL Scripts, Stored Procedures, User-Defined
Functions, Web Services, and XML. The Web Services folder contains
a subfolder named Universal Services, containing the services you
are going to modify. The XML folder contains subfolders WSDL, XML
Documents, XML Schema, and XSLT.
Figure 54.
Universal Services project contents
At this point you are ready to modify the Web services. You might want
to change one of the existing operations, for example, by adding a
parameter or adding operations to the Web service. For more
information on how to use Data Studio to develop Web services, see
Resources.
When you have made your modification (or even without modifications),
you can deploy your Web service.
- Right-click on the Web services folder, and select Build and
Deploy:
Figure 55.
Deploy Web service, step 1
- In the "Deploy Web Service" window, choose which Web server to use
from the drop-down menu.
- Choose whether to deploy to the Web server or just build the .war
file. Here, just build the .war file, as the other option requires
some configuration of the Web server in Data Studio.
- Make sure the location name is correct, then click on
Finish:
Figure 56.
Deploy Web service, step 2
A message in the Workspace log shows that the Web service has been
deployed together with the destination of the .war file:
Figure 57. Deploy Web
service, step 3
Finally, you have to deploy the .war file to the chosen Web server.
(Refer to the "Deploying the Web servers"
section.)
In the Universal Services bundle, an XHTML document defines a full Web
page, providing a user interface for invoking the Web service
operations. When modifying the operations through Data Studio, this
XHTML document may no longer be applicable, but it can be updated
manually to cater for the changes.
The XHTML document contains forms that collect arguments and generate
HTTP POST requests to the Web server. As an
example, the form for the
getXMLDocumentByKey operation is shown in
Listing 4:
Listing 4. XHTML for invoking operation getXMLDocumentByKey
<form name="testServices_getXMLDocumentByKey"
action="rest/UniversalServices/getXMLDocumentByKey"
method="post">
<tr class="row-dark" >
<td>getXMLDocumentByKey</td>
<td align="right">ID:</td>
<td align="center">
<input type="text" name="p1" size="40" />
</td>
<td align="center">
<input type="submit" value="Invoke" />
</td>
</tr>
</form> |
You can see that the name of the operation is part of the action URL
and that the form field for the single argument is named p1 (and p2,
p3, and so on for subsequent arguments).
Alternatively, the individual operations of the Web service can be
invoked directly through the HTTP GET
method. Listing 5 shows example of URLs for each of the supplied
operations. Note that parameters are passed as p1, p2, and so on, and
separated by an ampersand (&).
Listing 5. URLs for GET methods of Universal Services
http://localhost:8888/servicesUniversalServices/rest/UniversalServices/getPrimaryKeys?
http://localhost:8888/servicesUniversalServices/rest/UniversalServices
/getXMLDocumentByKey?p1=1
http://localhost:8888/servicesUniversalServices/rest/UniversalServices/deleteDocument?p1=3
http://localhost:8888/servicesUniversalServices/rest/UniversalServices
/update?p1=<document4>updated document</document4>&p2=4
http://localhost:8888/servicesUniversalServices/rest/UniversalServices
/insertXML?p1=A comment&p2=<document5>new doc</document5>
http://localhost:8888/servicesUniversalServices/rest/UniversalServices
/runxpathXML?p1=.&p2=2 |
|  |