|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
MXDJ TOP LINKS YOU MUST CLICK ON ! Web Services Building DB2-Based Web Services Using WebSphere, Part 2
Building DB2-Based Web Services Using WebSphere, Part 2
Sep. 25, 2002 12:00 AM
In my previous article (WSDJ, Vol. 1, issue 7), I gave you a glimpse of the Web Services Object Runtime Framework (WORF), a set of tools for implementing Web services with DB2 and WebSphere. WORF is deployed on WebSphere Application Server (WAS) and uses Apache SOAP 2.2. It implements a layer that runs on WAS and is responsible for taking database access definitions and translating them on-the-fly to Web services constructs supporting SOAP messages and WSDL documents. The mapping between the database definitions and the Web service is done in a Document Access Definition eXtension (DADX) file. WORF uses the DADX definition to provide an implementation of a Web service through a servlet that accepts a Web service invocation over SOAP, an HTTP GET, or an HTTP POST. This servlet implements the Web service by accessing DB2, invoking the SQL operation defined in the DADX file, and returning the results as a SOAP response. Last month's focus was on the general framework and the reasons why DB2-based Web services are so attractive. This month I'll continue with a more in-depth discussion of WORF and show you how to build DADX files, deploy them on WAS, and more.
System Requirements and Installation
Next, you need to install WORF. After you download worf.zip (see Resources), unzip it and copy worf.jar and soap-samples.jar to {WAS_ HOME}/AppServer/lib. You should then install the sample Web application services.war as a new enterprise application within WAS. You can do this using the administrator's console (regardless of whether you're running the single-server edition or the advanced edition). Figure 1 shows the first step of the installation using the single-server administrator's console. Remember, after creating the enterprise application you need to regenerate the Web server plug-in and restart the server. You're now ready to go.
Example Scenario
The operations for which DB2-based Web services are provided are:
Building DADX Files
A DADX file is an XML document. The root node is a DADX node, but the real work is done within the operation nodes. Listing 1 shows a very simple DADX file defining a Web service called getWorkForEmployee, which receives an employee ID and returns a collection of two-tuples, each containing the call number and the action number. DADX also supports update operations. As an example, Listing 2 shows the DADX file used for the second Web service on our list - a Web service that updates the status of a call. The operation in this DADX file is an update operation that wraps an SQL update statement. Note that in addition to the operation, a documentation element has been added; this will find its way into the WSDL file that's automatically generated by WORF on your behalf. Finally, Listing 3 shows the DADX document for the third Web service wrapping a call to a stored procedure. Incidentally, a DADX file may contain many operation elements, each transformed into a Web service by WORF.
Deploying and Calling WORF Web Services
Database properties are specified within a groups.properties file, as shown in Listing 4. This file tells WAS which JDBC driver to load and how to connect to the database. It also defines reload parameters allowing you to modify the DADX files and have WAS reload the definitions automatically. In our example, the groups.properties should be placed in a folder called callWS under {WAS_HOME}/App Server/installedApps/servicesApp.ear/WEB-INF/classes/groups. Your DADX files should also be placed here. You need to inform the WORF that you've created a new group and the associated Web services. For each group, add a DxxInvoker servlet to your web.xml file within the Web application. Each invoker servlet handles a set of Web services that access the same DB2 instance. Listing 5 shows the additions to the web.xml file required to support the CALL Web services; now you're ready to start using the Web services. WORF supports both HTTP bindings and a SOAP binding. When invoking a WORF Web service using an HTTP GET binding, use a URL of the form http:// <host>/callWS/getWorkForEmployee.dadx/getWorkForEmployee?employee_id=112001. This invokes the first operation shown in Listing 1, passing in the employee ID to be used by the SQL query. The same form of invocation would be used in an HTTP POST request, except that the parameter would be passed within the request body. To use the SOAP binding, activate a URL of the form http://<host>/ call WS/getWorkForEmployee.dadx/SOAP. The input arguments are passed in as a SOAP request within the body of the request. If all operations are packaged together in a single DADX file (let's assume all operations are inside the CALL.dadx file), the invocation over HTTP GET would take the form of http://<host>/callWS/ CALL.dadx/ getWorkForEmployee?employee_id=112001. Invocation over SOAP would always use a URL of the form http://<host>/callWS/ CALL.dadx/ SOAP, while the SOAP request would embody the actual operation that needs to be invoked.
WSDL and Schema Files
For example, to get the WSDL file for the query shown in Listing 1, simply access a URL of the form http:// <host>/callWS/getWorkForEmployee.dadx/WSDL. This will return a WSDL document that describes your Web service. If you want to publish your Web service on a UDDI registry, you actually need the WSDL delivered in two files - a service file and a binding file. To retrieve these documents use the following two URLs:
http://<host>/callWS/getWorkForEmployee.dadx/WSDLservice WORF even takes care of generating schema files for you. Regardless of whether you use advanced XML manipulation with the XML Extender (in which case metadata is often held as DTDs), you can easily retrieve XSD files for your Web service. As an example, to generate an XSD file for the getWorkForEmployee Web service simply access a URL of the form http://<host>/callWS/getWorkForEmployee.dadx/XSD.
Advanced XML Manipulation
Summary
Because so many of today's systems are database-centric, many of the Web services you may need to build involve either database operations or storing/retrieving data from your data store. I hope that when you have such a task you remember WORF and the work it can save you. While this two-part series introduced you to the subject, it is by no means a complete overview of WORF, XML Extender, DADX, or DAD files. The resources below provide all you need to build and deploy DB2-based Web services.
Resources
LATEST FLEX STORIES & POSTS
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||