Test and debug enterprise components

This page discusses - Test and debug enterprise components

Test and debug enterprise components

Test and debug enterprise components

Generating EJB deployment code from the workbench

Before you can successfully run your enterprise beans on either a test or production server, you need to generate deployment code for the enterprise beans.

Note: If your EJB project contains CMP beans that have not been mapped, a default top-down mapping is created when you generate the deployment code.

Important:

  • Make sure that your bean classes compile cleanly (that is, there are no compilation errors). Then run validation. Now, you can deploy the beans.

  • If you have turned automatic validation off, it is strongly recommended that you manually validate your enterprise beans before you generate deployment code for them. If you validate your beans and any validation errors are reported, you must not generate deployment code until the errors are fixed. However, if you validate your beans and only warning or information messages are received, you can generate deployment code for the beans.

  • You can generate deployment code either for individual enterprise beans that you have modified or added newly to the project or you can generate deployment code for the entire EJB project. Note however, that when you generate deployment code for the entire project, the EJB deployment tool picks up only the new entities or changes that have been made to the project.

To generate deployment code for an EJB project:

  1. If you have changed the class path of any EJB project, ensure that your EJB project's source folder appears at the beginning of the project's class path. (The EJB Import wizard imports both the JAR file and the JAR file's source code into the workbench, so the correct order of the entries on the class path is an important consideration.)

  2. In the Project Navigator view, right-click the project (or the EJB JAR, if you are in the J2EE Hierarchy view) that contains the enterprise beans for which you want to generate deployment code, then select Generate > Deployment and RMIC code. The Generate Deployment and RMIC Code wizard appears.

    Deploy and RMIC code
  3. By default, only those enterprise beans that have changed and require updated deployment code are selected in the wizard. If you want to select or remove from the selection those enterprise beans that are listed, complete one of the following tasks:

    • Manually select or clear the check box beside the name of any enterprise bean.

    • Click Select all to automatically select all of the enterprise beans that are listed on the page.

    • Click Deselect all to automatically clear all of the enterprise beans that are listed on the page.

    • Click Default to automatically select only those enterprise beans that have changed and require updated deployment code.

    Deploy and RMIC code
  4. Click Finish. By default, the deployment code is generated in the ejbModule source folder. To change the source folder that deployment code is generated into, use the EJB Deployment property page for the EJB project. If there is a problem with the generation of RMIC code, a Cannot Generate Code for Deployment window appears where you can read any error messages that are associated with the problem.

To generate deployment code for an enterprise bean:

  1. In the J2EE Hierarchy view, right-click the enterprise bean for which you want to generate deployment code, then select Generate Deployment Code.

  2. Code is generated into the folder where your enterprise beans are located.

After the deployment code is generated, you can export your enterprise beans to a JAR or EAR file for installation on an EJB server, such as the WebSphere Application Server.

Testing EJB projects using an existing test environment

If you are testing your files on a machine that already has a server and server configuration defined, the server tools search for a compatible server that it can use.

  1. Expand the EJB Modules that contains the module you want to test (titan).

  2. Right-click an EJB module that you want to test.

    EJB module
  3. Select Run on Server.... The Server selection wizard opens.

  4. Select the Use an existing server radio button and select the server you previously created.

    Use an existing server
  5. Click Next to configure additional settings (optional).

  6. On the Select Tasks page, select the Create tables and data sources check box to automatically create tables and data sources for CMP bean testing (optional). This check box will not appear if you do not have any CMP beans in your EJB project. When a dialog box informs you that the tables were successfully created, click OK.

    Select the Deploy EJB beans check box to generate EJB deployment code (optional).

    Deploy EJB beans
  7. Click Finish. The server tools automatically do the following tasks for you: 0

    • If the Automatically publish before starting servers check box on the Server preferences page (Window > Preferences > Server) is selected, the server tools check to see if your project and files on the server are synchronized. If they are not, the project and the files are automatically updated on the remote machine when the server is restarted.

    • Starts the server. (This may take time depending on the server configuration settings.)

    • Displays the enterprise bean in the Universal Test Client (UTC). 1

Now, you can test your beans in the Universal Test Client.

If you have made any changes to the files while you tested your project, you may need to restart the server.

Testing enterprise beans in the universal test client 2

The server tools provide you with a Web-based Universal Test Client (UTC) where you can test your enterprise beans and Java classes.

To use the Universal Test Client:

  1. Create a WebSphere server and configuration. 3

  2. Add a project to the server.

  3. To ensure that the server is enabled to use the Universal Test Client:

    1. In the Server Configuration view, double-click your server. The server editor opens. 4

    2. Select the Configuration tab.

    3. Select the Enable universal test client check box.

      Enable universal test client
    4. Close the editor and save your changes. 5

  4. Start a server.

  5. To start the Universal Test Client:

    1. In the J2EE Hierarchy view, right-click on an EJB module (titan). 6

    2. Select Run on Server. The Universal Test Client opens in the Web Browser.

      Universal Test 	Client

      Server's log during startup:

      [26.07.05 15:13:40:470 EEST] 3d1557d1 ApplicationMg A WSVR0200I: Starting application: IBMUTC
      [26.07.05 15:13:40:501 EEST] 3d1557d1 WebContainer  A SRVE0169I: Loading Web Module: IBM Universal Test Client.
      [26.07.05 15:13:40:595 EEST] 3d1557d1 WebGroup      I SRVE0180I: [IBM Universal Test Client] [/UTC] [Servlet.LOG]: JSP 1.2 Processor: init
      [26.07.05 15:13:40:611 EEST] 3d1557d1 WebGroup      I SRVE0180I: [IBM Universal Test Client] [/UTC] [Servlet.LOG]: SimpleFileServlet: init
      [26.07.05 15:13:40:611 EEST] 3d1557d1 ApplicationMg A WSVR0221I: Application started: IBMUTC
      											
  6. Use the Universal Test Client to perform one or more of the following tasks:

    • Finding an enterprise bean or class 7

    • Calling a method

    • Removing an enterprise bean or class

    • Viewing fields 8

    • Filtering the methods displayed

    • Changing the property settings

  7. When you have finished using the Universal Test Client, close it. 9

Finding an enterprise bean

In order to test an enterprise bean in the Universal Test Client, you must locate it on your server. If you know the JNDI name of your enterprise bean, you may use the JNDI Explorer page to directly type the name. Otherwise, use the graphical view on the JNDI Explorer page to browse the JNDI hierarchy of your server and locate the enterprise bean.

Special objects within the hierarchy are displayed with different icons. For example, enterprise beans are displayed as a bean. Selecting a bean automatically loads the EJB home into the EJB Page. Data sources and user transactions are loaded into the JNDI Objects page. Selecting a URL will browse to that URL. 0

Use the JNDI Explorer page of the Universal Test Client to find an enterprise bean on a server when you know the JNDI name of the EJB file. The JNDI Explorer page allows you to load an enterprise bean that you want to test by directly typing in the JNDI name of the enterprise bean.

If you want to find an enterprise bean, but you do not know the JNDI name, you should use the graphical representation of the JNDI server's namespace that is located on the JNDI Explorer page. The Root contexts in the JNDI namespace are displayed as folders and allow you to browse through the hierarchy:

  1. To find the JNDI name of the enterprise bean when the JNDI name is known: 1

    1. On the Universal Test Client toolbar, select the JNDI Explorer icon on the toolbar. The JNDI Explorer page appears.

    2. In the JNDI Name field, type the JNDI name of the enterprise bean that you want to test.

    3. Click Lookup. Depending on the type of object that was entered, the appropriate page displays. For example, if a bean was entered, then the Bean page of the test client opens displaying all the methods for that particular EJB. 2

  2. To find the JNDI name of the enterprise bean when the JNDI name is unknown:

    1. On the Universal Test Client toolbar, select the JNDI Explorer icon. The JNDI Explorer page appears showing a list of the JNDI server's namespace.

      JNDI Explorer
    2. Click the JNDI name of the enterprise bean that you want to test. Depending on the type of object that was entered, the appropriate page displays. For example, if a bean was entered, then the EJB page of the test client opens displaying all the methods for that particular EJB. 3

      EJB page

If an enterprise bean with a remote view does not appear in the JNDI Explorer, then it is not correctly deployed in the server. There are a number of causes of this problem, including not generating deploy and RMIC code, not deploying the EJB JAR file to the EAR file correctly, and incorrect deployment descriptors in either the EJB JAR file or EAR file.

If an enterprise bean is not a selectable link in the JNDI Explorer, then there are two possible causes to this problem:

  • The object you are looking at may not be an enterprise bean. Make sure you have the JNDI name correct and that you are looking at the correct object. 4

  • The client side EJB classes may not be available to the Universal Test Client. If you are not running the test client on the same server as the enterprise beans are deployed to, make sure you add the EJB client JAR file to the server's class path before starting the Universal Test Client.

Calling a method

The Bean page of the Universal Test Client allows you to invoke methods on EJB classes, as well as other objects. 5

To call a method:

  1. In the Universal Test Client, click the Bean page icon on the toolbar. The Bean page opens displaying all the methods.

  2. In the References pane of the Bean page, select a method. The Parameters pane displays all the parameters for that particular method. 6

  3. (Optional) If the parameter is a primitive type, the field is enabled allowing you to change its value.

  4. (Optional) If the parameter is a complex type, select an existing object or null from the Object drop-down list (for example if you are testing a JavaBean), or select a constructor from the Constructors drop-down list, and expand the parameter until you are able to enter a value in the Value column.

  5. Click the Invoke button to invoke the method: 7

    Invoke

    The Results section displays one of the following results of the method invocation depending on the conditions:

    • Displays the value if the method returned a value. It also displays a Work with object link that allows you to place that object into the References pane. If more than one object is returned (for example a collection), it will also display a Work with Contained Objects link

      Work with object link
    • Displays an error message if the method threw an exception. 8

    • Displays a Method executed successfully message if the method completes successfully but did not have any value to return.

You can invoke now methods on TravelAgent session bean:

  • sendReservation method: 9

    sendReservation

    Console output:

    [26.07.05 16:39:02:568 EEST] 683817d3 SystemOut     O TravelAgentBean: Cruise reservation sent
    [26.07.05 16:39:02:600 EEST] 1efa97d3 SystemOut     O ReservationProcessor: Customer: Mikalai Zaikin
    [26.07.05 16:39:02:600 EEST] 1efa97d3 SystemOut     O ReservationProcessor: Cruise: Hawaii
    								
  • createCabins method:

    createCabins

    Console output: 0

    [27.07.05 13:20:22:806 EEST] 55a2d7d3 SystemOut     O TravelAgentBean: cabins created
    								
  • createShips method:

    createShips

    Console output:

    [27.07.05 13:26:47:163 EEST] 29b997d0 SystemOut     O ShipBean: ejbCreate : [id = 1]
    [27.07.05 13:26:47:178 EEST] 29b997d0 SystemOut     O ShipBean: ejbCreate : [id = 2]
    [27.07.05 13:26:47:178 EEST] 29b997d0 SystemOut     O TravelAgentBean: ships created
    [27.07.05 13:26:47:194 EEST] 29b997d0 SystemOut     O ShipBean: ejbStore
    [27.07.05 13:26:47:225 EEST] 29b997d0 SystemOut     O ShipBean: ejbStore
    								
  • listCabins method: 1

    listCabins

    Console output:

    [27.07.05 13:28:34:287 EEST] 55a2d7d3 SystemOut     O TravelAgentBean : Cabin # 1
    [27.07.05 13:28:34:287 EEST] 55a2d7d3 SystemOut     O  name : Master Suite
    [27.07.05 13:28:34:287 EEST] 55a2d7d3 SystemOut     O  deck level : 1
    [27.07.05 13:28:34:287 EEST] 55a2d7d3 SystemOut     O  ship ID : 1
    [27.07.05 13:28:34:287 EEST] 55a2d7d3 SystemOut     O  bed count : 3
    [27.07.05 13:28:34:303 EEST] 55a2d7d3 SystemOut     O TravelAgentBean : Cabin # 2
    [27.07.05 13:28:34:303 EEST] 55a2d7d3 SystemOut     O  name : Suite
    [27.07.05 13:28:34:303 EEST] 55a2d7d3 SystemOut     O  deck level : 2
    [27.07.05 13:28:34:303 EEST] 55a2d7d3 SystemOut     O  ship ID : 1
    [27.07.05 13:28:34:303 EEST] 55a2d7d3 SystemOut     O  bed count : 5
    								
  • listShips method:

    listShips

    Console output: 2

    [27.07.05 13:30:33:239 EEST] 29b997d0 SystemOut     O ShipBean: ejbLoad
    [27.07.05 13:30:33:239 EEST] 29b997d0 SystemOut     O TravelAgentBean : Ship # 1
    [27.07.05 13:30:33:239 EEST] 29b997d0 SystemOut     O  name : Nordic Prince
    [27.07.05 13:30:33:239 EEST] 29b997d0 SystemOut     O  tonnage : 5000.0
    [27.07.05 13:30:33:239 EEST] 29b997d0 SystemOut     O  capacity : 300
    [27.07.05 13:30:33:286 EEST] 29b997d0 SystemOut     O ShipBean: ejbLoad
    [27.07.05 13:30:33:286 EEST] 29b997d0 SystemOut     O TravelAgentBean : Ship # 2
    [27.07.05 13:30:33:286 EEST] 29b997d0 SystemOut     O  name : Bohemian Rhapsody
    [27.07.05 13:30:33:286 EEST] 29b997d0 SystemOut     O  tonnage : 6000.0
    [27.07.05 13:30:33:286 EEST] 29b997d0 SystemOut     O  capacity : 400
    [27.07.05 13:30:33:286 EEST] 29b997d0 SystemOut     O ShipBean: ejbStore
    [27.07.05 13:30:33:302 EEST] 29b997d0 SystemOut     O ShipBean: ejbStore
    								
  • cleanup method:

    cleanup

    Console output:

    [27.07.05 13:32:19:754 EEST] 55a2d7d3 SystemOut     O ShipBean: ejbLoad
    [27.07.05 13:32:19:770 EEST] 55a2d7d3 SystemOut     O ShipBean: ejbRemove
    [27.07.05 13:32:19:770 EEST] 55a2d7d3 SystemOut     O ShipBean: ejbLoad
    [27.07.05 13:32:19:832 EEST] 55a2d7d3 SystemOut     O ShipBean: ejbRemove
    [27.07.05 13:32:19:832 EEST] 55a2d7d3 SystemOut     O TravelAgentBean: ships removed
    [27.07.05 13:32:19:926 EEST] 55a2d7d3 SystemOut     O TravelAgentBean: cabins removed
    								

Tutorials

  1. Appendix A. Additional materials
  2. WSAD 5.0 Practicing for IBM Test 000-287 Mind Map
  3. Deploy enterprise applications into servers
  4. Chapter 6. Assemble enterprise applications and deploy them in IBM WebSphere Application Server
  5. Configure resource and security-role references
  6. Design and develop custom tags
  7. Chapter 4. Demonstrate understanding of database connectivity and messaging within IBM WebShpere Application Server
  8. Chapter 5. EJB transactions
  9. Design and develop message-driven EJBs
  10. Design and develop entity EJBs
  11. Validate operational parameters of application server to support the enterprise application
  12. Chapter 1. Design, build and test reusable enterprise components
  13. Access container and server services from enterprise components
  14. Part I. Exam Objectives
  15. Explain implications of resource management on application design and implementation
  16. Manage end-user state and understand performance tradeoffs of using HTTP sessions
  17. Chapter 7. Validate, tune and troubleshoot an application within an IBM WebSphere Application Server environment
  18. Implement mechanisms for efficient inter-component calls
  19. IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide
  20. Chapter 3. Develop clients that access the enterprise components
  21. Implement Java clients calling Web Services
  22. Configure JMS connection factories and destinations
  23. Design, develop and test JSPs
  24. Use JTA to control transaction demarcation
  25. Manipulate transactional behavior of EJBs using deployment descriptors
  26. Implement mechanisms which support loose coupling between clients and components
  27. Identify misbehaving application components
  28. Preface
  29. WSAD 5.0 Practicing for IBM Test 000-287
  30. Part II. Appendixes
  31. Interact with connection pools to obtain and release connections
  32. Describe the effects of a server failure on the application
  33. Test and debug enterprise components
  34. Chapter 2. Design, build and test web components
  35. Chapter 2. Design, build and test web components