Working with the Online Auction sample application
(UML visualization for J2EE - Technical Preview Edition)

This topic tells you how to work with the Online Auction sample application by completing one or both of the following activities:

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.

Part 1 - Running the ready-made sample application

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:

  1. Open WebSphere Studio.
  2. Click the Open The New Wizard icon Picture of the Open the New wizard icon at the left end of the toolbar:
  3. In the left frame of the New wizard, expand Examples and select Enterprise Applications 1.3.
  4. In the right frame, select Auction and click Next.
  5. In the Project name field, accept the default name.
  6. Click Finish. Instructions for running the Online Auction sample application are automatically opened in the Web browser.
  7. Follow the instructions for running the sample application.

Part 2 - Building the sample application for yourself

To build the sample application, you must perform the following tasks:

These tasks are described in the sections below.

 

Create the required projects

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:

  1. Open WebSphere Studio.
  2. 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:
    1. Switch to the Server perspective (Window > Open Perspective > Server).
    2. In the Server Configuration view, expand Server Configurations and expand TestServer, then right-click AuctionExample and select Remove.
  3. Switch to the J2EE perspective (Window > Open Perspective > Other > J2EE).
  4. Click the Open The New Wizard icon Picture of the Open the New Wizard iconat the left end of the toolbar.
  5. In the left frame of the New wizard, select J2EE.
  6. In the right frame, select Enterprise Application Project and click Next.
  7. Select the Create J2EE 1.3 Enterprise Application project radio button and click Next.
  8. In the Enterprise application project name field, type Auction.
  9. Clear the Application client module check box.
  10. Accept the default names that appear in the EJB project name and Web project name fields and click Finish.
  11. 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:


    Picture of the projects in the J2EE Hierarchy view.

 

Add enterprise beans to the EJB project

In this section, you learn how to add the following enterprise beans to the AuctionEJB project:

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:

  1. In the J2EE Hierarchy view, right-click AuctionEJB and select Generate > EJB to RDB Mapping. The EJB to RDB Mapping wizard opens.
  2. Select Create a new backend folder and click Next.
  3. Select Bottom-up and click Next.
  4. The Database Connection page of the wizard appears. In the Database field, type dreamauc.
  5. For Linux In the User ID and Password fields, specify your DB2 user ID (for example, db2inst1) and password.
  6. In the JDBC driver field, ensure that the following driver is specified:

    IBM DB2 APP DRIVER

  7. In the Class location field, ensure that the correct path is specified for the JDBC driver and click Next. For example:

    For Windows C:\Program Files\SQLLIB\java\db2java.zip

    For Linux /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.

  8. Select the check box for the EJB.ONLINEITEM table and click Next:

    Picture of the database tables in the EJB to RDB mapping wizard.

  9. Select the Generate 2.0 enterprise beans radio button.
  10. In the Package for generated EJB classes field, type com.acme.ejb.
  11. Click Finish. A CMP entity bean named Onlineitem is created in AuctionEJB and the mapping editor opens.
  12. Close the mapping editor.

To create the home and remote interfaces:

  1. In the J2EE Hierarchy view, right-click AuctionEJB and select Open With > Deployment Descriptor Editor. The editor opens.
  2. Click the Beans tab and select Onlineitem.
  3. Scroll down to the Class and Interface Files section and click Add. The Add Client View dialog box opens.
  4. Select the Add new remote and remote home interfaces and Copy methods from local interfaces to remote interfaces checkboxes and click Finish.
  5. Save and close the deployment descriptor editor.

To create a UML class diagram view of the Onlineitem entity bean:

  1. In the J2EE Navigator view, right-click AuctionEJB and click New > Folder on the shortcut menu. The New Folder dialog box opens.
  2. In the Folder name field, type diagrams.
  3. Click Finish.
  4. In the J2EE Navigator view, select the AuctionEJB project.
  5. Click File > New > Class Diagram. The New Class Diagram dialog box opens.
  6. Select the folder AuctionEJB/diagrams.
  7. In the File name box, enter OnlineAuction.
  8. Click Finish. The Class Diagram Editor window opens.
  9. In the J2EE Hierarchy view, expand EJB Modules and AuctionEJB.
  10. Drag the Onlineitem entity bean to the Class Diagram Editor window. A UML view of the Onlineitem entity bean is created.
  11. 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.
  12. Save the UML class diagram.

