Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax.mail.session and DataSource(Apache Tomcat)

 
Sergey Kargopolov
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day!

I am trying to set up DataSource to use javax.mail.session. And I need help here.

1.I think I configured web.xml correctly.

<resource-ref>
<res-ref-name>mail/MailSession</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

2. How to lookup JNDI is also clear I think

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Session session = (javax.mail.Session) envCtx.lookup("mail/MailSession");

3. But I am not sure how to configure server.xml(TOMCAT)

<Resource name="mail/MailSession" auth="Container" ype="javax.mail.Session" mail.smtp.host="sergey"/>

Is it correct way to configure?

Please suggest me where can I go and read more information about java.mail.session with DataSource, may be see some examples, tutorials.


Thank you very much!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A javax.mail.Session is nothing to do with a javax.sql.DataSource. You've given your resource reference the wrong type.

Your resource factory configuration looks ok though, assuming you have an SMTP host set up called 'sergey'?

(By the way, we have a Tomcat forum which is specifically for these kinds of configuration questions. Next time you would be better posting there).
 
Sergey Kargopolov
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am very sorry I have misstyped it!!!

<resource-ref>
<res-ref-name>mail/MailSession</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

Thank you for your reply
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to apologise! Don't feel worried about posting code with mistakes in it on JavaRanch; we all do it and helping with the mistakes is what we are for.
 
Sergey Kargopolov
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul, thank you for your replies.
The problems was not because of above misspelling.

I am not sure now to create Resource in Tomcat server.xml

<Resource name="mail/MailSession" auth="Container" ype="javax.mail.Session" mail.smtp.host="sergey"/>

sergey - is server name(my local machine)

I have written a very simple web client that sends ands receives emails. Now I am re-designing its architecture and i want Sessions or even Store connections to be managed by Container. For that I am trying to configure Datasource. But if I modify my Tomcat server.xml in the way I posted above, tomcat stops working .

I have posted a message to Tomcat forum after you have suggested me to do that. Hopefully, with your help and with the help of others I will manage to solve my problem.

Thank you very much Paul!
 
Sergey Kargopolov
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it working!

http://www.coderanch.com/t/86121/Tomcat/javax-mail-Session-DataSource-Apache


Thank you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic