1 22 package org.jboss.ejb3.test.mail; 23 24 import javax.annotation.Resource; 25 import javax.ejb.Stateless ; 26 import javax.ejb.Remote ; 27 import javax.naming.Context ; 28 import javax.naming.InitialContext ; 29 import javax.naming.NamingException ; 30 31 import org.jboss.annotation.ejb.RemoteBinding; 32 import org.jboss.ejb3.Container; 33 34 import org.jboss.logging.Logger; 35 36 import javax.mail.Session ; 37 38 42 @Stateless (name="StatelessMail") 43 @Remote (StatelessMail.class) 44 @RemoteBinding(jndiBinding="StatelessMail") 45 public class StatelessMailBean 46 implements StatelessMail 47 { 48 private static final Logger log = Logger.getLogger(StatelessMailBean.class); 49 50 @Resource(name="DefaultMail", mappedName="java:/Mail") 51 private Session mailSession; 52 53 @Resource(mappedName="java:/Mail") 54 private Session session; 55 56 public void testMail() throws NamingException 57 { 58 Context initCtx = new InitialContext (); 59 Context myEnv = (Context ) initCtx.lookup(Container.ENC_CTX_NAME + "/env"); 60 61 Object obj = myEnv.lookup("mail/DefaultMail"); 63 if ((obj instanceof javax.mail.Session ) == false) 64 throw new NamingException ("DefaultMail is not a javax.mail.Session"); 65 } 66 67 public void testMailInjection() 68 { 69 mailSession.getProperties(); 70 71 session.getProperties(); 72 } 73 74 } 75 | Popular Tags |