To create an access bean:

  1. In the J2EE Hierarchy view, expand AuctionEJB, then select Onlineitem and click the Create an access bean icon Picture of the Create an access bean icon on the toolbar.
  2. 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.
  3. Click Next and ensure that AuctionEJB is specified in the EJB Project field.
  4. In the Enterprise Beans table, select the Onlineitem check box and click Next.
  5. Select the Onlineitem bean in the Enterprise beans text area.
  6. In the Interfaces to use group, click the Remote radio button.
  7. 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.
  8. Ensure that all of the check boxes in the Attribute helpers list box are selected:

    Picture of the Data Class Access Bean page of the Create an access bean wizard.

  9. 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:

  1. Select the OnlineAuction diagram in the Class Diagram Editor window.
  2. In the J2EE Navigator view, select the package AuctionEJB > ejbModule > com.acme.ejb.
  3. 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.
  4. On the shortcut menu, click the Arrange > All Elements.
  5. In the Class Diagram Editor window, right-click the the Onlineitem entity bean shape and click Filter > Show Operation Signature on the shortcut menu.
  6. Save the UML class diagram.

To create a session bean:

  1. 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.
  2. In the EJB Project box, select AuctionEJB and click Next.
  3. In the Bean name box, type ItemHelper and click Next.
  4. Select Container for the Transaction type.
  5. In the boxes on the Enterprise Bean Details page, enter the following values:
  6. 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.
  7. Save the UML class diagram.

 

Add the business logic to the session bean

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:

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:

To create a project to hold the contents of the zipped project that you will import:

  1. Click the Open The New Wizard icon at the left end of the toolbar.
  2. In the left frame of the New wizard, select Simple.
  3. In the right frame, select Project and click Next.
  4. In the Project name field, type AuctionSamples.
  5. Click Finish. The Resource perspective opens and the project AuctionSamples is added to the workbench.

To import the zipped project:

  1. From the File menu, select Import to open the Import wizard, then select Zip file and click Next.
  2. 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):

    For Windows install_path\samples\scenario_parts\auction\AuctionSample.zip

     

    For Linux /opt/IBM/WebSphereStudio/samples/scenario_parts/auction/AuctionSample.zip

    Click Open.

  3. Beside the Folder field, click Browse and select the AuctionSamples folder, then click OK.
  4. Click Finish. The files contained in AuctionSample.zip are imported into the AuctionSamples project.

To import the supporting classes from the zipped project:

  1. From the File menu, select Import to open the Import wizard again, then select Zip file and click Next.
  2. 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):

    For Windows workspace_path\workspace\AuctionSamples\setup\Server-support.zip

     

    For Linux /home/workspace_path/workspace/AuctionSamples/setup/Server-support.zip

    Click Open.

  3. Beside the Folder field, click Browse and expand AuctionEJB, then select ejbModule and click OK.
  4. 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:

  1. In the Navigator view, expand AuctionSamples and the setup folder, then double-click ItemHelperBean.java to open the source editor.
  2. In the editor, copy the entire contents of the class to the clipboard, then close the editor.
  3. Switch to the J2EE perspective.
  4. In the J2EE Hierarchy view, expand EJB Modules, AuctionEJB, and ItemHelper, then double-click ItemHelperBean. The class opens in the Java editor.
  5. In the editor, replace the entire contents of the class by pasting in the contents that you copied to the clipboard.
  6. 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.)
  7. In the Outline view, expand ItemHelperBean and select the create, findByValue, makeBid, and reserveKeys methods together:

    Picture of the methods in the Outline pane.

  8. 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.

  9. Close the editor.
  10. In the J2EE Hierarchy view, double-click the ItemHelper class. The source editor opens.
  11. 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;
    
  12. 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:

  1. 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.
  2. Click the Beans tab, and then select Onlineitem.
  3. Scroll down to the Queries section and click Add. The Add Finder Descriptor dialog box opens.
  4. Select New for the method.
  5. Select find method for the method type.
  6. Select Remote for the type.
  7. In the Name box, type findByValue.
  8. Click the Add button beside the Parameters list box. The Add Method Parameter dialog box opens.
  9. In the Name box, type value.
  10. In the Type box, select long and click OK.
  11. In the Return type box, select java.util.Collection and click Next.
  12. 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.

  13. Click File > Save EJB Deployment Descriptor to save the changes, and then close the deployment descriptor editor.
  14. Arrange the diagram so that it appears as the image below.
  15. 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:

  1. Right-click AuctionEJB and select Generate > Deploy and RMIC code.
  2. Click Select all to mark both the Onlineitem and ItemHelper beans for code generation:

    Picture of the Generate Deploy and RMIC Code wizard.

  3. Click Finish to generate the deploy and RMIC code. This code is needed to deploy the EJB module to a server.

 

Create a server and add a data source

To configure the EJB module to use the correct data source for the auction database:

  1. In the J2EE Hierarchy view, right-click AuctionEJB.
  2. Select Open With > Deployment Descriptor Editor.
  3. Scroll down to the JNDI -- CMP Factory Connection Binding section.
  4. In the JNDI name field , type jdbc/dreamauc for the data source JNDI name.
  5. 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.


    Picture of the WebSphere Bindings section of the deployment descriptor editor.

  6. In the Backend ID section, click Refresh and ensure the value in the Current field is DB2UDBNT_V72_1.
  7. Click File > Save EJB Deployment Descriptor and then close the deployment descriptor editor.

To create and configure a server:

  1. 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.
  2. In the Server Name field, type TestServer.
  3. In the Folder field, select Servers from the drop-down menu.
  4. In the Server type list box, expand WebSphere version 5.0 and select Test Environment.
  5. Click Finish to create the server.
  6. For Linux In the J2EE Hierarchy, expand Servers.
  7. For Linux Double-click TestServer. The server configuration editor opens.
  8. For Linux 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.
  9. For Linux 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:

To define a JAAS authentication entry:

  1. In the J2EE Hierarchy, expand Servers.
  2. Double-click TestServer. The server configuration editor opens.
  3. At the bottom of the editor, click the Security tab.
  4. In the JAAS Authentication Entries section, click Add. The JAAS Authentication Entry dialog opens.
  5. In the Alias field, type your DB2 user ID. For LinuxFor Linux this is db2inst1.
  6. In the User ID field, type your DB2 user ID again. For LinuxFor Linux this is db2inst1.
  7. In the Password field, type your DB2 password then click OK.

To add a data source and define its resource properties:

  1. At the bottom of the editor, click the Data Sources tab.
  2. Scroll down to the Server Settings section. In the JDBC provider list, select Default DB2 JDBC Provider.
  3. 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.
  4. 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.
  5. In the Name field, type dreamauc.
  6. In the JNDI name field, type jdbc/dreamauc.
  7. In the Description field, type Dream Auction Database.
  8. In the Category field, type Examples.
  9. In the Data source helper class name field, select com.ibm.websphere.rsadapter.DB2DataStoreHelper.
  10. In the Component-managed authentication alias field, select the alias that you defined earlier.
  11. Select the Use this data source in container managed persistence (CMP) check box and click Next.
  12. In the Resource Properties field, select select databaseName
  13. In the Value field, type dreamauc and click Finish.
  14. 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:

  1. In the J2EE Hierarchy, expand Servers.
  2. Double-click TestServer. The server configuration editor opens.
  3. Click the Environment tab.
  4. Beside the System Properties list table, click Add. The Add System Property dialog box opens.
  5. In the Name field, type client.encoding.override.
  6. In the Value field, type UTF-8 and click OK.
  7. Click File > Save TestServer to save the configuration, then close the editor.

 

