This topic tells you how to work with the Online Auction sample application
by completing one or both of the following activities:
- Running the ready-made Online Auction sample application
- Building the Online Auction sample application for yourself
The sample application features an auction Web site, where you can browse
auction items, submit items for sale, and bid on items. Running the application
gives you a quick feel for the kind of J2EE application that you can build with
WebSphere Studio. Also, the ready-made sample application contains a number of
J2EE components that you can browse and reuse.
Building the application will give you a solid introduction to many of the
WebSphere Studio tools, such as the EJB tools. To save time, some of the
required components for building the application are already provided, such as
the GIF images and some source code.
Even if you want to build the application, you may want to run the ready-made
sample application first. This will show you how the application works before
you actually build it, which will aid you in your development tasks.
Note: If you followed the instructions in Part 2 below and you built
the sample application before you followed these instructions on running
the ready-made application, then you will need to remove the Auction project
from the server configuration before you can run the ready-made application.
Instructions for removing the Auction project from the server configuration are
found in the final step of the "Unit test the application" section of
Part 2.
To run the ready-made application:
- Open WebSphere Studio.
- Click the Open The New Wizard icon
at the left end of the toolbar:
- In the left frame of the New wizard, expand Examples and select Enterprise
Applications 1.3.
- In the right frame, select Auction and click Next.
- In the Project name field, accept the default name.
- Click Finish. Instructions for running the Online Auction sample
application are automatically opened in the Web browser.
- Follow the instructions for running the sample application.
To build the sample application, you must perform the following tasks:
These tasks are described in the sections below.
In the workbench, everything must reside in a project. A project is the top
level of organization of your resources in the workbench. A project contains
files and folders. Projects are used for building, version management, sharing,
and organizing resources. A project can contain session and persistent
properties, settings for environmental variables, and references to other
projects. As resources are created and modified within a project or projects,
builders are run and constraints are maintained. Builders create or modify
resources within projects, usually based on the existence and state of other
resources. For example, a Java builder converts Java source files into
executable class files, a Web link builder updates links to files when names and
locations have changed, and so on.
In this section, you create an Enterprise Application project named Auction.
Enterprise Application projects contain the resources needed for enterprise
applications and can contain a combination of Web modules, JAR files, EJB
modules, and application client modules. An Enterprise Application project is
deployed in the form of an EAR file. You also create an EJB project named
AuctionEJB and a Web project named AuctionWeb, which are both referenced by the
Auction enterprise application project. EJB projects contain the metadata files
(such as the deployment descriptor, IBM(R) extensions, and RDB
mappings) for the EJB application, Java source files, compiled code for the
enterprise beans, and stubs for the beans. In this tutorial, you will create
Unified Modeling Language (UML) class diagram views of the EJB project and store
these views as diagrams in the EJB project. An EJB project is deployed as
an EJB module (JAR file). Web projects contain servlets, JSP files, Java files,
static documents (for example HTML pages or images), and any associated
metadata. A Web project is deployed as a Web module (WAR file). All three
projects are created in a single step using a wizard.
To create the three types of projects that are required for this application:
- Open WebSphere Studio.
- If you ran the ready-made sample application by following the instructions
in "Part 1 - Running the ready-made sample application", then you
must remove the AuctionExample project from the server configuration by
completing the following steps:
- Switch to the Server perspective (Window > Open Perspective >
Server).
- In the Server Configuration view, expand Server Configurations and
expand TestServer, then right-click AuctionExample and select Remove.
- Switch to the J2EE perspective (Window > Open Perspective > Other
> J2EE).
- Click the Open The New Wizard icon
at
the left end of the toolbar.
- In the left frame of the New wizard, select J2EE.
- In the right frame, select Enterprise Application Project and click
Next.
- Select the Create J2EE 1.3 Enterprise Application project radio
button and click Next.
- In the Enterprise application project name field, type Auction.
- Clear the Application client module check box.
- Accept the default names that appear in the EJB project name and Web
project name fields and click Finish.
- In the J2EE Hierarchy view, expand Enterprise Applications, Web Modules,
and EJB Modules to see the new projects. The Enterprise Application project
named Auction, the EJB project named AuctionEJB, and the Web project named
AuctionWeb are all added to the workbench:

