Legal | Privacy

Deploying Database Web Services

In this lesson, you learn how to deploy a call-out Web service to OC4J.

This lesson covers the following topics:

Overview
Prerequisites
Understanding the Purchase Order Application
Installing the Application
Setting Up the Database
Opening the Application
Running the Application

Place the cursor on this icon to display all the screenshots in the lesson. You can also place the cursor on each individual icon in the following steps to see only the screenshot that is associated with that step.

Database Web Services

Web services enable programmatic access to remote content and application functionality on the Web using industry-standard mechanisms, without dependence on the platform, location, and implementation. The interfaces and binding of Web services are capable of being described by standard XML. Web services are services deployed on the middle-tier application servers. Oracle9iAS Web services focus on exposing the J2EE components as Web services. However, there is an increasing need to access stored procedures as well as data and metadata through the Web services interface. Database Web services focus on exposing functionality in the database as Web services and consuming external Web services from the database.

Before starting this lesson, you should have:

1.

Completed the Configuring Linux for the Installation of Oracle Database 10g lesson

2.

Completed the Installing the Oracle Database 10g on Linux lesson

3.

Completed the Installing Oracle9i JDeveloper on Linux lesson.

4.

Downloaded and unzipped dbws.zip to your working directory
(/home/oracle/wkdir)

The application that you deploy in this lesson illustrates calling a Web service from within an Oracle database. It shows calling out Web services from a Java stored procedure. The front end of this purchasing-model application is designed with JSP pages, which display the product catalog and enable you to browse for products. To purchase products, you provide log-in information, with authentication performed by the Web service. This application uses a Credit Agency Web service that maintains a repository of customers and their credit card information. The Web service exposes two methods:

To authorize the customer
To bill the purchase amount to the customer's credit card account

How does the application work?

1.

The products catalog is displayed, and you can browse through the catalog.

2.

To purchase any product, you must enter your customer ID.

3.

The Credit Agency Web service maintains a repository of customers and their credit card information. Based on the login information supplied in step 2, the Web service authenticates you for buying products.

  a. If you are not a valid customer, the Web service returns INVALID_CUSTOMER.
  b.

If you are a valid customer, the Web service returns VALID_CUSTOMER. The information about the products that you have chosen is stored in the database. The status of the order is stored as PENDING and processed later.

4.

A batch job runs every six minutes to process the PENDING orders.

5.

This job invokes the Credit Agency Web service to bill your account. The Web service is invoked with the customer information and the amount of purchase.

  a. If the amount in your account is less than the bill amount, the Web service returns the string INSUFFICIENT_FUNDS and your account is restored.
  b. If the amount in your account is sufficient, the account is charged and the message SHIPPED is returned.
  c.

If the Web service does not recognize you, it returns INVALID_CUSTOMER.

6.

Depending on the response from the Web service, the batch job updates the order status with the string that is returned by the Web service.

Move your mouse over this icon to see the image

Files in the Application

WSClientSample
build.xml Project build file for generating deployment file using ANT. You use this file only if you are deploying the application to standalone OC4J.
WSClientSample.jws Oracle9i JDeveloper workspace file
WSClientSample.jpr Oracle9i JDeveloper project file
WSClientSample/config
application.xml Configuration file for the Application Server
WSCreate.sql SQL script file used to create a user and the tables required by the application
WSProcedure.sql SQL script used to publish the Java stored procedure to the database and create a batch job for invoking the Java stored procedure
Connection.properties Properties file that has details of the database connection
WSClientSample/src/oracle/otnsamples/wsservices
CreditAgencyService.java Class that implements a stateless Java Web service
ICreditAgencyService.java Web service interface that lists the methods exposed as Web service
CreditAgencyService.wsdl WSDL file for the Web service
ConnectionManager.java A Java bean used for managing database connection
WSClientSample/src/oracle/otnsamples/wsclient
CreditAgencyServiceClient.java Stored procedure that invokes the Web service for validation
CreditAgencyServiceStub.java Client-side stub file for the Web service; generated by Oracle9i JDeveloper
StoresBean.java Java bean used by the JSP to handle database operations
OrdersInfo.java Value object used to pass order information between the JSP and the Java bean
ProductsInfo.java Value object used to pass product information between the JSP and the Java bean
WSClientSample/webroot
Products.jsp Displays the product catalog and accepts orders
ViewOrders.jsp Retrieves order status for a specified order ID
ShipOrders.jsp Retrieves order information from the database for the shipping service
ErrorHandler.jsp Error page for JSP pages
WEB-INF/web.xml Configuration file for the Web container

To install the Purchase Order application, do the following:

1.

Open a terminal window and execute the following commands:

cd /home/oracle/wkdir
jar xvf dbwebservice.jar

Move your mouse over this icon to see the image

 

To set up the database, perform the following steps:

1.

Open this file with an editor: /home/oracle/wkdir/WSClientSample/config/WSCreate.sql

Verify that the following line specifies localhost:8988. Make corrections if necessary:

execute dbms_java.grant_permission('WS','SYS:java.net.SocketPermission',
  'localhost:8988','connect,resolve');

Move your mouse over this icon to see the image

 

2.

From your terminal window, execute the following commands:

cd /home/oracle/wkdir/WSClientSample/config
sqlplus /nolog
connect / as sysdba
@WSCreate
exit

This script prompts you to enter a password for the user system and the tns name. Enter oracle and orcl, respectively.

Move your mouse over this icon to see the image

 

3.

The Web service client is a Java stored procedure. This client application requires some .jar files to be present in the database to invoke the external Web service. Edit the load.sh file found in /home/oracle/wkdir and modify the path of the .jar files to reflect the correct path on your machine.

/u01/app/oracle/product/10.1.0/db_1/oc4j/soap/lib/soap.jar
/u01/app/oracle/product/10.1.0/db_1/oc4j/lib/dms.jar
/u01/app/oracle/product/10.1.0/db_1/lib/servlet.jar
/u01/app/oracle/product/10.1.0/db_1/oc4j/j2ee/home/lib/ejb.jar
/u01/app/oracle/product/10.1.0/db_1/oc4j/j2ee/home/lib/mail.jar
/u01/app/oracle/product/10.1.0/db_1/oc4j/j2ee/home/lib/jssl-1_2.jar
       

From your terminal window, run the following commands:

cd /home/oracle/wkdir
chmod 777 load.sh
./load.sh

Move your mouse over this icon to see the image

 

4.

Check the Web service end point in the client. Open the following file:/home/oracle/wkdir/WSClientSample/src/oracle
/otnsamples/wsclient/CreditAgencyServiceStub.java

Verify that the string variable endpoint points to your Web service end point as follows:

public String endpoint = "http://localhost:8988/wsclient/CreditAgencyService";

Move your mouse over this icon to see the image

5.

Load the Web service client and stub file to the database. Switch back to your terminal window and issue the following commands:

cd /home/oracle/wkdir/WSClientSample/src/oracle/otnsamples/wsclient
loadjava -thin -user ws/ws@localhost:1521:orcl 
   CreditAgencyServiceStub.java CreditAgencyServiceClient.java

 

6.

Publish the Web service client and create a database job that can invoke the Web service. From your terminal window, execute the following commands:

cd /home/oracle/wkdir/WSClientSample/config
sqlplus /nolog
connect / as sysdba;
@WSProcedure
exit
When prompted for the tnsname value, type orcl. This SQL script publishes the stored procedure created in the previous step to the database and creates a job that invokes CreditAgencyServiceClient.java once every six minutes.

Move your mouse over this icon to see the image

 

7.

Open the following file:
/home/oracle/wkdir/WSClientSample/config/
Connection.properties

Verify the following values:

HostName = localhost
SID = orcl
Port = 1521
UserName = ws
Password = ws

Move your mouse over this icon to see the image

 

To open the application in JDeveloper, perform the following steps:

1.

Launch JDeveloper.

2.

Click and highlight Workspaces in the System-Navigator window. Then click the + icon at the top-left corner of this window.

