Working with the Online Auction sample application

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 IBM Rational Developer. 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 IBM Rational Developer 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 Test the application section of Part 2.

To run the ready-made application:

  1. Click File > Import. The Import Wizard is displayed.
  2. Select WebLogic EAR file and click Next. The enterprise application import wizard is displayed.
  3. In the EAR file textbox, specify the following EAR file (where install_path is the directory where you have installed IBM Rational Developer):
    install_path\eclipse\plugins\com.ibm.etools.weblogic.scenario.auction.doc\Auction.ear
  4. In the Target server field, select your WebLogic Server version. Click Finish.
  5. In the Project Explorer, right-click AuctionEJB and select Properties. In the left pane, select Java Build Path, and then view the Libraries tab.
  6. Click Add External JARs and add the following files (where install_path is the directory where you have installed IBM Rational Developer):
    install_path\eclipse\plugins\com.ibm.etools.dbjars_6.0.0\jars\dbbeans.jar
    install_path\runtimes\base_v6_stub\lib\ivjejb35.jar
  7. View the Order and Export tab and check ivjejb35.jar to export the JAR to dependent projects.
  8. Click OK to close the Properties dialog.
  9. In the Project Explorer, expand AuctionEJB and double-click the Deployment Descriptor to open it in the EJB Deployment Descriptor Editor. View the WebLogic page.
  10. Select Onlineitem in the left column and ensure the following are true:
    JNDI Name: com/acme/ejb/OnlineitemHome
    Local JNDI Name: com/acme/ejb/OnlineitemLocalHome
    Data Source Name: jdbc/dreamauc
  11. Select ItemHelper in the left column and ensure the JNDI Name is com/acme/ejb/ItemHelperHome.
  12. Save the Deployment Descriptor Editor by selecting File > Save.
  13. From the menu, go Project > Build All.
  14. 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. 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 IBM Rational Developer.
  2. Switch to the J2EE perspective (Window > Open Perspective > Other > J2EE).
  3. 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 Auction project from the server by completing the following steps:
    1. In the Servers view, right-click the WebLogic server and select Add and remove projects.
    2. Remove Auction from the Configured projects list and click Finish.
  4. From the menu, go to File > New > Enterprise Application Project.
  5. In the Name field, type Auction.
  6. Click Show Advanced to show the advanced options.
  7. Set J2EE version to 1.3.
  8. Select a WebLogic server runtime in Target server. One should have been created in the Install IBM Rational Deployment Toolkit for WebLogic Server section of "Preparing for the Online Auction sample application".
  9. Click Next.
  10. Click the New Module button.
  11. Clear the Application Client project and Connector project check boxes.
  12. Accept the default names that appear in the EJB project and Web project fields and click Finish to create the EAR modules.
  13. Click Finish to create the enterprise application project.
  14. In the Project Explorer view, expand Enterprise Applications, Dynamic Web Projects, and EJB Projects 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.
  15. Right-click on the AuctionEJB project and select Properties from the context menu.
  16. In the left pane, select Validation.
  17. Clear the Override validation preferences check box and then clear the Run validation automatically when you save changes to AuctionEJB resources check box.
  18. Click OK to save your changes.

Add enterprise beans to the EJB project

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

To create a CMP entity bean in the EJB project:

  1. In the Project Explorer view, expand AuctionEJB.
  2. Right-click the Deployment Descriptor and select New > Enterprise Bean. The enterprise bean creation wizard opens.
  3. Ensure that the EJB project field is set to AuctionEJB.
  4. Select the Entity bean with container-managed persistence (CMP) fields radio button.
  5. Set the CMP version to 2.x.
  6. In the Bean name field, type Onlineitem.
  7. In the Default package field, type com.acme.ejb. Click Next.
  8. Select (check) the Remote client view checkbox.
  9. We now need to add the fields to the CMP bean:
    1. First, remove the default CMP field by selecting it in the CMP attributes list box and clicking Remove.
    2. Now, click the Add button to display the Create CMP Attribute dialog box.
    3. In the Name field, type itemtypeid.
    4. In the Type field, type java.lang.Integer.
    5. Select (check) the Key field checkbox. This will be the only key field in this bean. Click Apply.
    6. Enter the remaining field names and types shown in the table below. Click Close when you have finished entering the fields.
      Name Type
      catalognumber java.lang.Integer
      title java.lang.String
      description java.lang.String
      value java.lang.Long
      startingbid java.lang.Long
      imagelocn java.lang.String
      imagelocnsm java.lang.String
      lastbid java.lang.Long
      lastbidder java.lang.String
  10. Clear the Use the single key attribute type for the key class checkbox. Ensure that the Key class field contains the class com.acme.ejb.OnlineitemKey.
  11. Click Finish.

