Java Reference
In-Depth Information
deployment-descriptor files for WebLogic application server (version 6.1) are listed in Listing 20-4 . If you
use different application servers, the files may look different.
Listing 20-4: Deployment-descriptor files for HelloEJB
# First file: J2EE standard
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 2.0//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>HelloEJB</ejb-name>
<home>HelloSLBean.HelloHome</home>
<remote>HelloSLBean.Hello</remote>
<ejb-class>HelloSLBean.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
#Second file: WebLogic specific
<?xml version="1.0"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic
6.0.0 EJB//EN' 'http://www.bea.com/servers/wls60/ejb20/dtd/weblogic-ejb-
jar.dtd'>
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>HelloEJB</ejb-name>
<jndi-name>Hello</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
You can see that the first XML file specifies the EJB name, remote interface name, home interface
name, and bean class name. It specifies that HelloEJB is a stateless session bean, and the container
manages its database transaction (transaction management is discussed later). The second file
specifies the EJB's Java Naming and Directory Interface (JNDI) name, which the client uses to look up
the EJB.
Now that the EJB has been developed, it is time to code the client. The steps for a client to invoke EJB
services are as follows:
1. Instantiate an InitialContext instance.
2. Look up the home interface from JNDI.
3. Create a remote interface instance as the EJB reference.
4. Invoke EJB services via the reference.
These steps are illustrated in the JSP client listed in Listing 20-5 . The output of the test is shown in
Figure 20-1 . Bounds checking coded into the method getWelcomeMsg(int) prevent the array index
Search WWH ::




Custom Search