In this section, you learn how to add the following enterprise beans to the
AuctionEJB project:
- A CMP entity bean named Onlineitem (using the bottom-up mapping approach).
Entity beans with container-managed persistence (CMP) fields must be mapped
to database tables that are represented in a schema. You map entity beans to
database tables by creating a map. Maps are used to generate the SQL and
other supporting code needed to make enterprise beans persistent. You will
use the bottom-up mapping approach to create the Onlineitem bean. This
approach assumes that the database tables already exist, and that once the
selected tables are imported, the enterprise beans and mappings between them
are automatically generated.
- An access bean named OnlineitemData (using the Create an Access Bean
wizard). An access bean is an enterprise bean wrapper that is typically used
by client programs, such as JSP files and servlets. Access beans simplify
client access to enterprise beans and improve the performance of reading and
writing multiple EJB properties.
- A session bean named ItemHelper (using the Create an Enterprise bean
wizard). Session beans are non-persistent enterprise beans that do not
require database access, though they can obtain it indirectly (as needed) by
accessing entity beans
You can also create a UML class diagram that shows the structure and
relationships of the Onlineitem entity bean.
To add enterprise beans to the EJB project:
- In the J2EE Hierarchy view, right-click AuctionEJB and select Generate
> EJB to RDB Mapping. The EJB to RDB Mapping wizard opens.
- Select Create a new backend folder and click Next.
- Select Bottom-up and click Next.
- The Database Connection page of the wizard appears. In the Database
field, type dreamauc.
In the User ID and Password fields, specify your DB2 user ID
(for example, db2inst1) and password.
- In the JDBC driver field, ensure that the following driver is
specified:
IBM DB2 APP DRIVER
- In the Class location field, ensure that the correct path is
specified for the JDBC driver and click Next. For example:
C:\Program Files\SQLLIB\java\db2java.zip
/home/db2inst1/sqllib/java12/db2java.zip
This instructs WebSphere Studio to read the database catalog for the
dreamauc database and display a list of the tables in the database. Click Next.
- Select the check box for the EJB.ONLINEITEM table and click Next:

- Select the Generate 2.0 enterprise beans radio button.
- In the Package for generated EJB classes field, type com.acme.ejb.
- Click Finish. A CMP entity bean named Onlineitem is created in
AuctionEJB and the mapping editor opens.
- Close the mapping editor.
To create the home and remote interfaces:
- In the J2EE Hierarchy view, right-click AuctionEJB and select Open
With > Deployment Descriptor Editor. The editor opens.
- Click the Beans tab and select Onlineitem.
- Scroll down to the Class and Interface Files section and click Add.
The Add Client View dialog box opens.
- Select the Add new remote and remote home interfaces and Copy
methods from local interfaces to remote interfaces checkboxes and click Finish.
- Save and close the deployment descriptor editor.
To create a UML class diagram view of the Onlineitem entity bean:
- In the J2EE Navigator view, right-click AuctionEJB and click New
> Folder on the shortcut menu. The New Folder dialog box opens.
- In the Folder name field, type diagrams.
- Click Finish.
- In the J2EE Navigator view, select the AuctionEJB project.
- Click File > New > Class Diagram. The New Class
Diagram dialog box opens.
- Select the folder AuctionEJB/diagrams.
- In the File name box, enter OnlineAuction.
- Click Finish. The Class Diagram Editor window opens.
- In the J2EE Hierarchy view, expand EJB Modules and AuctionEJB.
- Drag the Onlineitem entity bean to the Class Diagram Editor window. A UML view of the Onlineitem entity bean is created.
- In the Class Diagram Editor window, right-click the Onlineitem entity
bean and then click Filter > Show Accessor Operations on the
shortcut menu. The
get/set accessors are filtered out of the diagram.

- Save the UML class diagram.
To create an access bean:
- In the J2EE Hierarchy view, expand AuctionEJB, then select Onlineitem
and click the Create an access bean icon
on the toolbar.
- In the Add an Access Bean wizard, ensure that Data class is
selected. Data classes provide the data storage and access methods for
cacheable enterprise bean properties.
- Click Next and ensure that AuctionEJB is specified in the EJB
Project field.
- In the Enterprise Beans table, select the Onlineitem check
box and click Next.
- Select the Onlineitem bean in the Enterprise beans text
area.
- In the Interfaces to use group, click the Remote radio button.
- In the Access Bean name field, the default access bean name OnlineitemData
appears. Ensure that com.acme.ejb is specified in the Package
name field.
- Ensure that all of the check boxes in the Attribute helpers list
box are selected:

- Click Finish. The new access bean named OnlineitemData is
generated. (Also, an EJB factory class is also automatically generated that
is named OnlineitemFactory. OnlineitemFactory provides the means for
creating references to enterprise bean remote objects).
To add the access bean to the UML class diagram:
- Select the OnlineAuction diagram in the Class Diagram Editor
window.
- In the J2EE Navigator view, select the package AuctionEJB > ejbModule > com.acme.ejb.
- Drag the file OnlineitemData.java to the Class Diagram Editor window. The Java bean OnlineitemData and
its nested class Store are shown in the diagram.
- On the shortcut menu, click the Arrange > All Elements.
- In the Class Diagram Editor window, right-click the the Onlineitem entity bean
shape and click Filter > Show Operation Signature on the
shortcut menu.
- Save the UML class diagram.
To create a session bean:
- In the UML Class Diagram Editor tool box, select the Create a
Stateless Session Bean tool and then click inside the Class Diagram Editor
window. The Enterprise Bean Creation wizard opens.

- In the EJB Project box, select AuctionEJB and click Next.
- In the Bean name box, type ItemHelper and click Next.
- Select Container for the
Transaction type.
- In the boxes on the Enterprise Bean Details page, enter the following values:
- Bean supertype: <none>
- Bean class: com.acme.ejb.ItemHelperBean
- EJB binding name: ejb/com/acme/ejb/ItemHelperHome
- Remote home interface: com.acme.ejb.ItemHelperHome
- Remote interface: com.acme.ejb.ItemHelper
- Click Finish. A session bean named ItemHelper is created in the
AuctionEJB project. It holds the application's business
logic and serves as a front end for the Onlineitem CMP entity bean.
- Save the UML class diagram.
In this section, you add your business logic to the session bean and then
promote the bean to the remote interface. The remote interface defines the
business methods that can be called by a client. The business logic consists of
four public methods:
- create Registers a new item for sale in the auction. The method
ensures that the business rules are enforced, such as ensuring that the
value of the minimum opening bid is less than the appraised value of the
item.
- findByValue Searches the auction database for all items that have a
value less than the value specified as the search criteria.
- makeBid Bids for an item and ensures that all of the business rules
are met, such as ensuring that the current bid value is greater than the
previous bid value.
- reserveKeys A utility method that reserves a block of keys so that
when new items are submitted for sale, their entity key values can be
assigned locally.
To save you the effort of typing in the business methods by hand, the
business methods are provided for you in a .java file, which is contained in a
zipped project that you need to import. The next section shows you how to
complete the following tasks:
- Create a simple project to hold the contents of the zipped project that
you will import. Simple projects are generic projects that contain files and
folders.
- Import the zipped project
- Import the supporting classes from the zipped project and copy the
business methods to the session bean
- Add a finder method to obtain an entity bean instance from the dreamauc
database.
To create a project to hold the contents of the zipped project that you will
import:
- Click the Open The New Wizard icon at the left end of the toolbar.
- In the left frame of the New wizard, select Simple.
- In the right frame, select Project and click Next.
- In the Project name field, type AuctionSamples.
- Click Finish. The Resource perspective opens and the project
AuctionSamples is added to the workbench.
To import the zipped project:
- From the File menu, select Import to open the Import wizard,
then select Zip file and click Next.
- Beside the Zip file field, click Browse and then navigate to
the following file and select it (where install_path is the directory
where you have installed WebSphere Studio):
install_path\samples\scenario_parts\auction\AuctionSample.zip
/opt/IBM/WebSphereStudio/samples/scenario_parts/auction/AuctionSample.zip
Click Open.
- Beside the Folder field, click Browse and select the AuctionSamples
folder, then click OK.
- Click Finish. The files contained in AuctionSample.zip are imported
into the AuctionSamples project.
To import the supporting classes from the zipped project:
- From the File menu, select Import to open the Import wizard
again, then select Zip file and click Next.
- Beside the Zip file field, click Browse and then navigate to
the following file and select it (where workspace_path is the
directory where you have installed your WebSphere Studio workspace):
workspace_path\workspace\AuctionSamples\setup\Server-support.zip
/home/workspace_path/workspace/AuctionSamples/setup/Server-support.zip
Click Open.
- Beside the Folder field, click Browse and expand AuctionEJB,
then select ejbModule and click OK.
- Click Finish. The files contained in Server-support.zip are
imported into the ejbModule folder. (Any errors that appear in the Task list
will eventually be resolved as you continue walking through the
instructions.)
To copy the business methods to the session bean:
- In the Navigator view, expand AuctionSamples and the setup folder, then
double-click ItemHelperBean.java to open the source editor.
- In the editor, copy the entire contents of the class to the clipboard,
then close the editor.
- Switch to the J2EE perspective.
- In the J2EE Hierarchy view, expand EJB Modules, AuctionEJB,
and ItemHelper, then double-click ItemHelperBean. The class
opens in the Java editor.
- In the editor, replace the entire contents of the class by pasting in the
contents that you copied to the clipboard.
- Click File > Save ItemHelperBean.java to save the revised source
code. (Any errors that appear in the Task list will eventually be resolved
as you continue following the instructions.)
- In the Outline view, expand ItemHelperBean and select the create,
findByValue, makeBid, and reserveKeys methods together:

