In this step you are going to test the EJBs and examine whether their behavior is as intended. Because EJBs are server-side components, you must first create a client application, such as a web application. Here you will build a test web service instead. This requires generating an EJB control for the EJB, and generating a test web service for the EJB control.
The tasks in this step are:
To Create the Web Service Project
Web service development is done in a separate project in the application.
When you want to invoke a session bean from a client application, you must first look up the session bean in the EJB container's JNDI registry and obtain a reference to the EJB's home interface, before you can create an EJB instance and invoke the EJB's business methods. You can do this by calling the standard JNDI API methods, or you can use EJB controls that do this for you. In this tutorial you will create an EJB control for the Hello session bean.
The
EJB control HelloBeanCtrl is created
and appears in Design View. Notice that there are no methods defined in
the EJB Control. An EJB control is only used to obtain a
reference to the EJB. It does not define methods of its own, but simply
provides a window to the EJB it exposes. To see exactly which methods are
exposed, you need to use the EJB control in a client application such as
the test web service that you will generate next.
If you examine the Property Editor, you will see that the EJB control uses the Hello bean's remote JNDI name ejb.HelloRemoteHome to reference its remote interfaces. Remember that this JNDI name was defined when you created the session bean and can be used to look up the EJB within the context of the EJB container.
To learn more about EJB controls, see the help topic EJB Controls. To learn more about Java controls in general, see Getting Started Tutorial: Java Controls
The test web service HelloBeanCtrlTest is generated. The Application pane should now look like this:
A test web service is a web service that exposes the methods of a Java control. In this particular case the test web service is a client application that calls the methods on the EJB control helloBeanCtrl, which in turn exposes the methods of the Hello bean. Remember that the Hello bean has two methods, namely the create method to obtain a reference to a Hello bean instance, and the component method hello. When you use an EJB control, you do not have to call the create method first to obtain a reference, because the EJB control will handle this automatically for you. Instead you can simply invoke the hello method directly. To learn more about web services, see the Getting Started Tutorial: Web Services.
Let's run the test web service and test the behavior of the EJBs.
Click one of the following arrows to navigate through the tutorial: