| From | Sent On | Attachments |
|---|---|---|
| glas...@javadesktop.org | Mar 10, 2008 5:04 am | |
| glas...@javadesktop.org | Mar 11, 2008 4:38 am | |
| Sahoo | Mar 11, 2008 9:42 am | |
| glas...@javadesktop.org | Mar 13, 2008 3:57 am | |
| Sahoo | Mar 13, 2008 5:32 am | |
| glas...@javadesktop.org | Mar 13, 2008 10:10 am | |
| glas...@javadesktop.org | Mar 16, 2008 3:08 am | |
| Sahoo | Mar 16, 2008 5:50 am | |
| Sahoo | Mar 20, 2008 12:32 am | |
| glas...@javadesktop.org | Mar 20, 2008 5:20 am | |
| Sahoo | Mar 20, 2008 11:21 am | |
| glas...@javadesktop.org | Mar 21, 2008 6:13 pm | |
| Sahoo | Mar 21, 2008 7:34 pm | |
| glas...@javadesktop.org | Mar 21, 2008 8:31 pm | |
| glas...@javadesktop.org | May 17, 2008 1:33 pm | |
| glas...@javadesktop.org | May 17, 2008 2:42 pm | |
| glas...@javadesktop.org | Sep 2, 2008 8:36 am | |
| glas...@javadesktop.org | Sep 2, 2008 9:19 am | |
| glas...@javadesktop.org | Sep 2, 2008 9:47 am | |
| glas...@javadesktop.org | Sep 2, 2008 9:52 am | |
| glas...@javadesktop.org | Sep 2, 2008 10:33 am | |
| glas...@javadesktop.org | Sep 2, 2008 10:44 am | |
| glas...@javadesktop.org | Sep 18, 2008 1:30 pm | |
| glas...@javadesktop.org | Sep 18, 2008 3:28 pm | |
| glas...@javadesktop.org | Jan 6, 2009 8:48 am |
| Subject: | Re: Problem on configuring Java Mail Session | |
|---|---|---|
| From: | Sahoo (sah...@sun.com) | |
| Date: | Mar 20, 2008 12:32:38 am | |
| List: | net.java.dev.glassfish.users | |
The correct way to look up resource in Java EE is to use the local name (a.k.a. logical name) of the resource rather than the actual JNDI name of the resource. You can run the following sample and see the difference:
@Stateless() @WebService() public class VisitorRegistrationService {
// The actual JNDI name is mail/FossDemoMailSession // where as the local name is mail/MailSession. @Resource(name="mail/MailSession", mappedName="mail/FossDemoMailSession") Session mailSession; // inject a Mail Session /** * Web service operation */ @WebMethod public int registerVisitor( String name, String email) { try { InitialContext ctx = new InitialContext(); Object a = ctx.lookup("mail/FossDemoMailSession"); Object b = ctx.lookup("java:comp/env/mail/MailSession"); System.out.println(a); System.out.println(b); } catch(Exception e) { e.printStackTrace(); } return 0; } }
Looking up the resource using the actual JNDI name (mail/FossDemoMailSession) returns com.sun.enterprise.deployment.MailConfiguration@49d560 object, where as if you use java:comp/env/mail/MailSession, it returns javax.mail.Session@157bbd4.
To try out yourself, just compile, jar and deploy. Create a MailSession using admin gui and give it a name mail/FossDemoMailSession. You can test the program by using the web service test client that is available in the admin gui.
Thanks, Sahoo
glas...@javadesktop.org wrote:
Hi Sahoo,
Below post from 'Frenchdrip' pointed out what my doubt was. Actually I tried
followig different ways,
1. directly using resource injection on setter or instance variable
2. inject resource on class level and lookup it from sessionContext
3. inject resource on class level and lookup it from JNDI initial context.
Only 1 gets mailSession object. Both 2 and 3 return mail configuration which
requires casting to session. I had never experienced such as well known
'NameNotFoundException' so I don't believe that's a JNDI problem.
Thanks, Ken [Message sent by forum member 'dabaner' (dabaner)]





