Working with Enterprise JavaBeans

Testing an EJB with Java Explorer involves the following three main steps:
  • Connecting to the Java Name Service (JNDI)
  • Selecting an EJB Home object that is registered at the Naming Service and can be used as the factory object
  • Creating an EJB on the application server

To test an EJB:

  1. In the Workflow bar, click Start Here. The Load File Wizard opens.
  2. Alternative: In the Classes pane, right-click Remote Objects and choose New EJB to start the EJB Wizard directly. In this approach, skip the next two steps.
  3. Click the Enterprise JavaBeans / RMI over IIOP option button.
  4. Click Next. The Connect to Naming Server dialog box opens.
  5. If available, select the application server vendor from the Server list box.
    Note: The entries in the list work as a template that pre-configures other settings, like initial context factory, protocol, and port, with default values. For additional information regarding the configuration of specific application server types, see Vendor-Specific JNDI Settings.
  6. In the Factory text box, specify the context factory of the naming service.
  7. In the Host/Port text boxes, type the URL where the naming service provider is to be hosted. The naming server provider URL is comprised by protocol, host, and port. You can also type the URL directly into the Provider URL text box.
  8. If required by the provider, type the credentials in the User and Password text boxes.
  9. Click Edit Classpath .... The Classpath Configuration dialog box opens.
  10. Choose Static and click Add entries to classpath to specify the archives that are necessary to connect to the naming service of the application server.
  11. Choose Dynamic and click Add entries to classpath to specify the archives that contain the client stubs of the application. For vendor-specific details, refer to the application server documentation. For additional information on classpaths, see Classpath Settings.
  12. Click OK.
  13. Back on the EJB Wizard, click Next to connect to the naming service. The Look up and narrow a Home Interface or Remote Object dialog box opens.
  14. In the naming service sub-folders, select the EJB Home interface, represented by a "hand holding a coffee bean" icon, or the remote object, represented by a satellite dish icon, for which Java Explorer should obtain a reference. The corresponding client stubs must have been added to the classpath of the project.
  15. Click Finish. You can now use the Load File Wizard to browse for the methods of the remote object and to specify which test case the methods are to be called from.
    Note: EJBs which implement the EJBLocalObject interface instead of the EJBHome interface are not displayed correctly in the JNDI tree.
  16. Alternative: If you invoke the EJB Wizard directly by right-clicking Remote Objects in the Classes pane, you must perform the following two steps:
    1. Select the create() method of the EJB Home object to instantiate an EJB object. Store the EJB object to a variable.
    2. Invoke one or more methods on the EJB object.