LuckyNumberDBClient.jws Sample

A sample that uses a database to store players and their lucky numbers. LuckyNumberDBClient uses the LuckyNumber.jws web service to generate random numbers in the range [1,20] inclusive, then checks for winners in a database and returns the number drawn and the list of winners, if any. The database is managed using the LuckyNumberDBControl.ctrl Database control. LuckyNumberDBControl.ctrl creates and manages a PLAYERS table in the database and implements queries against it. Demonstrates using SQL's CREATE , INSERT, SELECT and DROP statements in a database control.

# Concepts Demonstrated by this Sample

- Use of a Database control

# Location of Sample Files

This sample is located in the database folder of the samples WebLogic Workshop project. In the file system the location is:

BEA_HOME\weblogic700\samples\workshop\applications\database\LuckyNumberDBClient.jws

# How to Run the Sample

To run this web service:

1. Start WebLogic Server in the appropriate domain.

   - On Microsoft Windows systems, from the Start menu navigate to:

   BEA WebLogic Platform 7.0->WebLogic Workshop->WebLogic Workshop Examples->Start Examples Server.

   - On Linux or Solaris systems, run:

   BEA_HOME/weblogic700/samples/workshop/startWebLogic.sh

2. Launch the service either by opening it in WebLogic Workshop and selecting the Start operation or by entering http://localhost:7001/samples/database/LuckyNumberDBClient.jws in the address bar of your browser. If WebLogic Server is running in the appropriate domain on this machine, you may click here to run the sample.

3. Navigate to the Test Form tab of Test View, if necessary.

4. Invoke the start method to create the database table and populate it with test data.

5. Click on the conversation ID (the large number in the Message Log) to access the continue and finish methods for that conversation.

6. Invoke the drawNumber method. The web service invokes the getLuckyNumber method of the LuckyNumber web service to obtain a random number. LuckyNumberDBClient then queries the database, via the LuckyNumberDBControl Database control, to see if there are any players holding that number.

7. Any winners found are returned in a string, as the return value of drawNumber.

8. Test View always show the details of a Message Log entry when it arrives. Since the invocation of getLuckyNumber occurred after the invocation of drawNumber, Test View is now displaying the details of the getLuckyNumber invocation. Select the drawNumber entry in the Message Log to see its formatted return string.

9. Select log entries in the Message Log to see the message traffic involved in each interaction.

10. Examine the source code for LuckyNumberDBClient.jws and LuckyNumberDBControl.ctrl to see how the CTRL file defines database operations and method shape and the web service uses the methods and data structures provided by the Database control.

Related Topics

CustomerDBClient.jws Sample

Controls: Using Resources from a Web Service

Database Control: Using a Database from Your Web Service

@jws:sql Tag

Test View