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.
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:
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.)
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.
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.
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:
In the J2EE Hierarchy view, right-click the enterprise bean for which you want to generate deployment code, then select Generate Deployment Code.
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.
Expand the EJB Modules that contains the module you want to test (titan).
Right-click an EJB module that you want to test.
Select Run on Server.... The Server selection wizard opens.
Select the Use an existing server radio button and select the server you previously created.
Click Next to configure additional settings (optional).
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).
Click Finish. The server tools automatically do the following tasks for you:
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).
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
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:
Create a WebSphere server and configuration.
Add a project to the server.
To ensure that the server is enabled to use the Universal Test Client:
In the Server Configuration view, double-click your server. The server editor opens.
Select the Configuration tab.
Select the Enable universal test client check box.
Close the editor and save your changes.
Start a server.
To start the Universal Test Client:
In the J2EE Hierarchy view, right-click on an EJB module (titan).
Select Run on Server. The Universal Test Client opens in the Web Browser.
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
Use the Universal Test Client to perform one or more of the following tasks:
Finding an enterprise bean or class
Calling a method
Removing an enterprise bean or class
Filtering the methods displayed
Changing the property settings
When you have finished using the Universal Test Client, close it.
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.
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:
To find the JNDI name of the enterprise bean when the JNDI name is known:
On the Universal Test Client toolbar, select the JNDI Explorer icon on the toolbar. The JNDI Explorer page appears.
In the JNDI Name field, type the JNDI name of the enterprise bean that you want to test.
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.
To find the JNDI name of the enterprise bean when the JNDI name is unknown:
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.
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.
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.
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.
To call a method:
In the Universal Test Client, click the Bean page icon on the toolbar. The Bean page opens displaying all the methods.
In the References pane of the Bean page, select a method. The Parameters pane displays all the parameters for that particular method.
(Optional) If the parameter is a primitive type, the field is enabled allowing you to change its value.
(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.
Click the Invoke button to invoke the method:
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
Displays an error message if the method threw an exception.
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: