Exercise 5.3: The Local Component Interfaces

The example program in Exercise 5.3 explores the use of local interfaces. The Cabin entity bean you created in Exercise 4.1 will be expanded to provide a local interface for use in the TravelAgent stateless session bean. This exercise also describes how to modify your EJB deployment descriptors to enable local interfaces.

Start Up JBoss

If you already have JBoss running, there is no reason to restart it. Otherwise, start it up as instructed in the JBoss Installation and Configuration chapter.

Initialize the Database

The database should contain the 100 rows created by a successful execution of the test programs from Exercise 4.1.

Build and Deploy the Example Programs

In the ex05_3 directory, build and deploy the examples as you did for Exercise 5.1.

Examine the JBoss-Specific Files

JBoss has a minor restriction. It requires that you use <ejb-link> when you want your bean to reference a local bean through an <ejb-local-ref> tag.

ejb-jar.xml

<ejb-jar>
 <enterprise-beans>
    ...
    <session>
     <ejb-name>TravelAgentEJB</ejb-name>
     <home>com.titan.travelagent.TravelAgentHomeRemote</home>
     <remote>com.titan.travelagent.TravelAgentRemote</remote>
     <ejb-class>com.titan.travelagent.TravelAgentBean</ejb-class>
     <session-type>Stateless</session-type>
     <transaction-type>Container</transaction-type>

     <ejb-local-ref>
       <ejb-ref-name>ejb/CabinHomeLocal</ejb-ref-name>
       <ejb-ref-type>Entity</ejb-ref-type>
       <local-home>com.titan.cabin.CabinHomeLocal</local-home>
       <local>com.titan.cabin.CabinLocal</local>
      <!-- ejb-link is required by jboss for local-refs. -->
                     <ejb-link>CabinEJB</ejb-link>
     </ejb-local-ref>
     ...
</ejb-jar>

If you examine the jboss.xml file for Exercise 5.3, you’ll see that you must also declare the JNDI binding for the remote home interface. The Cabin EJB’s local home interface doesn’t need a binding in jboss.xml, though, because the binding information is contained in the <ejb-link> tag instead. JBoss will register both CabinHomeRemote and CabinHomeLocal into the JNDI tree.

jboss.xml

<jboss>
  <enterprise-beans>
    <entity>
      <ejb-name>CabinEJB</ejb-name>
      <jndi-name>CabinHomeRemote</jndi-name>
      <local-jndi-name>CabinHomeLocal</local-jndi-name>
    </entity>

TravelAgentEJB only tells JBoss under which JNDI name it should be bound:

    <session>
       <ejb-name>TravelAgentEJB</ejb-name>
       <jndi-name>TravelAgentHomeRemote</jndi-name>
    </entity>
  </enterprise-beans>
</jboss>

Examine and Run the Client Applications

The example code for Client_53 is exactly the same as Client_3 from Exercise 4.2.

Run Client_53 by invoking the appropriate Ant task, as you did in previous examples: run.client_53. Remember to set your JBOSS_HOME and PATH environment variables.

The output should look something like this:

C:workbookex05_3>ant run.client_53
Buildfile: build.xml

prepare:

compile:

ejbjar:

run.client_53:
     [java] 1,Master Suite,1
     [java] 3,Suite 101,1
     [java] 5,Suite 103,1
     [java] 7,Suite 105,1
     [java] 9,Suite 107,1
     [java] 12,Suite 201,2
     [java] 14,Suite 203,2
     [java] 16,Suite 205,2
     [java] 18,Suite 207,2
     [java] 20,Suite 209,2
     [java] 22,Suite 301,3
     [java] 24,Suite 303,3
     [java] 26,Suite 305,3
     [java] 28,Suite 307,3
..................Content has been hidden....................

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