Welcome!

IBM Cloud Authors: Liz McMillan, Stackify Blog, Elizabeth White, Pat Romanski, Yeshim Deniz

Related Topics: IBM Cloud

IBM Cloud: 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.


    @ThingsExpo Stories
    "IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
    In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
    22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
    "Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
    Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
    Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
    "MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    Large industrial manufacturing organizations are adopting the agile principles of cloud software companies. The industrial manufacturing development process has not scaled over time. Now that design CAD teams are geographically distributed, centralizing their work is key. With large multi-gigabyte projects, outdated tools have stifled industrial team agility, time-to-market milestones, and impacted P&L stakeholders.
    "Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    "Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
    "There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
    SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
    It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
    WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, introduced two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a multip...
    A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
    SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
    Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
    To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...