users@glassfish.java.net

Re: Problem on configuring Java Mail Session

From: Sahoo <sahoo_at_sun.com>
Date: Sat, 22 Mar 2008 08:05:13 +0530

Use resource-ref instead of resource-env-ref. Following is an example of
what you need to inject a mail.Session into your EJB without using
annotation.

<resource-ref>
    <res-ref-name>mail/MailSession</res-ref-name>
    <res-type>javax.mail.Session</res-type>
    <mapped-name>mail/FossDemoMailSession</mapped-name>
    <injection-target>
       
<injection-target-class>ejb.VisitorRegistrationService</injection-target-class>
       <injection-target-name>mailSession</injection-target-name>
    </injection-target>
</resource-ref>

It uses mappedName entry, so no need for using sun-ejb-jar.xml for
mapping the local name to global JNDI name.

There is a trick that you can use in future to find out the exact DD
required for such cases:
1. deploy the original sample which uses annotations.
2. Open to
$GF_HOME/domains/domain1/generated/xml/j2ee-module/<ejb-jar-name>/META-INF/ejb-jar.xml.
You can now see the equivalent ejb-jar.xml that GlassFish has generated
from your annotations in source code. Copy and paste relevant sections
into your ejb-jar.xml.

Thanks,
Sahoo

glassfish_at_javadesktop.org wrote:
> Hi Sahoo,
>
> Thanks for that. The @Resource at class level works either.
>
> Can I ask you a further question on this, that is how to work it out using deployment descriptor instead? Below are ejb-jar.xml and sun-ejb-jar.xml I am using, when I added them into your example and commented out the @Resource annotation, I got both a and b are MailConfiguration, not the desired MailSession.
> Can you please have a look and let me know if I did something wrong?
> ejb-jar.xml
> <?xml version="1.0" encoding="UTF-8"?>
>
> <ejb-jar xmlns = "http://java.sun.com/xml/ns/javaee"
> version = "3.0"
> xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
> <enterprise-beans>
> <session>
> <ejb-name>VisitorRegistrationService</ejb-name>
> <ejb-class>ejb.VisitorRegistrationService</ejb-class>
> <resource-env-ref>
> <resource-env-ref-name>mail/MailSession</resource-env-ref-name>
> <resource-env-ref-type>javax.mail.Session</resource-env-ref-type>
>
> </resource-env-ref>
> </session>
> </enterprise-beans>
> </ejb-jar>
>
> sun-ejb-jar.xml
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
> <sun-ejb-jar>
> <enterprise-beans>
> <ejb>
> <ejb-name>VisitorRegistrationService</ejb-name>
> <jndi-name>VisitorRegistrationService</jndi-name>
> <resource-env-ref>
> <resource-env-ref-name>mail/MailSession</resource-env-ref-name>
> <jndi-name>mail/FossDemoMailSession</jndi-name>
> </resource-env-ref>
> </ejb>
> </enterprise-beans>
> </sun-ejb-jar>
>
>
> Thanks
> Ken
> [Message sent by forum member 'dabaner' (dabaner)]
>
> http://forums.java.net/jive/thread.jspa?messageID=265260
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>