- Right-click the methods and select Enterprise Bean > Promote to
Remote Interface.
Notice the R label decoration appears beside the method names in the
Outline view to indicate that these are remote methods.
(Optional) You can browse the source code for these four methods to give
you an idea of how to add business logic to an application.
- Close the editor.
- In the J2EE Hierarchy view, double-click the ItemHelper class. The
source editor opens.
- Type (or copy and paste) the following code fragment into the ItemHelper
source code immediately after the opening curly brace:
public static final int ERROR_KEY = -1;
- In the editor, click File > Save ItemHelper.java to save the
updates and then close the editor.
To add a finder to the Onlineitem CMP bean:
- With OnlineAuction open in the Class Diagram Editor window, right-click the Onlineitem entity
bean and then click Open Deployment Descriptor Editor on the shortcut
menu. The Deployment Descriptor Editor opens.
- Click the Beans tab, and then select Onlineitem.
- Scroll down to the Queries section and click Add. The Add Finder
Descriptor dialog box opens.
- Select New for the method.
- Select find method for the method type.
- Select Remote for the type.
- In the Name box, type findByValue.
- Click the Add button beside the Parameters list box. The Add Method
Parameter dialog box opens.
- In the Name box, type value.
- In the Type box, select long and click OK.
- In the Return type box, select java.util.Collection and
click Next.
- In the Query statement text area, type the following string and
click Finish:
select object(o) from Onlineitem as o where o.value <=?1
In the string, value is the name of a column in the Onlineitem
table and ?1 represents the parameter that is passed into the
finder method, so the string specifies that you want all of the items in the
auction that are less than or equal to the amount that is passed in.
- Click File > Save EJB Deployment Descriptor to save the changes,
and then close the deployment descriptor editor.
- Arrange the diagram so that it appears as the image below.

- Click File > Save OnlineAuction.dnx to save your diagram
changes, and then close the Class Diagram Editor.
To generate deploy code for the enterprise beans:
- Right-click AuctionEJB and select Generate > Deploy and RMIC
code.
- Click Select all to mark both the Onlineitem and ItemHelper beans
for code generation:

- Click Finish to generate the deploy and RMIC code. This code is
needed to deploy the EJB module to a server.
To configure the EJB module to use the correct data source for the auction
database:
- In the J2EE Hierarchy view, right-click AuctionEJB.
- Select Open With > Deployment Descriptor Editor.
- Scroll down to the JNDI -- CMP Factory Connection Binding section.
- In the JNDI name field , type jdbc/dreamauc for the data
source JNDI name.
- In the Container authorization type field, select Per_Connection_Factory.
Later, the JNDI name will be paired up with a JNDI name in the
application server configuration, so that a connection to the real database
can be made.

- In the Backend ID section, click Refresh and ensure the value in
the Current field is DB2UDBNT_V72_1.
- Click File > Save EJB Deployment Descriptor and then close the
deployment descriptor editor.
To create and configure a server:
- Right-click the Servers folder in the J2EE Hierarchy. Select New >
Server and Server Configuration. The Create a New Server and Server
Configuration wizard opens.
- In the Server Name field, type TestServer.
- In the Folder field, select Servers from the drop-down menu.
- In the Server type list box, expand WebSphere version 5.0
and select Test Environment.
- Click Finish to create the server.
In the J2EE Hierarchy, expand Servers.
Double-click TestServer. The server configuration editor opens.
In the server editor, click the Paths tab, then click Add External
JARs in the WebSphere specific class path (ws.ext.dirs) section
to add DB2_installdir/java12/db2java.zip to the WebSphere
path, where DB2_installdir is the directory where DB2 is installed.
Click File > Save (name of file) to save your changes.
Now you need to add a data source so that the server can access the data in
the dreamauc database. You will need to complete the following tasks:
- Defining a JAAS authentication entry
- Defining a JDBC provider
- Defining a data source
- Defining resource properties for the data source, such as userids and
passwords
To define a JAAS authentication entry:
- In the J2EE Hierarchy, expand Servers.
- Double-click TestServer. The server configuration editor opens.
- At the bottom of the editor, click the Security tab.
- In the JAAS Authentication Entries section, click Add. The JAAS
Authentication Entry dialog opens.
- In the Alias field, type your DB2 user ID.
For
Linux this is db2inst1.
- In the User ID field, type your DB2 user ID again.
For
Linux this is db2inst1.
- In the Password field, type your DB2 password then click OK.
To add a data source and define its resource properties:
- At the bottom of the editor, click the Data Sources tab.
- Scroll down to the Server Settings section. In the JDBC provider list,
select Default DB2 JDBC Provider.
- In the Server settings section, beside the Data source defined in the
JDBC provider selected above list table, click Add. The Create a
Data Source wizard opens. This is where you add your information for the
dreamauc auction database that you created and populated when you earlier
ran the DB2 script.
- Select DB2 JDBC Provider the Version 5.0 data source radio
button and click Next. A version 5.0 data source is needed to run CMP
2.0 enterprise beans.
- In the Name field, type dreamauc.
- In the JNDI name field, type jdbc/dreamauc.
- In the Description field, type Dream Auction Database.
- In the Category field, type Examples.
- In the Data source helper class name field, select com.ibm.websphere.rsadapter.DB2DataStoreHelper.
- In the Component-managed authentication alias field, select the
alias that you defined earlier.
- Select the Use this data source in container managed persistence (CMP)
check box and click Next.
- In the Resource Properties field, select select databaseName
- In the Value field, type dreamauc and click Finish.
- Click File > Save TestServer to save the configuration, then
close the editor. In the steps you just completed, you associated a pooled
database connection to a JNDI name that can be used by the application.
(Optional) If you are using a non-English system to operate WebSphere Studio,
you must add a system property to the server configuration:
- In the J2EE Hierarchy, expand Servers.
- Double-click TestServer. The server configuration editor opens.
- Click the Environment tab.
- Beside the System Properties list table, click Add. The Add System
Property dialog box opens.
- In the Name field, type client.encoding.override.
- In the Value field, type UTF-8 and click OK.
- Click File > Save TestServer to save the configuration, then
close the editor.
Now you need to test your business methods using the universal test client.
First you will launch the server on the ItemHelper bean, which will start the
universal test client:
From the Window menu, select Preferences. The Preferences page
appears.
In the left frame, select Web Browser, then in the Location
field, type the following path for the Mozilla Web browser. For example, /usr/local/mozilla/mozilla
Click OK to close the Preferences page.
- In the J2EE Hierarchy view, expand EJB Modules and expand AuctionEJB,
then select ItemHelper
.
Right-click ItemHelper and select Run on Server to start the
server. The Server Selection wizard appears.
- Click Advanced.
- Click the Use an existing server radio button. Select TestServer
and click Next. Click Finish. If a message appears that asks
you if you want to convert your Netscape files to Mozilla, click the Convert
button.
- It may take a moment or two for the test client to appear, since all of
the following tasks are being performed automatically:
- Publishing the application to the test server
- Configuring the test server
- Starting the test server
- Starting the test client
- Starting the Web browser
Since the server was launched on a specific enterprise bean, the
Universal test client is opened on the bean in the browser window:

