Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

EJB Messaging, Part I: JMS and JavaMail-4 : Page 4


advertisement

EJBs and JavaMail Messaging
Obtaining a JavaMail session is considerably easier than obtaining a JMS session. You obtain a JavaMail session reference directly via a JNDI lookup; no additional method calls are required.

Assuming the following deployment descriptor settings:


<resource-ref>
   <description> This is a textual description 
of the resource.</description> <res-ref-name>mail/Email</res-ref-name> <res-type>javax.mail.Session</res-type> <res-auth>Container</res-auth> </resource-ref>


The code required to obtain a JavaMail session is as follows:


// Obtain the initial JNDI context
Context context = new InitialContext();

// JNDI lookup to obtain resource manager connection 
factory reference javax.mail.Session session = (javax.mail.Session) context.lookup("java:comp/env/mail/Email");

At this point you have a reference to a javax.jms.Session object and you are free to build QueueSender and QueueReceiver objects to be used in a point-to-point message exchange with other JMS clients.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date