You are on page 1of 45

IBM WebSphere Studio 򔻐򗗠򙳰

Hospital scenario: B2B database query


using Web services, JSP, servlets, and XML
tools
Note!
Before using this information and the product it supports, be sure to read the general
information under Notices.

Fifth Edition (December 2003)


This edition applies to Version 5.1.1 of IBM WebSphere Studio and to all subsequent releases and modifications
until otherwise indicated in new editions. Ensure that you are using the correct edition for the level of the product.
© Copyright International Business Machines Corporation 2000, 2003. All rights reserved.
US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract
with IBM Corp.
Contents
Chapter 1. Overview . . . . . . . . . 1 Creating the Web project . . . . . . . . . . 19
Implementation Details . . . . . . . . . . . 2 Importing the JAR file . . . . . . . . . . . 19
Retrieving patient information . . . . . . . 3 Generating the source code for the database query 20
Submitting the insurance claim . . . . . . . 3 Importing the source files . . . . . . . . 21
Processing the claim . . . . . . . . . . . 4 Importing the DTD file and insurance bean. . . 21
Displaying the claim response . . . . . . . 4 Creating the SQL query . . . . . . . . . 22
About Web service standards . . . . . . . . . 4 Generating the XSL file . . . . . . . . . 26
Accessing Web services . . . . . . . . . . 5 Creating the insurance Web service . . . . . . 28
About DADX . . . . . . . . . . . . . . 6 Testing the insurance Web service . . . . . . 29
Accessing DB2 using DADX operations . . . . 6 Next step . . . . . . . . . . . . . . . 30
Next step . . . . . . . . . . . . . . . 6
Chapter 5. Creating and deploying the
Chapter 2. Preparing for the sample hospital application . . . . . . . . . 31
application . . . . . . . . . . . . . 7 Creating the project . . . . . . . . . . . . 31
System prerequisites . . . . . . . . . . . . 7 Importing the XSD JAR files . . . . . . . . . 31
Enabling JDBC 2.0 on DB2 (Windows only) . . . . 7 Importing the client code . . . . . . . . . . 32
Creating the hospital and insurance databases . . . 8 Copy the proxies from the PatientProjClient and
Next step . . . . . . . . . . . . . . . 9 InsuranceProjClient projects. . . . . . . . . . 33
Next step . . . . . . . . . . . . . . . 33
Chapter 3. Developing the code for the
patient Web service . . . . . . . . . 11 Chapter 6. Running the hospital sample
Creating the Web project . . . . . . . . . . 11 application and testing the Web service 35
Creating the DADX group . . . . . . . . . 11 Submitting the claim . . . . . . . . . . . 35
Generating the DADX file . . . . . . . . . 12 Viewing the claim response . . . . . . . . . 36
Importing the DADX file . . . . . . . . . 12 Summary . . . . . . . . . . . . . . . 37
Creating the SQL query . . . . . . . . . 13
Creating the DADX file . . . . . . . . . 16 Notices . . . . . . . . . . . . . . 39
Creating the patient Web service . . . . . . . 16 Programming interface information . . . . . . 41
Testing the patient Web service . . . . . . . 18 Trademarks and service marks . . . . . . . . 41
Next step . . . . . . . . . . . . . . . 18

Chapter 4. Developing the code for the


insurance Web service . . . . . . . . 19

© Copyright IBM Corp. 2000, 2003 iii


iv
Chapter 1. Overview
In the business world, data frequently needs to be exchanged between different
organizations, such as a hospital and an insurance company. Different
organizations collect, store, and process information differently, making data
exchange difficult and time-consuming. The solution is to store data in a common
format, and to develop an application that integrates and automates the exchange
of data between different businesses across the Internet. You will use WebSphere®
Studio to develop this type of application. In this application, data exchange is
accomplished using XML, and business processes are integrated using Web
services and Simple Object Access Protocol (SOAP).

The Hospital scenario demonstrates how multiple features of WebSphere Studio


are combined in an end-to-end development scenario to build an e-business
application. To develop this application, you will use XML tools and Web service
tools. The sample application that you will develop consists of a hospital
application, a patient Web service, and an insurance Web service. Each of these
applications is distributed over four logical machines, as shown in the following
diagram:

The client is a hospital employee who processes patient information and submits
insurance claims on behalf of the patient. This employee enters the patient
information and makes a query to the hospital server. The server uses a Web
service to call the patient and insurance servers to obtain the information
requested. The arrows represent a request-response transaction.

The client machine accesses the hospital application through a Web browser. The
Web browser prompts the client to enter information required for a query. The
client submits the request and the client’s browser displays the response from the
hospital application.

In this scenario, the cost of a patient’s hospital visit is paid for by the patient’s
insurance company. The following steps explain how the necessary information
flows through the scenario.
1. To receive payment, the hospital must submit a claim to the insurance
company. To begin the data exchange, a hospital employee enters an account
number for the patient into a form displayed in a Web browser
(HospitalInput.jsp) on the client.
2. The hospital application retrieves information about the patient from a
Document Access Definition Extender (DADX) Web service, and invokes a

© Copyright IBM Corp. 2000, 2003 1


JavaServer Pages (JSP) page to display the results in the Web browser
(HospitalResults.jsp). DADX is explained in more detail later in this chapter.
3. The employee adds additional information about the patient to the page and
returns the information to the hospital application.
4. The hospital application generates an insurance claim from the patient
information, and sends it across the Internet to the insurance Web service for
processing.
5. The insurance Web service processes the claim, and returns a claim response to
the hospital application which invokes another JSP to display the result
(ClaimResponse.jsp) on the client.

The hospital application is implemented with Java™ servlets, JSP, and HTML. The
main function of the hospital application is to provide a user interface to the client.

The patient Web service responds to requests for patient information from the
hospital server. In the sample application, the patient Web service implements a
DADX Web service to query DB2® for patient information. The patient Web service
then returns the results to the hospital application as a SOAP encoded XML
document.

The insurance Web service processes the insurance claim submitted by the hospital
application through a Java bean Web service. The insurance bean performs a DB2
SQL query and returns an XML stream. The XML stream is then transformed using
standard XSL technology into the XML document that is returned to the hospital
application.

From the hospital employee’s perspective, this is a simple, seamless transaction


that takes place in a Web browser on the client. However, this transaction is more
complex. Data is collected from different sources, transformed into a common
format, and exchanged across the Internet between different organizations.

The following sections provide more details about the technologies that underlie
the sample application, how the sample application implements those technologies,
and what tools you will use to develop the sample application.

If you do not wish to complete the scenario but would like to run the application,
follow the steps in the “Preparing for the sample application” section, then import
the scenario into your workbench by selecting File > New > Other > Example
Project > Enterprise Applications > Hospital. Run the scenario by following the
instructions provided when the scenario is installed.

Implementation Details
To exchange data between the hospital Web application, the patient Web service,
and the insurance Web service, the sample application performs four major tasks:
v Retrieves patient information
v Submits the insurance claim
v Processes the claim
v Displays the claim response

These tasks are divided between the hospital application, the patient Web service,
and the insurance Web service as described in the following sections.

2
Retrieving patient information
The hospital application consists of several components, shown in the following
diagram, that are used to retrieve patient information and display it to the hospital
employee on the client.

At run time, the hospital servlet responds to the request to retrieve patient
information. The hospital servlet communicates with the DADX run-time through
the patient proxy. The patient proxy sends information such as the name of the
DADX group, the name of the DADX file, and any parameters required by the
DADX file to the DADX run-time. In this scenario, the patient proxy sends the
group name patientGroup, the file name patient.dadx, and the patient account
number to the run-time environment. The DADX run-time locates the patient
group and DADX file and queries the database. The run-time returns the result to
the patient proxy as an XML document using the SOAP protocol. The hospital
application then displays the result in a Web browser on the client.

Submitting the insurance claim


The hospital application consists of an additional component, shown in the
following diagram, that is used to submit the insurance claim to the insurance Web
service.

