Section 8.5. JavaMail-Based JNDI References in EJB Deployment Descriptors


8.5. JavaMail-Based JNDI References in EJB Deployment Descriptors

In previous chapters we've used the ejb-jar.xml and jboss.xml file to describe and deploy EJBs and JNDI resources. Here are the new JavaMail -based JNDI references in ejb-jar.xml that enable the CreditCheckProcessor MDB to use a JavaMail Session, as in Example 8-5.

Example 8-5. ejb-jar.xml
 <?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns=http://java.sun.com/xml/ns/j2ee          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee          http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1">   <enterprise-beans>     ...     <message-driven>       <display-name>CreditCheckProcessorMDB</display-name>       <ejb-name>CreditCheckProcessor</ejb-name>       ...       <resource-ref>         <res-ref-name>mail/JawJavaMailSession</res-ref-name>         <res-type>javax.mail.Session</res-type>         <res-auth>Container</res-auth>       </resource-ref>       ...     </message-driven>     ... </ejb-jar> 

The <resource-ref> elements specify the JNDI resources available to the CreditCheckProcessorMDB (or any POJO that it calls). <res-ref-name> is the JNDI name for the resourcejava:comp/env/mail/JawJavaMailSession. Notice that you don't have to specify java:comp/env/because it is the assumed prefix. The <res-type> for the mail/JawJavaMailSession is a JavaMail Session, and javax.jms.Session is its fully qualified class name. We want JBoss to manage our JavaMail resources, so we set <res-auth> to Container.

A JNDI resource is linked into an application only if we ask for it. JBoss binds resources under its in-JVM context, java:/. The jboss.xml file provides a mapping from the J2EE-style ENC names and the local JBoss-specific JNDI names that JBoss uses to deploy a JavaMail Session. Example 8-6 shows the JavaMail-related JNDI references for the CreditCheckProcessor MDB in jboss.xml.

Example 8-6. jboss.xml
 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN"                        "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd"> <jboss>   <enterprise-beans>     ...     <message-driven>       <ejb-name>CreditCheckProcessor</ejb-name>       <destination-jndi-name>queue/CreditCheckQueue</destination-jndi-name>       <resource-ref>         <res-ref-name>mail/JawJavaMailSession</res-ref-name>         <jndi-name>java:/Mail</jndi-name>       </resource-ref>     </message-driven>     ...   </enterprise-beans>   ... </jboss> 

As you'll see in the "Deploying JavaMail on JBoss" section, the java:/Mail name is the local JNDI name that JBoss uses to deploy its JavaMail Session.



JBoss at Work. A Practical Guide
JBoss at Work: A Practical Guide
ISBN: 0596007345
EAN: 2147483647
Year: 2004
Pages: 197

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net