Doron Sherman

Subscribe to Doron Sherman: eMailAlertsEmail Alerts
Get Doron Sherman: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: Apache Web Server Journal

Apache Web Server: Article

Building DB2-Based Web Services Using WebSphere, Part 2

Building DB2-Based Web Services Using WebSphere, Part 2

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
The system configuration required to implement DB2-based Web services through WORF includes the following:

  • DB2 Universal Database Version 7.2
  • DB2 XML Extender (only for advanced XML manipulation)
  • WebSphere Application Server version 4.0
  • Apache SOAP 2.2
  • WORF
Assuming you've already installed DB2 and WAS, the rest is simple and should take no more than five minutes. Installing SOAP 2.2 involves downloading the soap-bin-2.2.zip file (see Resources), unzipping it, and copying soap-2_2/lib/soap.jar into {WAS_HOME}/AppServer/lib.

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
I'll continue using the example scenario from Part 1, which is taken from the world of call centers. In this example, a call center database stores problem reports and work statuses. For every problem called in by a customer, a CALL is created. The information describing the call is maintained in the CALL table. Once the call is logged, the support center starts working on the problem. Work is encapsulated in an ACTION, which records information such as who is assigned to handle the problem, the scheduled start date, the estimated time of arrival (ETA), and so on. Information pertaining to what work is done in the context of an action is also recorded, and all of this activity is maintained as a record in an ACTION table. The DADX files assume the table structures shown in Table 1.

The operations for which DB2-based Web services are provided are:

  • Given an employee ID, return a list of all work assigned to this resource.
  • Update the status of an action.
  • Given an employee ID, call a stored procedure that computes the yearly first-time fix rate (i.e., how frequently the engineer resolves the problem on his or her first attempt). This complex business function can't be phrased as an SQL operation and is implemented as a stored procedure.

    Building DADX Files
    At the heart of WORF are the DADX files, which specify how to create a Web service using SQL operations. DADX supports all SQL operations, including queries, updates, and calls to stored procedures.

    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
    You need to do a bit of setup before you can start accessing your DADX-based Web services. Specifically, you need to set up a WORF group and specify the database properties that will be used to access the database. After all, the DADX files define the SQL commands but don't specify the database instance to which the SQL should be applied.

    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
    WORF is used not only at runtime for wrapping the SQL operation as a Web service in the context of an invocation; it also generates all that's required to deploy your Web service. WORF can automatically generate a Web Services Description Language (WSDL) file, which allows others to learn how to use your Web service. You can publish this WSDL document in a UDDI registry.

    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
    http://<host>/callWS/getWorkForEmployee.dadx/WSDLbinding

    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
    WORF supports two types of Web services: SQL-based operations and XML-based operations. The DADX documents shown above have all been SQL-based operations. XML-based operations allow you to compose XML documents from relational data and store it. You can create as complex a mapping as is required to allow you to make the most of your relational store without compromising your XML layouts. This uses advanced XML collection operations supported by the DB2 XML Extender, a package that allows you to store and retrieve XML documents from DB2 using flexible metadata definitions. To use these advanced features you must have the DB2 XML Extender option installed, and you need a more thorough understanding of how to use DAD files. This requires a bit of learning; for more details, see the Resources section.

    Summary
    WORF allows you to Web service-enable your DB2 database and leverage your investment in the database schema and its procedures by autowrapping them with Web services deployed on WAS. You can do this easily by writing a simple DADX file and inserting it into an appropriate groups directory.

    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

  • Download DB2 v7.2 at www14.software.ibm.com/webapp/download/ category.jsp?s=c&cat=data .
  • Download XML Extender for DB2 at www-3.ibm.com/software/data/db2/extenders/ xmlext/downloads.html.
  • Download a trial version of WAS 4 at www7b.boulder.ibm.com//wsdd/downloads/#WAS.
  • Download Apache SOAP 2.2. at http://xml.apache.org/dist/soap/version-2.2.
  • For more information and to download WORF, see www-3.ibm.com/software/data/db2/extenders/ xmlext/docs/v72wrk/WORF.html.
  • For more information on XML Extender and DAD files, see ftp://ftp.software.ibm.com/ps/products/ db2/info/vr7/pdf/letter/db2sxe70.pdf.
  • For more details on DADX, download the DADX specification at ftp://ftp.software.ibm.com/ps/products/db2extenders/ software/xmlext/docs/v72wrk/webserv/dadx.html.
  • More Stories By Ron Ben-Natan

    Ron Ben-Natan is Chief Technology Officer at ViryaNet Inc. Prior to that he worked for companies such as Intel, AT&T Bell Laboratories, Merrill Lynch and as a consultant at J.P. Morgan. He has a Ph.D. in Computer Science in the field of distributed computing and has been architecting and developing distributed applications for over 15 years. His hobby is writing about how technology is used to solve real problems and he has authored numerous books including “IBM WebSphere Application Server: The Complete Reference” published by Osborne/McGraw. He can be reached at

    More Stories By Doron Sherman

    Doron Sherman is the CTO of Collaxa, Inc., a Web Service Orchestration Server vendor and a BEA Partner located in Redwood Shores, California. He has been involved with Java since its early days and pioneered application server technology while being a founder and chief scientist at NetDynamics.

    Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.