Move your mouse over this icon to see the image

 

3.

Select the following file, and then click Open:
/home/oracle/wkdir/WSClientSample/WSClientSample.jws.

Move your mouse over this icon to see the image

 

4.

Expand the Workspaces tree to ensure that the project WSClientSample.jws is included.

Move your mouse over this icon to see the image

 

The USERS table in the ws schema is populated with two usernames: otn-user and oracle-user. The credit limit for otn-user is $2,000, and the credit limit for oracle-user is $3,000. You now run the application and place an order by otn-user for under $2,000 and another order that exceeds the credit limit of $2,000. Perform the following steps:

1.

Right-click CreditAgencyServiceWebservice and select Regenerate Web Service.

Move your mouse over this icon to see the image

 

2.

Click Yes to close the warning window.

Move your mouse over this icon to see the image

 

3.

Right-click the project WSClientSample.jpr and select Run.

Move your mouse over this icon to see the image

 

4.

When you run the application, you see this product selection screen in the default browser. Enter otn-user as the customer ID, and then choose some of the products. The default quantity is 1 if you do not specify a quantity. Then click Place Order. Click Continue when the security warning window appears

Move your mouse over this icon to see the image

 

5.

Observe that the order is placed successfully with order ID 1. Click View Order Status.

Move your mouse over this icon to see the image

 

6.

Enter 1 as the order ID and click Get Order Details. Click Continue if you see the security warning.

Move your mouse over this icon to see the image

 

7.

You have successfully placed the order. As the vendor, you now go to the shipment module to check the pending orders. In the URL, change ViewOrders.jsp to ShipOrders.jsp. The URL is now the following:

 http://host:8988/wsclient/ShipOrders.jsp

Move your mouse over this icon to see the image

 

8.

Select your order for shipping and then click Ship Order.

Move your mouse over this icon to see the image

 

9.

Observe that the status of the order changes from PENDING to IN_SHIPPING. The shipping process is automated and configured to run every six minutes. The process scans the database for orders that are ready to be shipped. Click Back to Orders Page.

Move your mouse over this icon to see the image

 

10.

You see that you have no more orders pending. Based on the amount of purchase and the credit balance of the customer, the status of the order is updated when the batch job is run next time. Remember that the batch job is designed to run every six minutes.

Move your mouse over this icon to see the image

 

11.

Open a SQL*Plus session and execute the following command:

connect ws/ws

Determine the next time that the job runs by issuing the following query:

SELECT last_date, last_sec, next_date, next_sec
FROM user_jobs
WHERE what like 'ws_client%';

Move your mouse over this icon to see the image

 

12.

Switch back to your browser and check the order status. In the location bar, replace ShipOrders.jsp with ViewOrders.jsp. Enter 1 as the order ID, and then click Get Order Details.

Move your mouse over this icon to see the image

 

13.

Observe that the status changes from IN_SHIPPING to SHIPPED. If it does not change, the batch job has not yet run. Try again in a few minutes until the status changes.

Move your mouse over this icon to see the image

 

14.

You now place another order so that the total amount of the order exceeds the credit limit. Change the URL to http://localhost:8988/wsclient/Products.jsp.
Enter otn-user as the customer ID, and then choose three of the products with a quantity of 10 for each. Click Place Order.

Move your mouse over this icon to see the image

 

15.

Your order is placed. Change the URL to http://localhost:8988/wsclient/ShipOrders.jsp.

Move your mouse over this icon to see the image

 

16.

Select your order, and then click Ship Order.

Move your mouse over this icon to see the image

 

17.

Your order is shipped. You must wait for the batch job to execute again.

Move your mouse over this icon to see the image

 

18.

Change the URL to http://localhost:8988/wsclient/ViewOrders.jsp.
Enter 2 as the order ID, and then click Get Order Details.

Move your mouse over this icon to see the image

 

19.

You see that there are insufficient funds because the credit limit is now exceeded.

Move your mouse over this icon to see the image

 

Place the cursor on this icon to hide all screenshots.

 

 

 

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy