Exercises

The exercise starts where today's example left of. The agency case study 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, email, 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 Day 5 exercise directory, you will find the usual subdirectories, including the following:

  • src The source code for the EJBs and clients

  • classes Directory to hold the compiled classes; empty

  • build Working directory for the asant build files to use

  • j2ee-ri Working directory for using deploytool to build and deploy the agency.ear application

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 Day05/exercise/src/agency.

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 command asant compile. (You must be in the Day05/exercise directory.)

4.
In deploytool, open up the existing enterprise application (Day05/exercise/j2ee-ri/agency.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.

7.
Map the Register bean onto the Sun-specific JNDI name ejb/Register.

8.
Define the ejb/Agency resource reference to refer to the ejb/Agency data source. For the AllClients application client, add an EJB reference to the Register Bean, mapping the reference onto the Sun-specific JNDI name ejb/Register.

9.
Save your application and verify J2EE compliance.

10.
Deploy your bean.

11.
Use deploytool to obtain the client JAR file from the Agency application you have just deployed. Save this as Day05/exercise/j2ee-ri/agencyClient.jar.

12.
To test out your bean issue the command

asant run-j2ee-ri

13.
If you prefer to work from the command line and want to hand edit the deployment descriptors to add the new Register EJB, you can used the command asant build to compile the classes and build the EAR file. You can verify using asant verify, deploy using asant deploy and run using asant run

If you take this approach you will need to update the following deployment descriptor files:

  • dd/agency/ejb-jar.xml

  • dd/agency/sun-ejb-jar.xml

  • dd/client/application-client.xml

  • dd/client/sun-application-client.xml

Follow the example deployment descriptor entries in today's case study for a guide to the deployment descriptor elements you will need to add. However you will need to include the following entry in ejb-jar.xml to define the transaction requirements for the Register Session bean:

<ejb-jar>
...
  <assembly-descriptor>
...
    <container-transaction>
      <method>
        <ejb-name>RegisterBean</ejb-name>
        <method-intf>Remote</method-intf>
        <method-name>*</method-name>
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
  </assembly-descriptor>
</ejb-jar>

A solution to the exercise is provided in Day05/agency.

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

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