Exercises

The exercise starts with a version of Day 5's job agency case study that already provides a number of beans:

  • There is a stateless Agency bean that returns lists of all applications, customers, locations and skills in the database.

  • There is a stateful Advertise bean that allows advertisers (of jobs) to update their name, e-mail, and address, and to manage the jobs they have posted to the job agency.

  • There is a stateful AdvertiseJob bean that represents an advertised job. This allows the description, location, and required skills to be maintained.

However, it does not define any bean for the potential job applicants at this point. What is required is a Register bean that allows applicants to register themselves with the job agency. The exercise is to implement the RegisterBean, define this new bean within the supplied agency.ear enterprise application, configure the bean, deploy your bean to the J2EE RI, and finally test with either RegisterClient or AllClients (supplied).

Under the day05exercise directory, you will find a number of subdirectories, including the following:

  • src The source code for the EJBs and clients.

  • classes Directory to hold the compiled classes; empty.

  • build Batch scripts (for Windows and Unix) to compile the source into the classes directory. The scripts are named compileXXX.

  • jar Holds agency.ear—the agency enterprise application. Also holds agencyClient.jar, the client-side JAR file optionally generated when deploying EAR. This directory also holds some intermediary JAR files that are used only to create the previous two JAR files.

  • run Batch scripts (for Windows and Unix) to run the JARs. Use the files in the jar directory.

The Register and RegisterHome interfaces have been provided for you, under the src directory. For example, the Register interface is as follows:

package agency;

import java.rmi.*;
import javax.ejb.*;

public interface Register extends EJBObject
{
void updateDetails (String name, String email, String location, String summary, String[]
 skills) throws RemoteException;
    String getLogin() throws RemoteException;
    String getName() throws RemoteException;
    String getEmail() throws RemoteException;
    String getLocation() throws RemoteException;
    String getSummary() throws RemoteException;
    String[] getSkills() throws RemoteException;
}

Today's exercise is to implement the RegisterBean, configure an appropriate deployment descriptor, deploy your bean to the J2EE RI, and then test with the RegisterClient. The bean will need to be stateful.

If you need some pointers as to how to go about this, read on.

1.
Create a RegisterBean.java file and place this in day05exercisesrcagency.

2.
Implement RegisterBean to support the Register and RegisterHome interfaces supplied. Base your implementation on that of AdvertiseBean, if you want.

3.
Compile the RegisterBean code and the other interfaces, using the buildcompileAgencySessionEjbs script. Note that this expects the JAVA_HOME and J2EE_HOME environment variables to be set.

4.
In deploytool, open up the existing enterprise application (day05exercisejaragency.ear). Then, add the your Register bean to the existing Agency ejb-jar by using File, New, Enterprise Bean. Specify the contents to include all the required class files.

5.
Configure the deployment descriptor for the RegisterBean appropriately. The bean will need to be stateful. You will need to specify resource references and JNDI names for the RegisterBean; bind the bean to a name of ejb/Register.

6.
For the RegisterClient application client, configure the EJB reference appropriately. This has a coded name of java:comp/env/ejb/Register to refer to the RegisterBean.

7.
Deploy your bean by selecting it and using Tools, Deploy. As you do this, you will need to define the appropriate JNDI mappings (mapping the logical EJB references to the physical runtime environment). Request a client JAR file to be created, called agencyClient.jar, to reside in the JAR directory.

8.
To test out your bean, compile AllClients using the builduildAllClientsClient script. Then run the client using run unAll.

You may also have noticed that in the build directory there are several other scripts apart from those to compile the source. In fact, these can be used to recreate the agency.ear file using the deployment descriptors held in the dd directory. You will be learning more about this approach tomorrow. For now, all that you need to know is that the agency.ear file can be created automatically by running the batuildall script. It requires that the RegisterBean class exist to run successfully. You can then use deploytool to manually define and configure the RegisterBean within the EAR.

The solution to the exercise is under day05agency.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.72.176