Chapter 1. Overview 3
The insurance claim servlet makes a claim request through the insurance proxy to
the InsuranceServiceBean bean. The proxy calls the bean with the input parameters
to make the claim. In this scenario, the patient’s Social Security Number (SSN) is
the input parameter. The SQL to XML run-time code reads the template .xst file,
substitutes the SSN parameter, and then performs the query. The query returns an
XML stream.

Processing the claim


The insurance Web service consists of several components, shown in the diagram
above, that are used to process the claim.

You will create the query template file using the SQL query builder, and the
response.xsl file using the XML mapping editor.

In order to filter unwanted data from the query response, and to generate a result
that conforms to the hospital’s required format for a return, an XSL transformation
style sheet (response.xsl) is applied. The resulting XML document is returned to
the insurance claim servlet.

Displaying the claim response


The hospital application also contains components, shown in the following
diagram, that are used to display the claim response to the hospital employee.

The following section describes how these technologies are implemented in the
sample application.

About Web service standards


The sample application that you will develop is a distributed application in which
the patient information retrieval and claim processing functions are implemented
in Web services located on remote workstations. These functions are accessed by a
hospital application through a method call. The call is sent over the Internet using
SOAP.

A Web service is a set of related application functions that can be programmatically


invoked over the Internet. Web Services Description Language (WSDL) documents
will be indexed in a searchable Universal Description, Discovery, and Integration
(UDDI) Business Registry. The UDDI specification defines open,
platform-independent standards that enable businesses to share information in a
global registry. The UDDI Business Registry is poised to become a vast library of
functions available to all developers. Using the Web services in the Business
Registry, applications can use data and resources that are available on the Web, just
as they now use resources that are available to them locally.

4
WSDL is an XML-based open specification that describes the interfaces to and
instances of Web services on the network. It is extensible, so endpoints can be
described regardless of the message formats or network protocols that are used to
communicate. For more information on WSDL, refer to (www.w3.org/TR/wsdl)

SOAP is a protocol that defines a standard way for distributed applications to


communicate over the Internet. SOAP enables programmers to invoke remote
services in a platform-neutral manner in much the same way that Web browsers
can access Web servers regardless of the platform on which the servers run. The
following diagram illustrates the relationships between SOAP, UDDI, and WSDL.

Together, Web services and SOAP enable businesses to make their services
available to many potential clients using a standard connection protocol. This
makes it possible for related businesses, such as insurance companies and health
care providers, to integrate their business processes over the Internet, making
transactions easier and more efficient.

For more information about SOAP, refer to the (Apache SOAP) site.

For a tutorial that covers only Web services, refer to the Getting Started document
for WebSphere Studio. For more information on Web services, refer to the online
help.

Accessing Web services


To access a remote method in a Web service, a Web service proxy is created. The
proxy provides a Java interface to the Web service. Using the proxy, the application
calls a remote method on the Web service as if the method were a local one. Once
the application makes the remote call, the proxy handles all of the communication
details between the application and the Web service using SOAP.

The proxy sends the remote call to the Web service as a SOAP message. SOAP
messages are essentially XML documents with another layer of abstraction for the
protocol requirements. Encoding data in XML makes it a platform-neutral,
plain-text object that can be sent using HTTP. After the Web service processes the
call, it returns a SOAP response to the calling application with the result.

Chapter 1. Overview 5
About DADX
The DAD Extension (DADX) is an extension of the Document Access Definition
(DAD) file in the DB2 XML Extender and includes standard SQL functionality that
does not use the XML Extender. A DADX document enables the creation of Web
services that store and retrieve XML documents. A DADX document specifies
how to create a Web service using a set of operations that are defined by SQL
statements and, optionally, DAD files.

Accessing DB2 using DADX operations


Web service access to DB2 stored procedures and data is provided through tools
and run-time software. Three kinds of Web service operations are supported:
v XML document-based (query and store XML)
v SQL-based (query, insert, delete, and update)
v DB2 stored procedure invocations

Both XML-based and SQL-based operations are controlled by a DADX file.

The DB2 XML Extender provides the support for the XML-based operations that
store or retrieve XML documents from a DB2 database. An XML document can be
either stored in an XML column, along with its tags, or decomposed into a
collection of rows in tables using traditional relational data types. Similarly, an
XML document can be retrieved from an XML column or can be generated from a
collection of rows in tables. A user-specified file provides control over the mapping
of XML document elements to DB2 database columns for storage and retrieval,
called the Document Access Definition (DAD) file. The XML Extender offers a set
of stored procedures to decompose an XML document into existing table structures
or to generate an XML document from existing relational data. All of these features
of the DB2 XML Extender can be invoked through Web services.

For more information about the DB2 XML Extender see (


www.ibm.com/software/data/db2/extenders/xmlext/library.html) and select the
latest documentation for your platform. Under the Administration section, open
the XML Extender Administration and Programming guide.

The following section describes the tools you will use to develop the sample
application.

Next step
Before you can build the sample application, you need to prepare your
development environment. The next section describes the preparations you need to
make.

6
Chapter 2. Preparing for the sample application
Before you can develop the sample application, you need to perform the following
steps:
v Install the prerequisite software on your workstation
v Create the hospital and insurance databases

The following sections provide details about each of these tasks.

System prerequisites
You need the following software installed on your workstation:

v DB2 Universal Database™ (UDB) for Windows® Version 7.2 or higher installed
locally. DB2 is included with most configurations of the WebSphere Studio
product family. If DB2 was not included in your WebSphere Studio package, you
can download it from www.ibm.com/software/data/db2. The scenario will not
work if fixpack 4 is installed on version 7.2.

v DB2 Universal Database (UDB) for Linux Version 7.2 or higher installed locally
to the default location.
v Netscape version 6.0 or higher or Mozilla version 0.7 or higher

For more information on DB2, refer to www.ibm.com/cgi-


bin/db2www/data/db2/udb/winos2unix/support/v7pubs.d2w/en_main

Enabling JDBC 2.0 on DB2 (Windows only)


Note: The following instructions are applicable for DB2 Universal Database
Version 7.2 and are not intended for use with DB2 Universal Database
Version 8.

JDBC 2.0 allows Java applications to access relational and non-relational database
management systems. The following section only applies to Windows.

To ensure that JDBC 2.0 is enabled on DB2:


1. Stop all DB2 processes.
2. From a command prompt run the usejdbc2 batch file in
DB2_INSTALL_PATH\SQLLIB\java12
where DB2_INSTALL_PATH is the path where you installed DB2.
3. From the Services window, restart the following services:
v DB2 JDBC Applet Server
v DB2 JDBC Applet Server - Control Center
v IBM® WS AdminServer

© Copyright IBM Corp. 2000, 2003 7


Important: If you are denied access when running the usejdbc2 batch file, you
have not stopped all of the DB2 processes.

Creating the hospital and insurance databases


Before you can develop the sample application, you need to create the hospital and
insurance databases. The sample application retrieves patient information from the
patient database and policy holder data from the insurance database.

To create these databases, you will use setup files that are supplied. The files create
the following databases and tables:

Database Tables
HOSPITAL HEALTHCARERECORD
INSURE CLIENTINFO POLICYINFO

To create the databases, do the following:

1. Switch to a Command Prompt window.


2. Go to the following directory:
WS_Installdir\wstools\eclipse\plugins\com.ibm.etools.webservice_version\
samples\hospital\create_databases
where WS_Installdir is the drive and directory where WebSphere Studio is
installed and version is the version number of the plug-in.
3. Type the following command: db2cmd. This command opens the DB2 Command
Line Processor (CLP) window.
4. In the DB2 CLP window, invoke the hospital batch file by typing the following
command: hospital. The batch file uses the hospital.txt file to create the
hospital database. You should see messages indicating that the various DB2
commands in the batch file completed successfully.
5. In the DB2 CLP window, invoke the insurance batch file by typing the
following command: insure. The batch file uses the client.txt and policy.txt files
to create the insurance database. You should see messages saying that the
various DB2 commands in the batch file completed successfully.

In addition to viewing the messages displayed by the batch files, you can use the
DB2 Control Center to check that the databases created successfully.

1. Ensure that you are logged on as user db2inst1.


2. Open a terminal window.
3. Go to the following directory:
WS_Installdir/wstools/eclipse/plugins/com.ibm.etools.webservice_version/
samples/hospital/create_databases
where WS_Installdir is the drive and directory where WebSphere Studio is
installed and version is the version number of the plug-in.
4. Invoke the hospital shell script by typing the following command:
./hospital.sh. You should see messages indicating that the various DB2
commands in the shell script completed successfully.

8
5. Invoke the insurance shell script by typing the following command:
./insure.sh. You should see messages saying that the various DB2 commands
in the shell file completed successfully.

In this project, an SQL script file is used to create the required tables on the
iSeries™. The script file is located in
WS_Installdir/wstools/eclipse/plugins/com.ibm.etools.webservice_version/
samples/hospital/create_databases in the navigator view of the project. To create
the tables and run the example, the driver file that accesses the iSeries database
must be locally available on your workstation. The driver file name is jt400.jar and
is located in the IFS of the iSeries in /QIBM/ProdData/HTTP/Public/lib/jt400.jar. You
can either map a network drive to this location or copy the jt400.jar file to a hard
drive on your workstation.

You must also ensure that the jt400.jar file is referenced in the Class path of the
Server Configuration before you run the sample applications.

To create the tables on the iSeries:


1. Right-click hospital-iseries.sql.
2. Select Run on Database Server... from the popup menu.
3. Click Next in the Run Script window.
4. Select Commit changes only upon success and click Next on the Options
window.
5. Enter the following values in the Database Connection window and click
Finish:
v Database: example
v user ID: Your iSeries user ID
v Password: Your iSeries password
v Database vendor type: DB2 Universal Database for iSeries, V5R1
v JDBC driver: AS/400® Toolbox for Java JDBC Driver
v Host: system_name/example
v Class location: Specify the location of the jt400.jar file referenced earlier
v Accept the defaults for all other fields.
6. Verify that there are no errors in the Confirm export results window and click
Commit changes.

Next step
Once you complete the preparation tasks, you are ready to develop the patient
application.

Chapter 2. Preparing for the sample application 9


10
Chapter 3. Developing the code for the patient Web service
In this section, you will use the XML tools to generate the code required by the
patient application by doing the following:
v Create the Web project that will contain the source files for the patient
application
v Create a DADX group within the Web project
v Create an SQL statement that will query the hospital database for patient
information
v Create a DADX file from the SQL statement
v Create the patient Web service

The patient Web service responds to requests for patient information from the
hospital server. The patient Web service implements a DADX Web service to
query DB2 for patient information. The patient Web service then returns the
results to the hospital application as a SOAP encoded XML document.

Creating the Web project


Before you can develop the patient Web service, you need to create a Web project
that will contain the code for the patient Web service.

The patient Web project contains the patient artifacts such as the DADX group and
the DADX file. To create the Web project, do the following:
1. Switch to the Web perspective (Window > Open Perspective > Other > Web).
2. From the workbench, click File > New > Dynamic Web Project.
3. Type PatientProj in the Project name entry field.
4. Click Finish to create the PatientProj project. The PatientProj and DefaultEAR
projects are created. The Enterprise Application project stores the Web project
as a WAR file embedded in an EAR file that can be exported to a server.

Continue with the next step “Creating the DADX group.”

Creating the DADX group


The DADX group contains connection and other information that is shared
between DADX files. To create the DADX group, do the following:
1. Switch to the Web perspective (Window > Open Perspective > Other > Web) if
necessary.
2. In the Project Navigator view, select PatientProj.
© Copyright IBM Corp. 2000, 2003 11
3. Click File > New > Other > Web Services in order to display the various Web
service wizards. Select the Web Service DADX Group Configuration wizard.
Click Next.
4. Right-click PatientProj. Select Add group. In the DADX group name text field,
type patientGroup. Click OK.
5. Expand PatientProj and right-click patientGroup. Select Group Properties.
Change the DB URL to jdbc:db2:hospital. Click OK.

Enter your iSeries user ID and password. The DB Driver should be


com.ibm.as400.access.AS400JDBCDriver and the DB URL should be
jdbc:as400://server_name/example, where server_name is the name of your
iSeries server.
6. Click Finish. Your DADX group is generated in the
PatientProj\JavaSource\groups.patientGroup folder. If you expand the
PatientProj, Java Resources, and groups.patientGroup folders, your Project
Navigator view should look similar to the diagram below.

Generating the DADX file


DAD Extension (DADX) is an XML document format that specifies how to create a
Web service using a set of operations that are defined by DAD documents and
SQL statements. You can import the DADX file, or create your own by creating an
SQL query and generating a DADX file from the results using the SQL from XML
wizard. The patient.dadx file contains the DB2 query and a description of the
required account parameter.

Important: You can either import this DADX file or you can create it using the
SQL builder and XML from SQL creation wizards.
v To import the DADX file, follow the directions in “Importing the DADX file”,
then skip “Creating the SQL query”, and “Creating the DADX file”.
v To create the DADX file, skip the “Importing the DADX file” section and
following the directions in “Creating the SQL query” and “Creating the DADX
file”.

Importing the DADX file


To import the DADX file, do the following:
1. In the Project Navigator view, select the groups.patientGroup group in the Java
Resources folder of your PatientProj project.
2. Click File > Import to open the Import wizard.
3. Click File system from the Select an import source list, then click Next.

12
4. In the Directory text field, specify the following location of the DADX file. Use
the Browse button if necessary:
WS_Installdir\wstools\eclipse\plugins\com.ibm.etools.webservice_version\
samples\hospital\PatientProj\JavaSource\groups\patientGroup
5. Click OK.
6. Click Select All and select Overwrite existing resources without warning.
7. Click Finish. The patient.dadx file is imported into the PatientProj.

Now that you have imported the DADX file, continue the scenario with Creating
the patient Web service.

Creating the SQL query


To create the SQL query instead of importing it, you need to do the following:
v Define the database connection
v Define the SQL statement
v Test the query
v Generate the template file

The following sections provide details about each of these tasks.

Defining the database connection


Next, you need to define the connection to the hospital database by doing the
following:
1. Select Window > Open Perspective > Other > Data.
2. Right-click anywhere in the DB Servers pane, then click New Connection. The
New Connection wizard opens.
3. In the Connection Name entry field, type Hospital_connection.
4. In the Database entry field, type hospital.

In the Database entry field, type example.


5.

In the User ID and Password fields, type your DB2 user id and password.

In the User ID and Password fields, type your iSeries user ID and password.
6. In the Database vendor type field, ensure that the correct database driver is
selected.
7. In the JDBC driver field, ensure that the correct JDBC driver is selected.
8. In the Class location field, ensure that the path to your to your JDBC driver
class (in db2java.zip) is correct.

In the Class location field, ensure that the path to your JDBC driver class
(jt400.jar) is correct.
9. Click Finish. A connection to the hospital database is defined.

Now that you’ve defined the database connection, you need to copy the connection
information to the PatientProj project, by doing the following:

Chapter 3. Developing the code for the patient Web service 13


1. In the DB Servers pane, expand Hospital_connection and right-click
hopsital(jdbc:db2:hospital), and from the pop-up menu select Import to
Folder.

In the DB Servers pane, expand Hospital_connection and right-click


example(jdbc:as400://server_name), and from the pop-up menu select Import
to Folder.
2. In the Import to Folder dialog, click Browse and select the PatientProj project.
3. Click OK, then click Finish.
4. Click Yes to confirm the creation of the databases folder.

Defining the SQL statement


The SQL statement specifies the tables and fields that you want to query in the
hospital database, and the conditions that will govern the query. To define the SQL
statement, you first give the statement a name by doing the following:
1. Make sure you are in the Data perspective (Window > Open Perspective >
Other > Data).
2. Click the Data Definition tab.
3. Expand the contents of the PatientProj, WebContent folder, WEB-INF folder,
databases folder, and the hospital database until you find the Statements folder.
4. Right-click the Statements folder and select New > Select Statement.
5. In the Statement Name text field, type findPatient, then click OK. This
launches the SQL query builder.

Next, build your query accesses by doing the following:


1. In the Outline view, right-click findPatient, and from the pop-up menu click
Add Table. The Add Table dialog box opens.
2. From the Table name list select EXAMPLE.HEALTHCARERECORD, then click
OK. This specifies that the findPatient SQL statement will query the
HEALTHCARERECORD table.
3. In the Tables pane of the SQL query builder, select all of the columns.
Your screen should resemble this:

14
Now you need to specify which record you need returned. The query will be used
to return the health record for a certain account number.
1. Click the Conditions tab to open the Conditions page, click the first row, then
click the empty cell under the Column heading.
2. Click the drop-down arrow in the cell and select
HEALTHCARERECORD.ACCTNO from the list.
3. Click the first row, then click the empty cell under the Operator heading.
4. Select “=” from the list
5. Click the first row, then click the empty cell under the Value heading.
6. Type :acct then press Enter.
7. Save the query (File > Save). The Specify Variable Values dialog box opens
8. Click the first row, then click the empty cell in the Value field and type 34.
Press Enter, then click Finish.

Testing the query


Now that you have created the query, you should test it to ensure that it returns
the correct result. To test the query, do the following:
1. Select SQL > Execute. The Specify Variable Values dialog box opens.
2. Click the first row, then click the empty cell in the Value field and type 34.
Press Enter, then click Finish.

The result of the query appears in the DB Output pane. If the query was
successful, the Status column will indicate “Success”. The DB Output pane should
look similar to the following:

Chapter 3. Developing the code for the patient Web service 15


Click Close to close the Execute SQL Statement dialog box.

Now that you have created the SQL query, continue the scenario with Creating the
DADX file.

Creating the DADX file


To create the DADX file, do the following:
1. In the Web perspective (Window > Open Perspective > Other > Web), select
File > New > Other > Web services > DADX File. Click Next. The Create
DADX wizard opens.
2. Expand the PatientProj, WebContent, WEB-INF, databases, hospital and
Statements folders and select the findPatient statement, then click Next.
3. Click Next to bypass the Select DAD Files page.
4. In the DADX Generation page, type patient.dadx in the File name field.
5. Select /PatientProj/JavaSource/groups/patientGroup as the output folder.
6. Click Finish.

The DADX file opens in the XML editor. Examine the file then close the editor.

Now that you have generated the DADX file, continue the scenario with “Creating
the patient Web service”.

Creating the patient Web service


The patient information query is implemented using a DADX Web service. The
patient Web service enables the hospital application to retrieve information about a
patient from the patient database using a DB2 query. The results are returned to
the Hospital server as a SOAP-encoded XML document. The hospital application
invokes a JSP file to display the patient record.

You need to create a server and add the DB2 driver (db2java.zip) from the java12
directory to the ws.ext.dirs server path before you run the Web service wizard. See
the “Application testing and publishing” help topic for instructions for creating a
server and adding drivers to your server path.

To create the patient Web service from the patient.dadx file, do the following:
1. Switch to the Web perspective (Window > Open Perspective > Other > Web)
if necessary.
2. In the Project Navigator view, expand the PatientProj project, Java Resources
folder, and groups.patientGroup folder and select the patient.dadx file.
3. Click File > New > Other > Web Services. Select Web Service and click
Next to start the Web service wizard.

16
4. In the Web Services page of the wizard, ensure that DADX Web service is
selected from the Web service type menu. Ensure the Start Web service in
Web project, Generate a proxy and Test the generated proxy check boxes
are selected. Click Next.
5. In the Service Deployment Configuration page, ensure that the proper server
enviroment is selected. Use the Edit button to change the server environment,
if necessary. Click Next.
6. In the Web Service DADX File Selection page, ensure that
/PatientProj/JavaSource/groups/patientGroup/patient.dadx, is specified. Click
Next.
7. The Web Service DADX Group properties page of the wizard is used to
update your group properties.
a. Ensure the DB URL field displays jdbc:db2:hospital.

Ensure the DB URL field displays jdbc:as400://server_name/example,


where server_name is the name of your iSeries server.
b.

Enter your DB2 user ID and password.

Enter your iSeries user ID and password.


c. Click Next. If a Web services warning dialog regarding overwriting files
opens, click Yes to all.
8. In the Web Service Binding Proxy Generation page, click the Show mappings
check box. The client proxy provides a remote procedure call interface to your
Web service. Click Next to accept the default values.
9. In the Web Service XML to Java Mappings page of the wizard, select
http://tempuri.org/PatientProj/patientGroup/patient.dadx/
XSD:findPatientResult
then click Next.
10. In the Web Service SOAP Binding Mapping Configuration page, review the
SOAP binding mapping configurations. Click Next to accept the default
values.
11. In the Web Service Test page, ensure that the Test the generated proxy check
box is selected and that Web service sample JSPs appears in the Test facility
text field. Click Finish.

It may take a few minutes for the Web service to be generated. The Web service is
deployed to the WebSphere Application Server and an internal Web browser is
launched to demonstrate the sample application.

The Web service will be deployed using the WebSphere Application Server unit
test environment. The Server perspective automatically opens and a Server project
is created in the Navigator view. The WebSphere Test Environment starts. Now
that you have created the insurance Web service, test the method of the patient
DADX Web service, findPatient.

Chapter 3. Developing the code for the patient Web service 17


Testing the patient Web service
The sample Web application demonstrates how to code the proxy.

If it is necessary to launch the Web browser, follow these steps:


1. Ensure that you are in the Server perspective (Window > Open Perspective >
Other > Server).
2. Launch the Web Browser (click the Open Web Browser icon ) if necessary
and type the following address:
http://localhost:port/PatientProjClient/sample/patient/TestClient.jsp
where port is the port number of your test environment.

If the pages appear broken, click the refresh icon on the Web Browser.

To examine the methods of the sample Web application:


1. Click findPatient_(int) in the Methods pane.
2. In the acct field of the Inputs pane, type 34 or 35 and click Invoke. The Result
pane displays the patient record.

When you have finished examining the findPatient method of the sample Web
application, exit the Web browser.

Any changes you make to your Web service can be retested by returning to the
Web browser. When running a test environment, the server is running against the
resources that are in the workbench. The server will pick up any changes you
make to the Web project without being restarted. When you have finished testing,
close the Web browser.

Next step
Now that you’ve developed the code for the patient application, you can create
and deploy the insurance Web service.

18
Chapter 4. Developing the code for the insurance Web service
In this section, you will use the XML tools in WebSphere Studio to generate the
code required by the insurance Web service by doing the following steps:
v Create the project that will contain the source files for the insurance Web service.
v Use the SQL query builder to generate the SQL query that retrieves policy
holder information from the database in the insurance Web service and generate
the template file.
v Use the XML to XML mapping editor to generate the XSL transformation style
sheet that the insurance Web service uses to filter out unwanted data from the
health policy information retrieved from the insurance database.
v Create the insurance Web service.

The insurance Web service processes the insurance claim submitted by the hospital
application through a Java bean Web service. The insurance bean performs a DB2
SQL query and returns an XML stream. The XML stream is then transformed,
using standard XSL technology, into the XML document that is returned to the
hospital application.

Creating the Web project


Before you can create the insurance Web service, you need to set up the project
that will contain the code for the Web service. You need to add the Xalan and
Xerces JAR files to the project’s library because the insurance bean uses DOM tree
code from xerces.jar and XSL transformation code from xalan.jar. You do not need
to import these JAR files into the project because the server, to which the Web
service is deployed, has a copy of the Xalan and Xerces JAR files.

A Web project contains all of the resources required for the insurance Web service,
such as the InsuranceServiceBean bean, the JSP files, the WSDL documents, and
the deployment descriptors. The Web service uses servlet technology which runs
only in a Web project. To create the Web project for the insurance company, do
the following:
1. Switch to the Web Perspective (Window > Open Perspective > Other > Web).
2. On the main menu bar, click File > New > Dynamic Web Project.
3. In the Project name entry field, type InsuranceProj. Click Finish.
4. Right-click the project to open the pop-up menu for the InsuranceProj and
select Properties.
5. In the Properties window, select Java Build Path under the Libraries tab.
6. Click Add Variable. Press and hold the Ctrl key and select XERCES_API_JAR,
and SOAPJAR. Click OK to close the dialog.
7. Click OK.

Importing the JAR file


The sqltoxml.jar file contains the SQL to XML code required by the insurance bean.
The sqltoxml.jar file takes an SQL statement as input and generates an XML
document based on the results of the SQL statement.

Import the JAR file by doing the following:

© Copyright IBM Corp. 2000, 2003 19


1. In the Project Navigator, expand InsuranceProj and select the
WebContent/WEB-INF/lib folder.
2. From the workbench, click File > Import. The Import wizard opens.
3. In the wizard, select File system from the Select an import source list, then
click Next.
4. Click the Browse button, and browse to:
WS_Installdir\wstools\eclipse\plugins\com.ibm.etools.sqltoxml_version\jars.
Click OK.
5. If necessary, click the jars folder to display the files, without selecting the check
box. Select the sqltoxml.jar file check box.
6. In the Folder text field, ensure that the following is specified:
InsuranceProj/WebContent/WEB-INF/lib

1. Click Finish. The JAR file is imported into the InsuranceProj project.

If you want to see the imported file, select the Project Navigator view and expand
the lib folder.

Generating the source code for the database query


The insurance service bean is implemented by using SQL-to-XML code to perform
a DB2 query. The XML output from the SQL-to-XML code is transformed using
standard XSL transformation technology.

Important: You can either import the SQL query and XSL file into the insurance
Web project or you can create the SQL query and XSL file using the SQL query
builder and the XML to XML mapping editor:
v To import the source files, follow the directions in “Importing the source files”
below, then skip the directions in “Importing the DTD file and insurance bean”,
“Creating the SQL query”, and “Generating the XSL file”.
v Alternatively, to generate the source files, skip the “Importing the source files”
section and follow the directions in “Importing the DTD file and insurance
bean”, “Creating the SQL query,” and “Generating the XSL file”.

The code that you import or generate is required in order to query the insurance
database and return the health policy information.

20
Importing the source files
The source code for the insurance Web service is provided for you. To import the
source files:
1. Switch to the Web Perspective (Window > Open Perspective > Other > Web) if
necessary.
2. In the Project Navigator select the InsuranceProj folder.
3. Click File > Import to open the Import wizard.
4. Click File system to import the resources from the local file system. Click Next.
5. To enter the directory, click Browse to locate and select:
WS_Installdir\wstools\eclipse\plugins\com.ibm.etools.webservice_version\samples\
hospital\InsuranceProj
6. Click OK.
7. Click Select All to import the source files and folders.
8. In the Folder text field, ensure that the InsuranceProj folder is specified, then
click Finish to import the folders and files, and close the wizard.

Now that you have imported the SQL query and XSL file, continue the scenario
with Creating the insurance Web service.

Importing the DTD file and insurance bean


A DTD and insurance bean have been provided to simplify the scenario. After
you import the file and bean, you can double-click them to look at the source if
you want to see how they were written. Both of these files are required later in the
scenario. To import the files, do the following:
1. Switch to the Web Perspective (Window > Open Perspective > Other > Web)
if necessary.
2. In the Project Navigator view, under InsuranceProj, select the Java Resources
folder.
3. Click File > Import to open the Import wizard.
4. Click File system to import the resources from the local file system. Click
Next.
5. To enter the directory, click Browse to locate and select
WS_Installdir\wstools\eclipse\plugins\com.ibm.etools.webservice_version\
samples\hospital\InsuranceProj\JavaSource
Click OK.
6. In the Import wizard, select the check box beside the JavaSource folder.
7. Expand the JavaSource folder and click the query_info folder. The query_info
folder contains the DTD file that you will use later in the scenario.
8. Clear the checkboxes beside all files except the Response.dtd file.
9. Ensure that the com folder is selected. The com folder contains the bean
required for a Web service that you will create later in the scenario.
10. In the Folder text field, ensure that the following path is specified:
InsuranceProj/JavaSource
11. Ensure that the Create complete folder structure radio button is not selected.
12. Click Finish to import the folders and files and close the wizard.

Now that you have imported the bean, continue the scenario with “Creating the
SQL query”.

Chapter 4. Developing the code for the insurance Web service 21


Creating the SQL query
The insurance database (INSURE) contains two tables: CLIENTINFO which
contains information about the clients, and POLICYINFO which contains
information about the policies. You will create an SQL SELECT statement that uses
a social security number (SSN) to query the tables in the database. You use the
SQL query builder tool to define the query.

To create the SQL query, you need to do the following:


v Define the database connection
v Define the SQL statement
v Test the query
v Generate the template file

The following sections provide details about each of these tasks.

Defining the database connection


Define the connection to the insurance database by doing the following:
1. Select Window > Open Perspective > Other > Data.
2. Right-click anywhere in the DB Servers pane, then click New Connection. The
New Connection wizard opens.
3. In the Connection Name entry field, type Insurance_connection.
4. In the Database entry field, type insure.

In the Database entry field, type example.


5.

In the User ID and Password fields, type your DB2 user ID and password.
6. In the Database vendor type field, ensure that the correct database driver is
selected.
7. In the JDBC driver field, ensure that the correct JDBC driver is selected.
8. In the Class location field, ensure that the path to your to your JDBC driver
class (in db2java.zip) is correct.

In the Class location field, ensure that the path to your JDBC driver class
(jt400.jar) is correct.
9. Click Finish. A connection to the insurance database (INSURE) is defined.

Now that you have defined the database connection, you need to copy the
connection information to the workspace by doing the following steps:
1. In the DB Servers pane, expand Insurance_connection and right-click
insure(jdbc:db2:insure). From the pop-up menu select Import to Folder. The
Import to Folder dialog opens.

In the DB Servers pane, expand Insurance_connection and right-click


example(jdbc:as400://server_name). The Import to Folder dialog opens.
2. Click Browse and select the InsuranceProj folder.
3. Click OK, then click Finish.
4. Click Yes to confirm the creation of the databases folder.

22
Defining the SQL statement
The SQL statement specifies the tables and fields that are queried in the insurance
database, and the conditions that govern the query. To define the SQL statement,
you first give the statement a name:
1. Make sure you are in the Data perspective (Window > Open Perspective >
Other > Data)
2. Click the Data Definition tab.
3. Expand the contents of the InsuranceProj project, Web Content folder,
WEB-INF folder, databases folder and the insure database until you find the
Statements folder.
4. Right-click the Statements folder and select New > Select Statement.
5. In the Statement Name text field, type FindHealthPolicy, then click OK. This
launches the SQL query builder.

Note: Ensure that you specify the correct case when typing FindHealthPolicy.
For example, if you type findHealthPolicy instead of FindHealthPolicy
with an upper case F, the application will fail.

Next, specify the tables that the query accesses:


1. In the Outline view, right-click FindHealthPolicy, and from the pop-up menu
click Add Table. The Add Table dialog box opens.
2. From the Table name list select EXAMPLE.POLICYINFO, then click OK. This
specifies that the FindHealthPolicy SQL statement will query the POLICYINFO
table.
3. In the Outline pane, right-click FindHealthPolicy, and from the pop-up menu
click Add Table. The Add Table dialog box opens.
4. In the Table name list select EXAMPLE.CLIENTINFO, then click OK. This
specifies that the FindHealthPolicy SQL statement will also query the
CLIENTINFO table.
The Tables pane (the pane that contains a graphical representation of the
database tables) of the SQL query builder should look like this:

You can resize the Tables pane by hovering over the bottom corner of the pane
with your mouse until the cursor turns into an arrow. Click and drag to resize.

Now you need to specify that the query combines information from both the
POLICYINFO and CLIENTINFO tables for a given account number by doing the
following:

Chapter 4. Developing the code for the insurance Web service 23


1. In the Graph pane, click and hold the mouse button on ACCTNO from the
POLICYINFO table.
2. Drag the mouse pointer to the ACCTNO in the CLIENTINFO table. Ensure
that the check box next to ACCTNO remains clear.

Finally, specify that the SQL query should retrieve health policy information for the
given account number by doing the following:
1. In the Graph pane, select all of the fields in the POLICYINFO table by clicking
each check box next to each field.
2. Using the same method, select the following fields in the CLIENTINFO table:
v SSN
v ADDRLINE
v CITY
v STATE
v COUNTRY
3. In the Conditions page (click the Conditions tab to open this page), select the
first row, then click the empty field below the Column heading. The field
displays a down arrow on the right side.
4. Click the down arrow, and from the pop-up list click CLIENTINFO.SSN.
5. Click the empty field below the Operator heading, then click the down arrow.
6. From the pop-up list, select =.
7. Click the empty field below the Value heading, type :SSN and press Enter.
Make sure that you included the colon with this string. SSN is a variable that
will contain at run-time the social security number for the query.
8. Click the empty field below the AND/OR heading, then click the down arrow.
9. From the pop-up list, select AND.
10. Select the next empty row. Click the field below the Column heading, then
click the down arrow.
11. From the pop-up list, click POLICYINFO.POLICYTYPE.
12. Click the next empty field below the Operator heading, then click the down
arrow.
13. From the pop-up list, select =.
14. Click the next empty field below the Value heading, type ’health’ and press
Enter. Make sure that you included the single quotes in this string. This value
specifies that the query retrieves health policy information for the given social
security number.

Your query should resemble the following screen:

24
Testing the query
Now that you have created the query, you should test it to ensure that it returns
the correct result. To test the query, do the following:
1. Select SQL > Execute.
2. Click Execute in the Execute SQL Statement dialog. The Specify Variable Values
dialog box opens.
3. In the Value field, replace NULL with the text ’123-45-6789’. Include the single
quotation marks. Press Enter, then click Finish.

If the query is successful, the result in the DB Output pane looks like this:

Save the query (File > Save).

When you save the query, the Specify Variable Values dialog box will open. In the
Value field, replace NULL with the text ’123-45-6789’. Include the single quotation
marks. Press Enter, then click Finish to save the query.

Generating the template file


The template file contains the SQL statement and other configuration information
related to the query. The insurance Web service uses this file to execute the query.
You need to save the SQL statement in this file by doing the following:
1. In the Outline view, right-click FindHealthPolicy, and from the pop-up menu
click Generate new XML. The XML from SQL wizard opens.

Chapter 4. Developing the code for the insurance Web service 25


2. In the wizard, accept the default values and ensure that Generate query
template file is selected.
3. Ensure that the Template file entry field contains: FindHealthPolicy.xst.
4. In the Output folder entry field, specify the following directory:
/InsuranceProj/JavaSource/query_info

then click OK.


5. Click Finish. The Specify Variable Values dialog box opens.
6. Click the first row, then click the Value field. Replace the NULL value with
’123-45-6789’. Include the single quotation marks. Press Enter, then click
Finish.
7. Switch to the Navigator view to view the template file FindHealthPolicy.xst.
Close the SQL query builder.

Now that you have created the SQL query, continue with “Generating the XSL
file”.

Generating the XSL file


To create the response XML document that the insurance Web service returns to
the hospital application, the insurance Web service must transform the health
policy information into the claim response by filtering out unwanted data. The
insurance Web service performs this transformation using an XSL transformation
style sheet (response.xsl). You generate the style sheet using the XML to XML
mapping editor.

The XML to XML mapping editor generates the style sheet based on the mapping
between a source and a target XML document. Mapping identifies what elements
in the source XML document will appear in the target XML document. The source
XSD for the health policy information is FindHealthPolicy.xsd, and the target DTD
that defines the claim response is Response.dtd. Response.dtd is already created for
you and you imported it in a previous step. You will create the
FindHealthPolicy.dtd. You will use the XML mapping editor to map the source and
target elements before generating the style sheet.

First, you need to open the source and target XML files by doing the following:
1. Switch to the XML perspective (Window > Open Perspective > Other >
XML).
2. In the Navigator view, expand the InsuranceProj, JavaSource, and query_info
folders.
3. In the query_info folder right-click FindHealthPolicy.xsd. Click Generate >
DTD.
4. Accept the default values and click Finish. FindHealthPolicy.dtd is generated
into the query_info folder.
5. Select the query_info folder. From the workbench, click File > New > XML >
XML to XML Mapping and click Next. The XML to XML Mapping dialog box
opens.
6. In the Folder text field, ensure the following is specified: InsuranceProj/
JavaSource/query_info.
The File name field specifies the mapping session name. Leave the default as
is, and click Next. The New XML to XML Mapping wizard opens.
7. Expand the InsuranceProj, JavaSource and query_info folders and select
FindHealthPolicy.dtd.

26
8. Click > to add the file to the Selected Files pane.
9. Click Next. The Specify Target XML, DTD, or XSD File dialog box opens.
10. Expand the InsuranceProj, JavaSource, and query_info folders and select
Response.dtd.
11. Click Next. The Root Element dialog box opens.
12. In the Target root element field, ensure that response is specified.
13. In the Source root elements field, ensure that SQLResult is specified.
14. Click Finish. This launches the XML to XML mapping editor. The source DTD
and target DTDs appear in the center pane of the workbench, and when
expanded look similar to the following diagram:

The next step is to map the source and target elements by doing the following:
1. Expand the element in the Source and Target panes.
2. Select POLICYNUM in both the Source and Target panes, then right-click on
the Target pane and select Create Mapping. The mapping specifies that the
POLICYNUM element in the health policy information will also appear in the
claim response. Notice that the Overview pane is updated to show the
mapping between the source and target elements.

You can also create a mapping by selecting POLICYNUM in the Source pane
and dragging the mouse pointer to POLICYNUM in the Target pane.
3. Follow the same procedure as in step 2 to map the following elements in the
source DTD file to the equivalent target DTD:
v SSN
v ACCTNO
v COVERAGEAMOUNT
v ADDRLINE
v CITY
v STATE
v COUNTRY

The elements in the source file that were not mapped to any elements in the
target DTD will not appear in the claim response that is returned to the
hospital application.

The Overview pane should resemble the following screen:

Chapter 4. Developing the code for the insurance Web service 27


Now that you have mapped the elements, you can generate the transformation
style sheet by doing the following:
1. Select Mapping > Generate XSLT Script. The Generate XSLT Script wizard
opens.
2. Select the InsuranceProj/JavaSource/query_info folder.
3. Click Finish. The style sheet is generated, and opens in the XML editor for
your review.
4. Close the file when you have completed the review.

Save the mapping session by selecting File > Save, then close the file.

Now that you have generated the XSL transformation file, continue the scenario
with “Creating the insurance Web service”.

Creating the insurance Web service


The insurance Web service enables the hospital application to generate an
insurance claim based on the results of the patient information. The insurance Web
service processes the claim, and returns a claim response to the hospital
application that invokes a JSP to display the results of the claim.

To create the insurance Web service, do the following:


1. Switch to the Web Perspective (Window > Open Perspective > Other > Web)
if necessary.
2. In the Project Navigator, expand the InsuranceProj folder, Java Resources
folder, com.ibm.b2b.examples.insurance package, and select the
InsuranceServiceBean.java file.
3. Click File > New > Other > Web services. Click Web Service and click Next
to start the Web service wizard.
4. In the Web Services page of the wizard, ensure that the Java bean Web
service is selected as the the Web service type, then ensure the Start Web
service in Web project and Generate a proxy and Test the generated proxy
check boxes are selected. Ensure that the the Overwrite files without
warning check box is selected. Click Next.
5. In the Server-Side Deployment Selection section of the Service Deployment
Configuration page, click Edit, and select IBM SOAP as the Web service run
time. Also, ensure that the proper server is selected. Click OK. In the
Client-Side Enviroment Selection section of the Service Deployment
Configuration page, ensure that IBM SOAP is the Web service run time and
that the proper server is selected. Click Next.
6. In the Web Service Java Bean Selection page ensure that the
InsuranceServiceBean is selected. Click Next.

28
7. The Web Service Java Bean Identity page of the wizard specifies your Web
service URI, scope, and the names of the generated files. Click Next to accept
the default values.
8. The Web Service Java Bean Methods page of the wizard displays a summary
of methods in your bean. The InsuranceServiceBean bean has one method that
is selected by default. You can specify input encoding and output encoding
styles. Ensure that SOAP encoding for the Input encoding is selected and
Literal XML encoding for the Output encoding is selected.
9. Select the Show server (Java to XML) type mappings check box, then click
Next.
10. In the Web Service Java to XML Mappings page, review your Web service
type mappings. Click Next to accept the default values.
11. In the Web Service Binding Proxy Generation page, review the bindings that
you will use to generate a Web service proxy. The client proxy provides a
remote procedure call interface to your Web service. The folder of the Java
client proxy defaults to /InsuranceProjClient/JavaSource. The name of the
fully qualified Java class defaults to proxy.soap.InsuranceServiceBeanProxy.
Click the Show mappings check box, then click Next.
12. In the Web Service XML to Java Mappings page, review your Web service
client type mappings then click Next to accept the default values.
13. In the Web Service SOAP Binding Mapping Config page, click Next to accept
the default values.
14. In the Web service Test page, ensure that Test the Generated Proxy is checked
and Web service sample JSPs are selected. Click Finish to accept the
remaining default values and to open the Web browser. The sample Web
application demonstrates how to code a JSP in terms of the proxy file.

It may take a few minutes for the Web service to be generated. The Web service is
deployed to the WebSphere Application Server and an internal Web browser is
launched to demonstrate the sample application.

The Web service will be deployed using the WebSphere Application Server unit
test environment. The Server perspective automatically opens and a Server project
is created in the Navigator view. The WebSphere Test Environment starts. Now
that you have created the insurance Web service, test the method of the
InsuranceServiceBean.

Testing the insurance Web service


The sample Web application demonstrates how to code the proxy.

If it is necessary to launch the Web browser, follow these steps:


1. Ensure that you are in the Server perspective (Perspective > Open > Other >
Server).
2. Launch the Web Browser (click the Open Web Browser icon ) and type the
following address:
http://localhost:port/InsuranceProjClient/sample
/InsuranceServiceBean/TestClient.jsp
where port is the port number of your test environment.

To examine the methods of the sample Web application:


1. Click processClaim in the Methods pane.

Chapter 4. Developing the code for the insurance Web service 29


2. In the ssn field of the Inputs pane, type 123-45-6789 and click Invoke. The
Result pane displays the patient record as an XML document.

Your browser should look similar to the following:

When you have finished examining the processClaim method of the sample Web
application, exit the Web browser.

Any changes you make to your Web service can be retested by returning to the
Web browser. When running a test environment, the server is running against the
resources that are in the workbench. Any changes you make to the Web project are
picked up without being restarted. When you have finished testing close the Web
browser.

Next step
Now that you have developed the code for the insurance Web service, you can do
the same for the hospital Web service.

30
Chapter 5. Creating and deploying the hospital application
In this section, you will import the source files for the hospital application by
doing the following:
v Create the Web project that will contain the source files for the hospital
application
v Import the Java beans, JAR files, JSP files, and HTML files for the hospital
application.

The hospital application is implemented with Java servlets, JSP files, and HTML
files. The main function of the hospital application is to provide a user interface
to the client.

Creating the project


You should have already set up the development environment for the insurance
and patient Web services. If not, refer to the instructions for setting up the Web
services.

Before you can create the hospital application, you need to set up the project that
will contain the code for the application. All of the files for the hospital application
have been provided for you. The code is used to provide a user interface to the
client and includes beans, JAR files, JSP files, and HTML files for the hospital
application.

To create the Web project, do the following:


1. Switch to the Web Perspective (Window > Open Perspective > Other > Web) if
necessary.
2. From the workbench, click File > New > Dynamic Web Project.
3. Type HospitalProj in the Project name entry field. Click Finish.
4. In the Repair Server Configuration dialog, click OK to add HospitalProj to the
DefaultEAR project.
5. Right-click the project and select Properties.
6. Select the Java Build Path page and click the Libraries tab.
7. Click Add Variable to add the following JAR files (hold down the Ctrl key to
select multiple files):
SOAPJAR
XERCES_API_JAR
8. Click OK.
9. Click OK to close the Properties dialog.

Importing the XSD JAR files


The hospital client code receives XML data from both the patient Web service and
the insurance Web service. The Web services wizard will create Java code to
programmatically extract the data from the XML data streams. The generated
code requires the XSD JAR files.

To import the XSD JAR files, do the following:

© Copyright IBM Corp. 2000, 2003 31


1. In the Project Navigator view, select the HospitalProj\WebContent\WEB-
INF\lib folder.
2. From the workbench, click File > Import. The Import wizard opens.
3. In the wizard, select File system from the Select an import source list, then
click Next.
4. In the Directory text field, specify the following location of the source code.
Use the Browse button if necessary:
WS_Installdir\wstools\eclipse\plugins\com.ibm.etools.xsdmodel_version\jars
5. Click OK.
6. Select the xsdbeans.jar file.
7. In the Folder text field, ensure the following is specified:
HospitalProj/WebContent/WEB-INF/lib. If the correct folder is not specified,
use the Browse button to specify the folder.
8. Click Finish. The source code is imported into the HospitalProj project.
9. Repeat steps 2 through 5, to select WS_Installdir\wstools\eclipse\plugins\
com.ibm.etools.xsd.bean_version\runtime
10. Select xsd.bean.runtime.jar.
11. Click Finish. The source code is imported into the HospitalProj project.

Once you have imported the XSD JAR files, you will import the client code.

Importing the client code


In order for the hospital to receive payment for a patient’s visit, the hospital must
submit a claim to the insurance company. The hospital application first retrieves
information about a patient from the patient database, invoking a JSP file to
display the patient record. Additional information about the patient is entered on
the page, returned to the patient database, and sent as a claim to the insurance
Web service for processing. The insurance Web service processes the claim, and
returns a claim response to the hospital application invoking another JSP to display
the results of the claim.

The source code for the hospital client application is provided. You need to import
the source code into HospitalProj by doing the following:
1. In the Project Navigator view, select the HospitalProj folder.
2. From the workbench, click File > Import. The Import wizard opens.
3. In the wizard, select File system from the Select import source list, then click
Next.
4. In the Directory text field, specify the following location of the source code.
Use the Browse button if necessary.
WS_Installdir\wstools\eclipse\plugins\com.ibm.etools.webservice_version\samples\
hospital\HospitalProj
5. Click OK.
6. Click Select All and select Overwrite existing resources without warning.
7. In the Folder text field, ensure HospitalProj is specified. If the correct folder is
not specified, use the Browse button to specify the project.
8. Click Finish. The source code is imported into the HospitalProj project.

Note: In the Tasks view, you can safely ignore any errors or warnings that describe
broken links in the HospitalProj project.

32
Copy the proxies from the PatientProjClient and InsuranceProjClient
projects.
In a real world example, you would run the Web Services Client Wizard on the
WSDL for each of the Web services to generate the proxies. To simplify, you will
copy the proxies from the PatientProjClient and InsuranceProjClient projects to the
HospitalProj project.

To copy the proxy from the PatientProjClient project:


1. Switch to the Resource perspective (Window > Open Perspective > Other >
Resource)
2. In the Navigator view, expand the PatientProjClient project and Java Resources
folders.
3. Select both org.tempuri.patientproj.patientgroup.patient.dadx.xsd and
proxy.soap folders.
4. Right-click and click Copy from the pop-up menu.
5. Expand the HospitalProj project.
6. Right-click the Java Resources folder and click Paste from the pop-up menu.
7. When asked if you want to overwrite the existing file, click Yes to all.

To copy the proxy from the InsuranceProjClient project:


1. In the Navigator view, expand the InsuranceProjClient project and Java
Resources folders.
2. Right-click the proxy.soap folder and click Copy from the pop-up menu.
3. Expand the HospitalProj project.
4. Right-click the Java Resources folder and click Paste from the pop-up menu.
5. When asked if you want to overwrite the existing file, click Yes to all.

Next step
Everything is now ready for you to test the hospital application sample application
using your Web browser.

Chapter 5. Creating and deploying the hospital application 33


34
Chapter 6. Running the hospital sample application and
testing the Web service
You run the sample application the same way a hospital employee would from
your Web browser. You start by entering a patient account number in the Patient
claim entry pane. You then enter additional patient information into the Patient
claim history pane. The Claim results pane displays the results. The following
sections take you through these steps.

Submitting the claim


To start or restart WebSphere Test Environment:
1. In the Servers perspective (Window > Open Perspective > Server) , click the
Servers tab at the bottom of the Servers view.
2. If the server is not started, right-click the server instance and select Start. If the
server is started, right-click the server instance and select Restart.
3. If the Server Selection dialog opens, click Advanced. Click Finish to close the
Server Selection dialog.

To get to the first page of the user interface, do the following:


1. Right-click the HospitalProj/WebContent/index.html file and select Run on
server.
2. Select the server, then click Finish. The following Web page is displayed:

3. In the Account number entry field of the Patient claim entry pane, type one of
the following account numbers: 34 or 35.
4. Click Submit. If you typed account number 34, the hospital application returns
the following Patient claim history page with the patient information:

© Copyright IBM Corp. 2000, 2003 35


5. Fill in the following fields in the Claim result page:
Visit description:
Name of doctor seen:
Visit cost:
6. Click Submit. The claim is sent to the insurance application for processing.

Viewing the claim response


The claim response that the insurance application returns consists of two parts, as
shown in the following illustration:

36
The response includes information from different sources:
v The claim amount that was entered by the hospital employee and then
submitted to the insurance application for processing
v Patient information, including the address, policy number, and coverage
information that was retrieved from the insurance database by the insurance
application

All of this information is merged by the insurance application to produce the claim
response.

Summary
Now that you have successfully run the sample application, you have completed
developing the scenario. You have gone through the process of developing an XML
application, from initial preparation, through code development, to testing. You
used the XML and Web service tools to generate the code required by the sample
application, including generated Java classes, the XSL transformation style sheet,
and the SQL query. The final step in this process would be to deploy each Web
service on their respective Web application servers, such as WebSphere Application
Server.

Chapter 6. Running the hospital sample application and testing the Web service 37
38
Notices
Note to U.S. Government Users Restricted Rights - Use, duplication or disclosure
restricted by GSA ADP Schedule Contract with IBM Corp.

This information was developed for products and services offered in the U.S.A.
IBM may not offer the products, services, or features discussed in this document in
other countries. Consult your local IBM representative for information on the
products and services currently available in your area. Any reference to an IBM
product, program, or service is not intended to state or imply that only that IBM
product, program, or service may be used. Any functionally equivalent product,
program, or service that does not infringe any IBM intellectual property right may
be used instead. However, it is the user’s responsibility to evaluate and verify the
operation of any non-IBM product, program, or service.

IBM may have patents or pending patent applications covering subject matter
described in this document. The furnishing of this document does not give you
any license to these patents. You can send license inquiries, in writing, to:

IBM Director of Licensing


IBM Corporation
North Castle Drive
Armonk, NY 10504-1785
U.S.A.

For license inquiries regarding double-byte (DBCS) information, contact the IBM
Intellectual Property Department in your country or send inquiries, in writing, to:

IBM World Trade Asia Corporation


Licensing
2-31 Roppongi 3-chome, Minato-ku
Tokyo 106, Japan

IBM may use or distribute any of the information you supply in any way it
believes appropriate without incurring any obligation to you.

The following paragraph does not apply to the United Kingdom or any other
country where such provisions are inconsistent with local law:
INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS
PUBLICATION “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OR CONDITIONS OF NON-INFRINGEMENT,
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states
do not allow disclaimer of express or implied warranties in certain transactions,
therefore, this statement may not apply to you.

This information could include technical inaccuracies or typographical errors.


Changes are periodically made to the information herein; these changes will be
incorporated in new editions of the publication. IBM may make improvements
and/or changes in the product(s) and/or the program(s) described in this
publication at any time without notice.

© Copyright IBM Corp. 2000, 2003 39


Licensees of this program who wish to have information about it for the purpose
of enabling: (i) the exchange of information between independently created
programs and other programs (including this one) and (ii) the mutual use of the
information which has been exchanged, should contact:

Lab Director
IBM Canada Ltd. Laboratory
8200 Warden Avenue
Markham, Ontario, Canada L6G 1C7

Such information may be available, subject to appropriate terms and conditions,


including in some cases, payment of a fee.

The licensed program described in this document and all licensed material
available for it are provided by IBM under terms of the IBM Customer Agreement,
IBM International Program License Agreement or any equivalent agreement
between us.

Information concerning non-IBM products was obtained from the suppliers of


those products, their published announcements or other publicly available sources.
IBM has not tested those products and cannot confirm the accuracy of
performance, compatibility or any other claims related to non-IBM products.
Questions on the capabilities of non-IBM products should be addressed to the
suppliers of those products.

Any references in this information to non-IBM Web sites are provided for
convenience only and do not in any manner serve as an endorsement of those Web
sites. The materials at those Web sites are not part of the materials for this IBM
product and use of those Web sites is at your own risk.

This information contains examples of data and reports used in daily business
operations. To illustrate them as completely as possible, the examples may include
the names of individuals, companies, brands, and products. All of these names are
fictitious and any similarity to the names and addresses used by an actual business
enterprise is entirely coincidental.

COPYRIGHT LICENSE:

This information contains sample application programs in source language, which


illustrates programming techniques on various operating platforms. You may copy,
modify, and distribute these sample programs in any form without payment to
IBM, for the purposes of developing, using, marketing or distributing application
programs conforming to the application programming interface for the operating
platform for which the sample programs are written. These examples have not
been thoroughly tested under all conditions. IBM, therefore, cannot guarantee or
imply reliability, serviceability, or function of these programs. You may copy,
modify, and distribute these sample programs in any form without payment to
IBM for the purposes of developing, using, marketing, or distributing application
programs conforming to IBM’s application programming interfaces.

Each copy or any portion of these sample programs or any derivative work, must
include a copyright notice as follows:

(C) (your company name) (year). Portions of this code are derived from IBM Corp.
Sample Programs. (C) Copyright IBM Corp. 2000, 2003. All rights reserved.

40
Programming interface information
Programming interface information is intended to help you create application
software using this program.

General-use programming interfaces allow you to write application software that


obtain the services of this program’s tools.

However, this information may also contain diagnosis, modification, and tuning
information. Diagnosis, modification and tuning information is provided to help
you debug your application software.

Warning: Do not use this diagnosis, modification, and tuning information as a


programming interface because it is subject to change.

Trademarks and service marks


The following terms are trademarks or registered trademarks of International
Business Machines Corporation in the United States, or other countries, or both:
v AIX®
v CICS®
v Cloudscape™
v DB2
v DB2 Extenders™
v DB2 Universal Database
v e-business
v IBM
v iSeries
v OS/390®
v S/390®
v VisualAge®
v WebSphere
v z/OS®

Java and all Java-based trademarks and logos are trademarks or registered
trademarks of Sun Microsystems, Inc. in the United States and other countries.

ActiveX, Microsoft®, Windows, Windows NT®, and the Windows logo are
trademarks or registered trademarks of Microsoft Corporation in the United States,
or other countries, or both.

UNIX® is a registered trademark of The Open Group.

Rational® is a trademark of International Business Machines Corporation and


Rational Software Corporation®, in the United States, other countries or both.

Other company, product, and service names, which may be denoted by a double
asterisk(**), may be trademarks or service marks of others.

Notices 41

You might also like