Test the business methods

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:

  1. For Linux From the Window menu, select Preferences. The Preferences page appears.
  2. For Linux 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
  3. For Linux Click OK to close the Preferences page.
  4. In the J2EE Hierarchy view, expand EJB Modules and expand AuctionEJB, then select ItemHelper Picture of the ItemHelper bean.
  5. For Windows For Linux Right-click ItemHelper and select Run on Server to start the server. The Server Selection wizard appears.
  6. Click Advanced.
  7. 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.
  8. It may take a moment or two for the test client to appear, since all of the following tasks are being performed automatically:

    Since the server was launched on a specific enterprise bean, the Universal test client is opened on the bean in the browser window:

    Picture of the Item Helper bean in the References pane of the EJB Test Client.

Now you will invoke methods and pass parameters to objects to place a bid.

  1. 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.
  2. 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:

    Picture of the ItemHelper object in the Parameters pane of the EJB Test Client.

  3. Click Work with Object. This adds the ItemHelper instance to the References pane.
  4. In the References pane, expand ItemHelper (1) and click the Status makeBid method link.
  5. In the Parameters pane, expand the parameters and type the following values in the Value column:

    Picture of the Parameters pane of the EJB Test Client

    The values specified for the parameters (which you can view in the source code) have the following interpretations:

  6. 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.

  1. Above the Parameters pane, click the JNDI Explorer icon Picture of the JNDI icon to open the JNDI Explorer.
  2. Expand the following folders: ejb/com/acme/ejb.
  3. Click the OnlineitemHome link:

    Picture of the OnlineitemHome link at the bottom of the JNDI Explorer.

  4. In the References pane, expand OnlineitemHome and click the Onlineitem findByPrimaryKey(OnlineitemKey) link.
  5. In the Parameters pane, expand com.acme.ejb.OnlineitemKey and OnlineItemKey.Itemtypeid appears in the Parameters column.
  6. 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.)


    Picture of the OnlineitemKey in the Parameters pane of the Universal Test Client.

  7. Click Work with Object. This places the item that you found in the previous step in the References pane.
  8. In the References pane, expand Onlineitem and click the String getLastbidder() method.
  9. In the Parameters pane, click Invoke.
  10. Ensure that the resulting string is correct. It should be the name of the bidder (Gary).
  11. If you want, you can continue to explore the features of the test client by invoking more methods.
  12. When you are finished exploring, in the Servers perspective, click the Servers tab to switch to the Servers view.
  13. In the Server column, select the TestServer server and then click the Stop icon Picture of the Stop icon.
  14. Close the browser session where the Universal Test Client is running.

 

Set up the team environment

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").

  1. Open the CVS Repository Exploring perspective (Window > Open Perspective > Other > CVS Repository Exploring).
  2. 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.)
  3. In the Host field, type the host name or IP address of the team server.
  4. In the Repository path field, type the fully qualified directory name of the CVS repository on the server. For example:

    For WindowsD:\CVS\CVSROOT

    For Linuxusr/local/cvsroot

  5. In the User field, type in your team server user name.
  6. In the Password field, type in your CVS password
  7. In the Connection type field, ensure that the correct connection type is selected:

    Picture of the Add CVS Repository wizard.

  8. Click Finish.

To prevent the class files from being stored in CVS, and save space in the repository:

  1. From the main menu, click Window > Preferences > Team > Ignored Resources.
  2. Click the Add button beside the Ignore Patterns pane. The Enter Ignore Pattern dialog box opens.
  3. Type *.class and click OK.


    Picture of the Ignored Resources preference page

  4. 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:

  1. From the main menu, click Window > Preferences > Workbench > Label Decorations.
  2. In the Available label decorations list box, click the CVS check box.
  3. Click OK on the Preferences page to save your changes.

 

Version the application

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").

  1. Switch to the J2EE perspective.
  2. In the J2EE Navigator view, select the Auction project.
  3. Right-click and select Team > Share Project. The Share Project wizard opens.
  4. Select CVS and click Next.
  5. Select the existing repository and click Next.
  6. Click the Use project name as module name radio button and click Next.
  7. Click Finish to import the project into the CVS repository. The Synchronize view opens.
  8. In the Structure Compare pane, right-click Auction and then select Commit.
  9. 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.)
  10. 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.
  11. Switch to the CVS Repository Exploring perspective.
  12. In the CVS Repositories view, click the Refresh View icon Picture of the Refresh icon. Expand the connection and expand HEAD.
  13. 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.
  14. In the Please enter a version tag field, type V1 and click OK.
  15. In the CVS Repositories view, expand Versions and then expand Auction to see the new version.

 

Add shared projects to another workspace

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".)

  1. 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.
  2. 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:
    1. Close your current workspace by exiting WebSphere Studio.
    2. Start WebSphere Studio. You are prompted to specify a directory for your workspace. Type the location of a new workspace. For example:

      For Windows workspace_path\workspace2

      For Linux /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.
  3. Open the CVS Repository Exploring perspective.
  4. 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.)
  5. In the Host field, type the host name or IP address of the team server.
  6. In the Repository path field, type the fully qualified directory name of the CVS repository on the server. For example:

    For WindowsD:\CVS\CVSROOT

    For Linuxusr/local/cvsroot

  7. In the User field, type in your team server user name.
  8. In the Password field, type in your CVS password.
  9. In the Connection type field, ensure that the correct connection type is selected and click Finish.
  10. Add CVS label decorations as previously described in the Set up the team environment section.
  11. 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 .
  12. Clear the Prune empty directories check box and click OK to exit the Preferences page.
  13. 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:

  1. Open the Server perspective.
  2. From the main menu, select File > New > Server Project. The Create a New Server project wizard opens.
  3. In the Project Name field, type Servers and click Finish. A new server project is created.
  4. From the main menu, select File > New > Server and Server Configuration. The Create a New Server and Server Configuration wizard opens.
  5. In the Server Name field, type TestServer.
  6. In the Folder field, select Servers from the drop-down menu.
  7. In the Server type list box, expand WebSphere version 5.0 and select Test Environment.
  8. Click Finish to create the server.
  9. For Linux In the Server Configuration view, expand Servers.
  10. For Linux Double-click TestServer. The server editor opens.
  11. For Linux 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.
  12. For Linux 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:

To define a JAAS authentication entry:

  1. In the J2EE Hierarchy, expand Servers.
  2. Double-click TestServer. The server configuration editor opens.
  3. At the bottom of the editor, click the Security tab.
  4. In the JAAS Authentication Entries section, click Add. The JAAS Authentication Entry dialog opens.
  5. In the Alias field, type your DB2 user ID. For LinuxFor Linux this is db2inst1.
  6. In the User ID field, type your DB2 user ID again. For LinuxFor Linux this is db2inst1.
  7. In the Password field, type your DB2 password then click OK.

To add a data source and define its resource properties:

  1. At the bottom of the editor, click the Data Sources tab.
  2. Scroll down to the Server Settings section. In the JDBC provider list, select Default DB2 JDBC Provider.
  3. 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.
  4. 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.
  5. In the Name field, type dreamauc.
  6. In the JNDI name field, type jdbc/dreamauc.
  7. In the Description field, type Dream Auction Database.
  8. In the Category field, type Examples.
  9. In the Data source helper class name field, select com.ibm.websphere.rsadapter.DB2DataStoreHelper.
  10. In the Component-managed authentication alias field, select the alias that you defined earlier.
  11. Select the Use this data source in container managed persistence (CMP) check box and click Next.
  12. In the Resource Properties field, select select databaseName
  13. In the Value field, type dreamauc and click Finish.
  14. 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:

  1. In the J2EE Hierarchy, expand Servers.
  2. Double-click TestServer. The server configuration editor opens.
  3. Click the Environment tab.
  4. Beside the System Properties list table, click Add. The Add System Property dialog box opens.
  5. In the Name field, type client.encoding.override.
  6. In the Value field, type UTF-8 and click OK.
  7. Click File > Save TestServer to save the configuration, then close the editor.

 

Add a professional Web front end

In this section, you add a Web front end to your application that will include the following functions:

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:

  1. 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.
  2. 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:
    1. Click the Open The New Wizard icon at the left end of the toolbar.
    2. In the left frame of the New wizard, select Simple.
    3. In the right frame, select Project and click Next.
    4. In the Project name field, type AuctionSamples.
    5. Click Finish. The project AuctionSamples is added to the workbench.
    6. From the File menu, select Import to open the Import wizard, then select Zip file and click Next.
    7. 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).

      For Windows install_path\samples\scenario_parts\auction\AuctionSample.zip

       

      For Linux /opt/IBM/WebSphereStudio/samples/scenario_parts/auction/AuctionSample.zip

    8. Beside the Folder field, click Browse and select the AuctionSamples folder, then click OK.
    9. Click Finish. The files contained in AuctionSample.zip are imported into the AuctionSamples project.
  3. 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.
  4. 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):

    For Windowsworkspace_path\workspace\AuctionSamples\setup\AuctionWeb.war

     

    For Linux 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

  5. In the Web project group, select the Existing radio button.
  6. Click Browse, select the AuctionWeb project and click OK.
  7. Select the Overwrite existing resources without warning check box.
  8. 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
  9. 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.
  10. On the left frame of the Properties page, click Java JAR Dependencies.
  11. 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.
  12. If you completed the optional "Set up the team environment" and "Version the application" sections, then complete the following steps:
    1. In the Navigator view, right-click the AuctionWeb project, then select Team > Synchronize with Repository. The Synchronize view opens.
    2. In the Structure Compare pane, right-click AuctionWeb and then select Commit.
    3. 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.)
  13. 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.

 

Unit test the application

To run the application in the test environment:

  1. If you completed the steps in the section "Add shared projects to another workspace", then complete the following two steps:
    1. Switch to the J2EE perspective. In the J2EE Navigator view, right-click AuctionWeb and select Team > Synchronize with Repository.
    2. 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.
  2. To set debugging preferences, from the main menu click Window > Preferences > WAS Debug.
  3. Clear the Use step-by-step debug mode check box and click OK.
  4. Right-click the AuctionWeb project and select Debug on Server. The Server selection wizard opens.
  5. Click Advanced.
  6. Click the Use an existing server radio button.
  7. Select TestServer and click Finish.
  8. 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.:


    Picture of the AuctionDelight Web site running in the Web browser

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:

  1. From the main menu, click Window > Show View> J2EE Navigator. The J2EE Navigator view opens.
  2. In the J2EE Navigator view, expand AuctionWeb and Web Content, then double-click FloralResults.jsp to open the JSP file in the source editor.
  3. Click the Source tab and then locate the following line of code (around line 46):
    com.acme.common.SearchResultBean r = results[i]; 
    
  4. Right-click the left margin beside the line of code, and select Add breakpoint from the pop-up menu.
  5. Switch back to Web Browser.
  6. In the search by price field, type 100 and then click the Go button.
  7. In the Variables view, browse some of the variables in the JSP file.
  8. In the Debug view, click the Step Over icon Picture of the Step over icon to step through some of the code.
  9. Right-click the breakpoint and select Remove Breakpoint.
  10. Click the Resume icon Picture of 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:

  1. Expand the AuctionEJB, ejbModule, and com.acme.ejb, then double-click ItemHelperBean.java to open the source editor.
  2. 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();
    
  3. Switch back to Web Browser and then click the round Bid button beside one of the flower items for sale.
  4. In the Your Name field, type your name.
  5. In the Your Bid field, type 250 and click the round Bid button.
  6. In the Debug view, expand the suspended thread that has the + symbol beside it, then click the ItemHelperBean.makeBid line.
  7. Examine some variables in the Variables view.
  8. In the Debug view, single-step through some code by clicking the Step Over icon.
  9. Remove the breakpoint that you set in the source code.
  10. In the Debug view, click the Resume icon.
  11. Close the open files and the Web browser.
  12. Switch to the J2EE perspective and click the Servers tab to open the Servers view.
  13. In the Server column, select the TestServer server and then click the Stop icon.
  14. 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:
    1. 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.