Now you will invoke methods and pass parameters to objects to place a bid.
- In the References pane, expand EJB References and ItemHelper
and ItemHelperHome, then click the ItemHelper create() link.
This prepares the test client to invoke the create method.
- In the Parameters pane, click Invoke to create and return a new
ItemHelper object. The ItemHelper object is returned in the lower half of
the Parameters pane:

- Click Work with Object. This adds the ItemHelper instance to the
References pane.
- In the References pane, expand ItemHelper (1) and click the Status
makeBid method link.
- In the Parameters pane, expand the parameters and type the following
values in the Value column:
- java.lang.Integer: 1
- java.lang.Long: 20000
- java.lang.String: Gary
- int: 1
The values specified for the parameters (which you can view in the source
code) have the following interpretations:
- 1 -- The item ID
- 20000 -- A bid of $200.00
- Gary -- The name of the bidder
- 1 -- The type of currency
- Click Invoke. A return code of 0 indicates that the method
completed successfully. You have just made your first bid!
Next, you will use the JNDI Explorer to find the object that you just bid on.
- Above the Parameters pane, click the JNDI Explorer icon
to open the JNDI Explorer.
- Expand the following folders: ejb/com/acme/ejb.
- Click the OnlineitemHome link:

- In the References pane, expand OnlineitemHome and click the Onlineitem
findByPrimaryKey(OnlineitemKey) link.
- In the Parameters pane, expand com.acme.ejb.OnlineitemKey and OnlineItemKey.Itemtypeid
appears in the Parameters column.
- In the Value field for the itemtypeid row, type 1 and
click Invoke. (In these steps, you are creating a new key and then
passing the key into the findByPrimaryKey method.)

- Click Work with Object. This places the item that you found in the
previous step in the References pane.
- In the References pane, expand Onlineitem and click the String
getLastbidder() method.
- In the Parameters pane, click Invoke.
- Ensure that the resulting string is correct. It should be the name of the
bidder (Gary).
- If you want, you can continue to explore the features of the test client
by invoking more methods.
- When you are finished exploring, in the Servers perspective, click the Servers
tab to switch to the Servers view.
- In the Server column, select the TestServer server and then click
the Stop icon
.
- Close the browser session where the Universal Test Client is running.
In this optional section, you configure your workspace with the location of
the team server. (This section assumes that you either have access to a CVS
server or you have already installed a CVS server for yourself using the
instructions in the topic "Preparing for the Online Auction sample
application").
- Open the CVS Repository Exploring perspective (Window > Open
Perspective > Other > CVS Repository Exploring).
- Position your mouse pointer in the CVS Repositories view, then right-click
and select New > Repository Location. The Add CVS Repository
wizard appears. (To determine the actual values that you need to specify in
the wizard, you will probably need to talk to your CVS administrator.)
- In the Host field, type the host name or IP address of the team
server.
- In the Repository path field, type the fully qualified directory
name of the CVS repository on the server. For example:
D:\CVS\CVSROOT
usr/local/cvsroot
- In the User field, type in your team server user name.
- In the Password field, type in your CVS password
- In the Connection type field, ensure that the correct connection
type is selected:

- Click Finish.
To prevent the class files from being stored in CVS, and save space in the
repository:
- From the main menu, click Window > Preferences > Team >
Ignored Resources.
- Click the Add button beside the Ignore Patterns pane. The Enter
Ignore Pattern dialog box opens.
- Type *.class and click OK.

- Click OK on the Preferences page to save your changes.
You can specify label decorations to appear for CVS resources, to show CVS
specific information on resources under CVS control. To display CVS label
decorations:
- From the main menu, click Window > Preferences > Workbench >
Label Decorations.
- In the Available label decorations list box, click the CVS check
box.
- Click OK on the Preferences page to save your changes.
In this optional section, you learn how to version your application. (This
section assumes that you either have access to a CVS server or you have already
installed a CVS server for yourself using the instructions in the topic
"Preparing for the Online Auction sample application").
- Switch to the J2EE perspective.
- In the J2EE Navigator view, select the Auction project.
- Right-click and select Team > Share Project. The Share Project
wizard opens.
- Select CVS and click Next.
- Select the existing repository and click Next.
- Click the Use project name as module name radio button and click Next.
- Click Finish to import the project into the CVS repository. The
Synchronize view opens.
- In the Structure Compare pane, right-click Auction and then select Commit.
- You are prompted to add the resources to version control. Click Yes.
(If you want, you can enter a comment in the next dialog box when prompted.)
- Repeat steps 1-9 for each of the AuctionEJB and AuctionWeb projects. The
server is updated with a file structure that matches the structure you have
in the local file system and the files on the server are automatically
compared to the files in the local file system.
- Switch to the CVS Repository Exploring perspective.
- In the CVS Repositories view, click the Refresh View icon
.
Expand the connection and expand HEAD.
- Select the Auction, AuctionEJB, and AuctionWeb
projects together, then right-click and select Tag as Version. This
causes the server to associate the same tag for all the files in these three
projects on the server. The Tag Resources dialog box appears.
- In the Please enter a version tag field, type V1 and click
OK.
- In the CVS Repositories view, expand Versions and then expand Auction
to see the new version.
In this optional section, you learn how to load the application into a
different WebSphere Studio workspace that resides on a remote machine, such as a
Web designer's machine. If you don't have access to a remote machine,
instructions are provided for simulating the experience by opening up a second
workspace on your own local machine. In this section and the following section,
the second workspace is referred to as the "Web designer's workspace."
(This section assumes that you either have access to a CVS server or you have
already installed a CVS server for yourself using the instructions in the topic
"Preparing for the Online Auction sample application".)
- If you are using a remote machine, follow the instructions given
previously for installing DB2 on the remote machine and running the DB2
script that is used to create the required database tables.
- If you do not have access to a remote machine and you want to open up a
second workspace on your local machine instead, complete the following three
steps:
- Close your current workspace by exiting WebSphere Studio.
- Start WebSphere Studio. You are prompted to specify a directory for
your workspace. Type the location of a new workspace. For example:
workspace_path\workspace2
/home/user_id/workspace_path/workspace2
WebSphere Studio opens with the new workspace. None of the resources that
you created in your other workspace are currently visible.
- Open the CVS Repository Exploring perspective.
- Position your mouse pointer in the CVS Repositories view, then right-click
and select New > Repository Location. The Add CVS Repository
wizard appears. (To determine the actual values that you need to specify in
the wizard, you will probably need to talk to your CVS administrator.)
- In the Host field, type the host name or IP address of the team
server.
- In the Repository path field, type the fully qualified directory
name of the CVS repository on the server. For example:
D:\CVS\CVSROOT
usr/local/cvsroot
- In the User field, type in your team server user name.
- In the Password field, type in your CVS password.
- In the Connection type field, ensure that the correct connection
type is selected and click Finish.
- Add CVS label decorations as previously described in the Set up the team
environment section.
- The default settings in WebSphere Studio are set to prune empty
directories in CVS. To disable this setting, from the main menu, click Window
> Preferences > Team > CVS .
- Clear the Prune empty directories check box and click OK to
exit the Preferences page.
- In the CVS Repositories view, expand the new repository node and expand HEAD,
then select Auction, AuctionEJB, and AuctionWeb
together and right-click and select Check out As Project. This adds
the projects to the Web designer's workspace.
To create and configure a server:
- Open the Server perspective.
- From the main menu, select File > New > Server Project. The
Create a New Server project wizard opens.
- In the Project Name field, type Servers and click Finish.
A new server project is created.
- From the main menu, select File > New > Server and Server
Configuration. The Create a New Server and Server Configuration wizard
opens.
- In the Server Name field, type TestServer.
- In the Folder field, select Servers from the drop-down menu.
- In the Server type list box, expand WebSphere version 5.0
and select Test Environment.
- Click Finish to create the server.
In the Server Configuration view, expand Servers.
Double-click TestServer. The server editor opens.
In the server editor, click the Paths tab, then click Add External
JARs in the WebSphere specific class path (ws.ext.dirs) section
to add DB2_install/java12/db2java.zip to the WebSphere path,
where DB2_install is the directory where DB2 is installed.
Click File > Save (name of file) to save your changes, then close
the server editor.
Now you need to add a data source so that the server can access the data in
the dreamauc database. You will need to complete the following tasks:
- Defining a JAAS authentication entry
- Defining a JDBC provider
- Defining a data source
- Defining resource properties for the data source, such as userids and
passwords
To define a JAAS authentication entry:
- In the J2EE Hierarchy, expand Servers.
- Double-click TestServer. The server configuration editor opens.
- At the bottom of the editor, click the Security tab.
- In the JAAS Authentication Entries section, click Add. The JAAS
Authentication Entry dialog opens.
- In the Alias field, type your DB2 user ID.
For
Linux this is db2inst1.
- In the User ID field, type your DB2 user ID again.
For
Linux this is db2inst1.
- In the Password field, type your DB2 password then click OK.
To add a data source and define its resource properties:
- At the bottom of the editor, click the Data Sources tab.
- Scroll down to the Server Settings section. In the JDBC provider list,
select Default DB2 JDBC Provider.
- In the Server settings section, beside the Data source defined in the
JDBC provider selected above list table, click Add. The Create a
Data Source wizard opens. This is where you add your information for the
dreamauc auction database that you created and populated when you earlier
ran the DB2 script.
- Select DB2 JDBC Provider the Version 5.0 data source radio
button and click Next. A version 5.0 data source is needed to run CMP
2.0 enterprise beans.
- In the Name field, type dreamauc.
- In the JNDI name field, type jdbc/dreamauc.
- In the Description field, type Dream Auction Database.
- In the Category field, type Examples.
- In the Data source helper class name field, select com.ibm.websphere.rsadapter.DB2DataStoreHelper.
- In the Component-managed authentication alias field, select the
alias that you defined earlier.
- Select the Use this data source in container managed persistence (CMP)
check box and click Next.
- In the Resource Properties field, select select databaseName
- In the Value field, type dreamauc and click Finish.
- Click File > Save TestServer to save the configuration, then
close the editor. In the steps you just completed, you associated a pooled
database connection to a JNDI name that can be used by the application.
(Optional) If you are using a non-English system to operate WebSphere Studio,
you must add a system property to the server configuration:
- In the J2EE Hierarchy, expand Servers.
- Double-click TestServer. The server configuration editor opens.
- Click the Environment tab.
- Beside the System Properties list table, click Add. The Add System
Property dialog box opens.
- In the Name field, type client.encoding.override.
- In the Value field, type UTF-8 and click OK.
- Click File > Save TestServer to save the configuration, then
close the editor.
In this section, you add a Web front end to your application that will
include the following functions:
- Searching for online items (based on a specified value)
- Obtaining details of a particular online item
- Registering an item for sale in the auction
- Bidding for an item
The OnlineItemData access bean will hold the information for an item.
To save you time, the Web front end is already provided for you in a WAR
file, which contains the artwork, JSP files, and servlets.
To add the Web front end:
- If you completed the steps in the previous section "Add shared
projects to another workspace", then remain in your current Web
designer's workspace to complete the steps in this section. However, if you
did not complete the steps in the "Add shared projects to another
workspace" section, you should continue to use the workspace that you
have been using up to this point in the tutorial.
- If you are working in the Web designer's workspace rather than in the
original developer's workspace where you began the tutorial, then complete
the following steps:
- Click the Open The New Wizard icon at the left end of the
toolbar.
- In the left frame of the New wizard, select Simple.
- In the right frame, select Project and click Next.
- In the Project name field, type AuctionSamples.
- Click Finish. The project AuctionSamples is added to the
workbench.
- From the File menu, select Import to open the Import
wizard, then select Zip file and click Next.
- Beside the Zip file field, click Browse and then
navigate to the following file and select it (where install_path
is the location where you have installed WebSphere Studio).
install_path\samples\scenario_parts\auction\AuctionSample.zip
/opt/IBM/WebSphereStudio/samples/scenario_parts/auction/AuctionSample.zip
- Beside the Folder field, click Browse and select the
AuctionSamples folder, then click OK.
- Click Finish. The files contained in AuctionSample.zip are
imported into the AuctionSamples project.
- From the File menu, select Import to open the Import wizard,
then select WAR file and click Next. A Web archive (WAR) file
is a packaged Web application that is deployed on a Web server. A Web
application is a group of HTML pages, JSP pages, servlets, and other
resources, along with source files that can be managed as a single unit.
- Beside the WAR File field, click Browse and then navigate to
the following WAR file and select it (where workspace_path is the
path where you installed the WebSphere Studio workspace):
workspace_path\workspace\AuctionSamples\setup\AuctionWeb.war
If you are working in the original developer's workspace, select: /home/user_name/workspace/AuctionSamples/setup/AuctionWeb.war.
If you are working in the Web developer's workspace, select: /home/user_name/workspace_path/workspace2/AuctionSamples/setup/AuctionWeb.war
- In the Web project group, select the Existing radio button.
- Click Browse, select the AuctionWeb project and click OK.
- Select the Overwrite existing resources without warning check box.
- Click Finish. The WAR file is imported into the AuctionWeb project.
Any errors or warnings that appear in the Task list will be resolved as you
complete the instructions
- To set the module dependency for the AuctionWeb project to the AuctionEJB
project, right-click the AuctionWeb project and select Properties.
The Properties page opens.
- On the left frame of the Properties page, click Java JAR Dependencies.
- In the Available dependent JARs list table, click the AuctionEJB.jar
check box and click OK. This enables the Web project to access the
classes in the EJB project at run time.
- If you completed the optional "Set up the team environment" and
"Version the application" sections, then complete the following
steps:
- In the Navigator view, right-click the AuctionWeb
project, then select Team > Synchronize with Repository. The
Synchronize view opens.
- In the Structure Compare pane, right-click AuctionWeb and then
select Commit.
- You are prompted to add the resources to version control. Click Yes.
(If you want, you can enter a comment in the next dialog box when
prompted.)
- If you used a second workspace (the Web designer's workspace) to complete
the steps in this section, you now have a fully functioning application and
you could use the various WebSphere Studio tools to enhance the application.
At this point in the tutorial you should now close the second workspace and
open your original WebSphere Studio developer's workspace by exiting and
restarting WebSphere Studio with your original workspace.
To run the application in the test environment:
- If you completed the steps in the section "Add shared projects to
another workspace", then complete the following two steps:
- Switch to the J2EE perspective. In the J2EE Navigator view,
right-click AuctionWeb and select Team > Synchronize with
Repository.
- In the Structure Compare pane, right-click AuctionWeb and select Update
from Repository. This moves all of the work that was done in the Web
designer's workspace into the original developer's workspace.
- To set debugging preferences, from the main menu click Window >
Preferences > WAS Debug.
- Clear the Use step-by-step debug mode check box and click OK.
- Right-click the AuctionWeb project and select Debug on Server.
The Server selection wizard opens.
- Click Advanced.
- Click the Use an existing server radio button.
- Select TestServer and click Finish.
- The Debug perspective opens. The entire application is automatically
deployed and the Online Auction home page opens up in the browser window
(which may take a moment or two). The URL is http://localhost:9080/AuctionWeb.:

Now that you have the application running on the test server, you can set
breakpoints and debug the application while it is running. To learn about how
search results are displayed in the application and debug a JSP file:
- From the main menu, click Window > Show View> J2EE Navigator.
The J2EE Navigator view opens.
- In the J2EE Navigator view, expand AuctionWeb and Web Content,
then double-click FloralResults.jsp to open the JSP file in the
source editor.
- Click the Source tab and then locate the following line of code
(around line 46):
com.acme.common.SearchResultBean r = results[i];
- Right-click the left margin beside the line of code, and select Add
breakpoint from the pop-up menu.
- Switch back to Web Browser.
- In the search by price field, type 100 and then click the Go
button.
- In the Variables view, browse some of the variables in the JSP
file.
- In the Debug view, click the Step Over icon
to step through some of the code.
- Right-click the breakpoint and select Remove Breakpoint.
- Click the Resume icon
to finish running the program. (Note that if you need to make changes to
your JSP files or to other classes in the Web project, the test environment
will detect the changes and automatically reload the files or classes.)
To learn how the business methods work, such as the makeBid method:
- Expand the AuctionEJB, ejbModule, and com.acme.ejb,
then double-click ItemHelperBean.java to open the source editor.
- Set a breakpoint beside the following line in the makeBid method (and
ensure that you put it in the makeBid method, since the line also appears in
other methods):
Status status = new Status();
- Switch back to Web Browser and then click the round Bid
button beside one of the flower items for sale.
- In the Your Name field, type your name.
- In the Your Bid field, type 250 and click the round Bid
button.
- In the Debug view, expand the suspended thread that has the + symbol
beside it, then click the ItemHelperBean.makeBid line.
- Examine some variables in the Variables view.
- In the Debug view, single-step through some code by clicking the Step
Over icon.
- Remove the breakpoint that you set in the source code.
- In the Debug view, click the Resume icon.
- Close the open files and the Web browser.
- Switch to the J2EE perspective and click the Servers tab to open
the Servers view.
- In the Server column, select the TestServer server and then click
the Stop icon.
- If you plan to run the ready-made sample application (as described in Part
1) after building the sample application for yourself from scratch, then you
need to remove the Auction project from the server configuration by
completing the following steps:
- In the Server Configuration view, expand Server Configurations
and expand TestServer, then right-click Auction and select
Remove Project.
(Note that if you make changes to your enterprise bean code, you will need to
right-click the EAR project and select Restart Project.)
Congratulations! You have built the Online Auction sample application and run
it in the WebSphere Studio unit test environment. You learned how to create
various types of enterprise beans that hold the business logic of the
application, create and configure servers that connect to a database, test the
business methods in the test client, work in a team environment using a CVS
repository, and test and debug the application in a test environment.