I think I figured out what was wrong. The global should be mail/whatever. I
can still use context lookup. Problem solved.
-----Original Message-----
From: Phillip Qin [mailto:Phillip.Qin@(protected)]
Sent: November 25, 2004 12:46 PM
To: 'tomcat-user@(protected)'
Subject: GlobalNamingResources
I setup a GlobalNamingResoruces entry in server.xml
<Resource name="mail/whatever" auth="Container" scope="Shareable"
type="
javax.mail.Session"/>
<ResourceParams name="mail/whatever">
<parameter>
<name>mail.smtp.host</name>
<value>mail.whatever.com</value>
</parameter>
</ResourceParams>
I then added resourcelink in my webapp's context.xml
<ResourceLink name="mail/whatever" global="java:comp/env/mail/whatever"
type="
javax.mail.Session"/>
First problem that I have is, if I do a context lookup, Tomcat complained
about not finding the binding, something like java:comp not bound. What I
did is
Context initialContext = new InitialContext();
Context context = (Context) initialContext.lookup("java:comp/env");
<= failed here
return (Session) context.lookup("mail/whatever");
The I realized I should use globalnamingcontext. So I changed the above code
to
StandardServer server = (StandardServer) ServerFactory.getServer();
<= failed here
Context context = server.getGlobalNamingContext();
return (Session) context.lookup("mail/whatever");
Now, the error message is
java.lang.NoClassDefFoundError: org/apache/catalina/ServerFactory
com.shareowner.core.services.mailservice.MailService.findMailSession(MailSer
vice.java:36)
com.shareowner.core.services.mailservice.MailService.send(MailService.java:6
5)
com.shareowner.onlinestore.services.beanservices.AuthLogService.sendEmail(Au
thLogService.java:43)
com.shareowner.onlinestore.services.beanservices.TxnLogService.log(TxnLogSer
vice.java:33)
com.shareowner.onlinestore.services.creditcardservices.CreditCardService.wri
teAuthLog(CreditCardService.java:356)
com.shareowner.onlinestore.services.creditcardservices.CreditCardService.pos
t(CreditCardService.java:214)
com.shareowner.onlinestore.services.creditcardservices.CreditCardService.pos
tToServer(CreditCardService.java:276)
com.shareowner.onlinestore.actions.PlaceOrderAction.placeOrder(PlaceOrderAct
ion.java:81)
com.shareowner.onlinestore.actions.PlaceOrderAction.performPostValidationAct
ion(PlaceOrderAction.java:50)
com.shareowner.onlinestore.actions.BaseAppAction.execute(BaseAppAction.java:
122)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProces
sor.java:484)
org.apache.struts.action.RequestProcessor.process (
RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process (
ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet (
ActionServlet.java:507)
javax.servlet.http.HttpServlet.service (
HttpServlet.java:689)
javax.servlet.http.HttpServlet.service (
HttpServlet.java:802)
com.shareowner.core.filters.HttpsFilter.doFilter(HttpsFilter.java:39)
ServerFactory is in ${catalina_home}/server/lib/catalina.jar, so there is no
reason why class loader can't find the class.
Any idea on how do I access the GlobalNamingResource from my webapp?
Approach 2 works with Tomcat Manager.
Regards,
PQ
Going to war for peace is like having sex for virginity
!DSPAM:41a61a69240991588114867!