To map the CMP enity bean fields to the database:

  1. In the Project Explorer view, right-click AuctionEJB and select EJB to RDB Mapping > Generate Map.
  2. Select Create a new backend folder and click Next.
  3. Select Top-Down and click Next.
  4. Set the Target database to DB2 Universal Database V8.1.
  5. Enter SAMPLE as the Database name and ensure Generate DDL is checked.
  6. Click Finish. The Mapping Editor will open.
  7. The column mappings for each field should be set up up correctly already. Confirm this by clicking on each field in the Overview section, ensuring that the field and database column names match, as follows:
    Field Name DBMS Column
    itemtypeid ITEMTYPEID
    catalognumber CATALOGNUMBER
    title TITLE
    description DESCRIPTION
    value VALUE
    startingbid STARTINGBID
    imagelocn IMAGELOCN
    imagelocnsm IMAGELOCNSM
    lastbid LASTBID
    lastbidder LASTBIDDER
  8. Save and close the Mapping Editor.

To create a database schema and tables:

  1. In the Project Explorer view, the generated DDL script is found under the EJB project as ejbModule/META-INF/Table.ddl.
  2. Run the DDL script against your target database to create the tables and associations.

To create an access bean:

  1. In the Project Explorer view, expand AuctionEJB to view the Onlineitem EJB.
  2. Right-click Onlineitem and select New > Other > EJB > Access Bean. Click Next.
  3. 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.
  4. Click Next and ensure that AuctionEJB is specified in the EJB Project field.
  5. In the Enterprise Beans table, select the Onlineitem check box and click Next.
  6. Select the Onlineitem bean in the Enterprise beans text area.
  7. In the Interfaces to use group, click the Remote radio button.
  8. 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.
  9. Ensure that all of the check boxes in the Attribute helpers list box are selected.
  10. 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 create a session bean:

  1. In the Project Explorer view, expand AuctionEJB.
  2. Right-click the Deployment Descriptor and select New > Enterprise Bean. The enterprise bean creation wizard opens.
  3. Ensure that the EJB project field is set to AuctionEJB.
  4. Select the Session bean radio button.
  5. In the Bean name field, type ItemHelper and click Next.
  6. Check the Session type is set to Stateless. Ensure that Container is selected as the Transaction type.
  7. Ensure the fields on the Enterprise Bean Details page are filled in with the following values:
  8. Click Finish. A session bean named ItemHelper is created in the AuctionEJB project, which will be used to hold the application's business logic and serve as a front end for the Onlineitem CMP entity bean.

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. From the File menu, select New > Project.
  2. In the New Project wizard, expand Simple and select Project. Click Next.
  3. In the Project name field, type AuctionSamples.
  4. Click Finish. 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 From 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 IBM Rational Developer):
    install_path\eclipse\plugins\com.ibm.etools.weblogic.scenario.auction.doc\AuctionSample.zip
  3. Click Open.
  4. Beside the Into folder field, click Browse and select the AuctionSamples folder, then click OK.
  5. 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 From 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 IBM Rational Developer workspace):
    workspace_path\workspace\AuctionSamples\setup\Server-support.zip
  3. Click Open.
  4. Beside the Into folder field, click Browse and expand AuctionEJB, then select ejbModule and click OK.
  5. Click Finish. The files contained in Server-support.zip are imported into the ejbModule folder. (Any errors that appear in the Problems view will eventually be resolved as you continue walking through the instructions.)

To copy the business methods to the session bean:

  1. In the Project Explorer 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. Expand AuctionEJB, Deployment Descriptor, Session Beans, and ItemHelper, then double-click ItemHelperBean. The class opens in the Java editor.
  4. In the editor, replace the entire contents of the class by pasting in the contents that you copied to the clipboard.
  5. Click File > Save to save the revised source code. (Any errors that appear in the Problems view will eventually be resolved as you continue following the instructions.)
  6. In the Outline view, expand ItemHelperBean and select the create, findByValue, makeBid, and reserveKeys methods together:

    Picture of the methods in the Outline pane.

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

  8. Close the editor.
  9. In the Project Explorer view, double-click the ItemHelper class. The source editor opens.
  10. 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;
    
  11. 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. In the Project Explorer view, expand AuctionEJB and double-click Deployment Descriptor.
  2. Click the Beans page, and select Onlineitem.
  3. Scroll down to the Queries section and click Add. The Add Finder Descriptor wizard opens.
  4. Click the New radio button for the method.
  5. Click the find method radio button for the method type.
  6. Click the Remote check box for the type and uncheck Local.
  7. In the Name field, type findByValue.
  8. Click the Add button beside the Parameters list box. The Add Method Parameter dialog box opens.
  9. In the Name field, type value.
  10. In the Type field, select long and click OK.
  11. In the Return type field, select java.util.Collection and click Next.
  12. Type the following string into the Query statement text area 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 to save the changes, then close the deployment descriptor editor.

To set up the JNDI bindings for the EJBs:

  1. In the Project Explorer view, expand AuctionEJB and double-click Deployment Descriptor.
  2. View the WebLogic page.
  3. In the left pane of the editor, select Onlineitem.
  4. Change the JNDI Name field to com/acme/ejb/OnlineitemHome.
  5. Change the Local JNDI Name field to com/acme/ejb/OnlineitemLocalHome.
  6. Change the Data Source Name field to jdbc/dreamauc.
  7. In the left pane of the editor, select ItemHelper.
  8. Change the JNDI Name field to com/acme/ejb/ItemHelperHome.
  9. Save and close the editor.

Create a server and add a data source

In this section, you create a WebLogic server and configure it so that it can work with the auction application and the auction database.

To create a WebLogic server:

  1. In the J2EE perspective, right-click in the Servers view and select New > Server.
  2. The New Server wizard opens. This wizard will create a new server that will use your specified WebLogic server runtime.
  3. Click Next. If the selected WebLogic server type does not have a server runtime predefined in Preferences, a page will be presented for you to create the runtime. One should have been created in the Install IBM Rational Deployment Toolkit for WebLogic Server section of "Preparing for the Online Auction sample application". Note that this page will not be displayed if a server runtime was already created beforehand.
  4. Click Next. Fill in all the WebLogic Server settings. Ensure that the correct WebLogic Server administrator username and password is in the Username and Password fields.
  5. Click Finish. The new WebLogic server will appear in the Servers view.

To configure the server classpath:

  1. In the Servers view, double-click the WebLogic server to open the Server Editor.
  2. At the bottom of the editor, click the Classpath tab.
  3. In the editor, click Add External Jars and add the JAR containing the DB2 driver classes. For example:
    C:\Program Files\IBM\SQLLIB\java\db2java.zip
    C:\Program Files\IBM\SQLLIB\java\db2jcc.zip (for DB2 8.1)
  4. Similarly, add the JARs containing IBM Rational Developer classes required to run the the auction application on the WebLogic server (where install_path is the directory where you have installed IBM Rational Developer).
    install_path\eclipse\plugins\com.ibm.etools.dbjars_6.0.0\jars\dbbeans.jar
    install_path\runtimes\base_v6_stub\lib\ivjejb35.jar
  5. Click File > Save to save your changes.

Note: The exact paths for the JARs may vary according to where you have installed DB2 and IBM Rational Developer.

Set up the database connection pool and data source for the auction database (Note: The steps below are specific to WebLogic Server version 7.0, but the general steps and information can be applied to versions 6.1 and 8.1.):

  1. In the Servers view, right-click on the WebLogic server and select Start. This will start the WebLogic server; it may take a few moments for the server to start.
  2. After the WebLogic server has started, view the Overview page of the server editor (used in the previous steps).
  3. Click the Launch WebLogic Server console button in the editor.
  4. Login using the WebLogic Server administrator username and password. The WebLogic Server home page will now be displayed in a browser window.
  5. Under the Services Configurations section, click Connection Pools to configure a new connection pool using the following information:
    Name: DreamAucConnectionPool
    URL: jdbc:db2:DREAMAUC
    Driver Classname: COM.ibm.db2.jdbc.app.DB2Driver
    Properties: user=xxx;password=yyy where xxx is the user name to connect to the database with (e.g. db2admin) and yyy is the password to connect with
  6. Click Create and then select the Targets tab to enable the connection pool for the target server.
  7. Navigate back to the homepage by clicking the Home icon in the top-right corner of the page.
  8. Under the Services Configurations section, click Tx Data Sources or (Data Sources in WLS 8.1) to configure a new JDBC TX Data Source using the following information:
    Name: DreamAucDataSource
    JNDI Name: jdbc/dreamauc
    Pool Name: DreamAucConnectionPool
  9. Click Create and then select the Targets tab to enable the connection pool for the target server.
  10. Close the WebLogic Server console.

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. In the Project Explorer view, expand EJB Projects, AuctionEJB, Deployment Descriptor, Session Beans, and then select ItemHelper.
  2. Right-click ItemHelper and select Run > Run on Server to start the server. The Server Selection wizard appears.
  3. Click the Choose an existing server radio button. Select the WebLogic server and click Next.
  4. Add the Auction enterprise application project to the server by moving it to the right pane.
  5. Click Finish.
  6. It may take a moment or two for the test client to appear, since all of the following tasks are being performed automatically:

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

  1. In the Universal Test Client, click JNDI Explorer to open the JNDI Explorer.
  2. On the JNDI Explorer page, in the JNDI Name field, type com/acme/ejb/ItemHelperHome.
  3. In the left left pane, expand ItemHelper and ItemHelperHome, then click the ItemHelper create() link. This prepares the test client to invoke the create method.
  4. 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.

  5. Click Work with Object. This adds the ItemHelper instance to the left pane.
  6. In the left pane, expand ItemHelper (1) and click the Status makeBid method link.
  7. 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:

  8. 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. Click JNDI Explorer to open the JNDI Explorer.
  2. On the JNDI Explorer, in the JNDI Name field, type com/acme/ejb/OnlineitemHome.
  3. In the left pane, expand OnlineitemHome and click the Onlineitem findByPrimaryKey(OnlineitemKey) link.
  4. In the Parameters pane, expand com.acme.ejb.OnlineitemKey and OnlineItemKey. Itemtypeid appears in the Parameters column.
  5. 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.

  6. Click Work with Object. This places the item that you found in the previous step in the left pane.
  7. In the left pane, expand Onlineitem and click the String getLastbidder() method.
  8. In the Parameters pane, click Invoke.
  9. Ensure that the resulting string is correct. It should be the name of the bidder (Gary).
  10. If you want, you can continue to explore the features of the test client by invoking more methods.
  11. When you are finished exploring, in the J2EE perspective, click the Servers tab to switch to the Servers view.
  12. Select the WebLogic server and then click the Stop toolbar button.
  13. 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:
    D:\CVS\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 Project Explorer 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 toolbar button. 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 IBM Rational Developer 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 IBM Rational Developer.
    2. Start IBM Rational Developer. You are prompted to specify a directory for your workspace. Type the location of a new workspace. For example:

      workspace_path\workspace2

    IBM Rational Developer 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:
    D:\CVS\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 IBM Rational Developer 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 WebLogic Server, see the section Create a server and add a data source .

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. From the File menu, select New > Project.
    2. In the New Project wizard, expand Simple and select Project. Click Next.
    3. In the Project name field, type AuctionSamples.
    4. Click Finish. The project AuctionSamples is added to the workbench.
    5. From the File menu, select Import to open the Import wizard, then select Zip file and click Next.
    6. Beside the From 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 IBM Rational Developer):
      install_path\eclipse\plugins\com.ibm.etools.weblogic.scenario.auction.doc\AuctionSample.zip
    7. Click Open.
    8. Beside the Into 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 WebLogic 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 IBM Rational Developer workspace):

    workspace_path\workspace\AuctionSamples\setup\AuctionWeb.war

  5. In the Web project field, select the AuctionWeb project from the drop-down list.
  6. Select the Overwrite existing resources without warning check box.
  7. Click Finish. The WAR file is imported into the AuctionWeb project. Any errors or warnings that appear in the Problems view will be resolved as you complete the instructions
  8. 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.
  9. On the left frame of the Properties page, click Java JAR Dependencies.
  10. 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.
  11. If you completed the optional Set up the team environment and Version the application sections, then complete the following steps:
    1. In the Project Explorer 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.)
  12. 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 IBM Rational Developer tools to enhance the application. At this point in the tutorial you should now close the second workspace and open your original IBM Rational Developer workspace by exiting and restarting IBM Rational Developer with your original workspace.

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 Project Explorer 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. Right-click the AuctionWeb project and select Debug > Debug on Server. The Server selection wizard opens.
  3. Click the Choose an existing server radio button. Select the WebLogic server and click Next.
  4. Add the Auction enterprise application project to the server by moving it to the right pane.
  5. Click Finish.
  6. 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:7001/AuctionWeb.

    Picture of the AuctionDelight Web site running in the Web browser

Now that you have the application running on the test WebLogic server, you can set breakpoints and debug the application while it is running.

To learn how the business methods work, such as the makeBid method:

  1. In the Project Explorer, expand 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 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. Select the WebLogic server and then click the Stop toolbar button.
  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 Servers view, right-click the WebLogic server and select Add and remove projects.
    2. Remove Auction from the Configured projects list and click Finish.

(Note that if you make changes to your enterprise bean code, you will need to republish to the server.)

Congratulations! You have built the Online Auction sample application and run it in the IBM Rational Developer 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.

Terms of use | Feedback
(C) Copyright IBM Corporation 2002, 2004. All Rights Reserved.