You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Erez Efrati <er...@netmedia.net.il> on 2004/03/25 00:17:18 UTC
can't load template
Hi there, I trying to work with the Velocity and keep complaining the
following error message:
" Unable to find resource 'resources.UserLoginInfo.vm' "
My application is contains the Logic (and EJB module) and Web (web
module). the UserLoginInfo.vm is located under the resources directory.
I am working with JBoss 3.2.3 /Tomcat 4.1.29.
Here is my Emailer.java:
Code:
/**
* A utility class that provides API for sending
* templated emails per application use case.
* <p>The <code>Emailer</code> uses Velocity SDK to generate
* the templated emails.
*
* @author Erez Efrati
* @version $Revision:$ $Date:$
*/
public class Emailer {
/**
* JNDI context for JavaMail sessions.
*/
private static final String JNDI_JAVA_MAIL = "java:/Mail";
/**
* The content type of the HTML email messages.
*/
private static final String HTML_CONTENT_TYPE =
"text/html;charset=UTF-8";
/**
* The user-login-info email template resource name.
*/
private static final String VM_USER_LOGIN_INFO_REMINDER
= "resources.UserLoginInfo.vm";
// Velocity variable names keys
private static final String VMVAR_USER = "user";
private static final String VMVAR_SUBJECT = "subject";
/**
* the engine instance
*/
VelocityEngine m_engine = new VelocityEngine ();
// ------------------------------------------------------
Private Methods
/**
* Configures the engine to use classpath to find templates
*
* @param engine the engine to
configure
* @throws Exception thrown if an errors occures
*/
private void configure (VelocityEngine engine) throws
Exception
{
Properties props = new Properties ();
props.setProperty
(VelocityEngine.RESOURCE_LOADER, "classpath");
props.setProperty ("classpath." +
VelocityEngine.RESOURCE_LOADER + ".class",
ClasspathResourceLoader.class.getName());
m_engine.init (props);
}
/**
* Creates a Velocity context
*/
private VelocityContext createContext()
{
VelocityContext ctx = new VelocityContext ();
return ctx;
}
/**
* Retreives a new JavaMail Mime message
*
* @return
* @throws NamingException
*/
private MimeMessage createMimeMessage() throws
NamingException
{
Context initCtx = new InitialContext ();
Session session = (Session)initCtx.lookup
(JNDI_JAVA_MAIL);
MimeMessage message = new MimeMessage (session);
return message;
}
// ------------------------------------------------------
Public Methods
/**
* Default constructor, configures the velocity engine.
*
* @throws Exception, if an error occures
*/
public Emailer () throws Exception
{
configure (m_engine);
}
/**
* Sends an email to the specified <code>user</code>
containing
* his login information which includes his username and
password.
*
* @param user
* @throws Exception
*/
public void sendUserLoginInfo (User user) throws Exception
{
// retrieve the email template
Template template = m_engine.getTemplate
(VM_USER_LOGIN_INFO_REMINDER);
// prepare the context and store data objects in
it
VelocityContext ctx = createContext ();
ctx.put (VMVAR_USER, user);
// merge the template
StringWriter writer = new StringWriter ();
template.merge (ctx, writer);
writer.close ();
// retrieve the message subject and text. The
subject
// is formulated as part of the email velocity
template.
StringBuffer text = writer.getBuffer();
String subject = (String)ctx.get
(VMVAR_SUBJECT);
// create a new message to work with
MimeMessage message = createMimeMessage ();
// retrieve the user's email address
String to = user.getEmail ();
String from = App.getSupportEmailAddress ();
message.setFrom (new InternetAddress (from));
message.addRecipient (Message.RecipientType.TO,
new InternetAddress (to));
// set the subject and content
message.setSubject (subject);
message.setContent (text, HTML_CONTENT_TYPE);
// Send message
Transport.send (message);
}
Why doesn't it work? What am I missing?
One more thing I maybe should point out as well - The emailer
is called from my 'UserServiceBean' which is a stateless Session bean.
I hope this is valid, is it?
I would really appreciate any help here :)
Erez
Re: can't load template
Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Mar 25, 2004, at 10:03 AM, Erez Efrati wrote:
> Geir,
>
> Yes, I do mean for the "." (dot) to be there, very much like the
> "resources.ApplicationResources.properties" in struts and others where
> the resource is loaded based on classpath.
Oh - just wanted to make sure that wasn't a typo... will go stare at
your previous message again...
>
> Erez
>
> -----Original Message-----
> From: Geir Magnusson Jr [mailto:geir@4quarters.com]
> Sent: Thursday, March 25, 2004 6:36 AM
> To: Velocity Users List
> Subject: Re: can't load template
>
>
> On Mar 24, 2004, at 6:17 PM, Erez Efrati wrote:
>
>> Hi there, I trying to work with the Velocity and keep complaining the
>> following error message:
>>
>> " Unable to find resource 'resources.UserLoginInfo.vm' "
>
> Do you really mean for the 'dot' to be between 'resources' and
> 'UserLoginInfo.vm'?
>
> geir
>
>>
>> My application is contains the Logic (and EJB module) and Web (web
>> module). the UserLoginInfo.vm is located under the resources
> directory.
>> I am working with JBoss 3.2.3 /Tomcat 4.1.29.
>>
>> Here is my Emailer.java:
>>
>> Code:
>>
>>
>> /**
>> * A utility class that provides API for sending
>> * templated emails per application use case.
>> * <p>The <code>Emailer</code> uses Velocity SDK to generate
>> * the templated emails.
>> *
>> * @author Erez Efrati
>> * @version $Revision:$ $Date:$
>> */
>> public class Emailer {
>>
>> /**
>> * JNDI context for JavaMail sessions.
>> */
>> private static final String JNDI_JAVA_MAIL = "java:/Mail";
>>
>> /**
>> * The content type of the HTML email messages.
>> */
>> private static final String HTML_CONTENT_TYPE =
>> "text/html;charset=UTF-8";
>>
>> /**
>> * The user-login-info email template resource name.
>> */
>> private static final String VM_USER_LOGIN_INFO_REMINDER
>>
>> = "resources.UserLoginInfo.vm";
>>
>> // Velocity variable names keys
>> private static final String VMVAR_USER = "user";
>> private static final String VMVAR_SUBJECT = "subject";
>>
>> /**
>> * the engine instance
>> */
>> VelocityEngine m_engine = new VelocityEngine ();
>>
>> // ------------------------------------------------------
>> Private Methods
>>
>>
>> /**
>> * Configures the engine to use classpath to find
> templates
>> *
>> * @param engine the engine to
>> configure
>> * @throws Exception thrown if an errors occures
>> */
>> private void configure (VelocityEngine engine) throws
>> Exception
>> {
>> Properties props = new Properties ();
>> props.setProperty
>> (VelocityEngine.RESOURCE_LOADER, "classpath");
>> props.setProperty ("classpath." +
>> VelocityEngine.RESOURCE_LOADER + ".class",
>>
>> ClasspathResourceLoader.class.getName());
>> m_engine.init (props);
>> }
>>
>>
>> /**
>> * Creates a Velocity context
>> */
>> private VelocityContext createContext()
>> {
>> VelocityContext ctx = new VelocityContext ();
>> return ctx;
>> }
>>
>> /**
>> * Retreives a new JavaMail Mime message
>> *
>> * @return
>> * @throws NamingException
>> */
>> private MimeMessage createMimeMessage() throws
>> NamingException
>> {
>> Context initCtx = new InitialContext ();
>> Session session = (Session)initCtx.lookup
>> (JNDI_JAVA_MAIL);
>> MimeMessage message = new MimeMessage
>> (session);
>> return message;
>> }
>>
>> // ------------------------------------------------------
>> Public Methods
>>
>> /**
>> * Default constructor, configures the velocity engine.
>> *
>> * @throws Exception, if an error occures
>> */
>> public Emailer () throws Exception
>> {
>> configure (m_engine);
>> }
>>
>>
>> /**
>> * Sends an email to the specified <code>user</code>
>> containing
>> * his login information which includes his username and
>> password.
>> *
>> * @param user
>> * @throws Exception
>> */
>> public void sendUserLoginInfo (User user) throws Exception
>> {
>> // retrieve the email template
>> Template template = m_engine.getTemplate
>> (VM_USER_LOGIN_INFO_REMINDER);
>>
>> // prepare the context and store data objects
>> in
>> it
>> VelocityContext ctx = createContext ();
>> ctx.put (VMVAR_USER, user);
>>
>> // merge the template
>> StringWriter writer = new StringWriter ();
>> template.merge (ctx, writer);
>> writer.close ();
>>
>> // retrieve the message subject and text. The
>> subject
>> // is formulated as part of the email velocity
>> template.
>> StringBuffer text = writer.getBuffer();
>> String subject = (String)ctx.get
>> (VMVAR_SUBJECT);
>>
>> // create a new message to work with
>>
>> MimeMessage message = createMimeMessage ();
>>
>> // retrieve the user's email address
>> String to = user.getEmail ();
>>
>> String from = App.getSupportEmailAddress ();
>> message.setFrom (new InternetAddress (from));
>> message.addRecipient
> (Message.RecipientType.TO,
>>
>> new InternetAddress (to));
>>
>> // set the subject and content
>> message.setSubject (subject);
>> message.setContent (text, HTML_CONTENT_TYPE);
>>
>> // Send message
>> Transport.send (message);
>>
>> }
>>
>>
>>
>>
>>
>> Why doesn't it work? What am I missing?
>>
>> One more thing I maybe should point out as well - The emailer
>> is called from my 'UserServiceBean' which is a stateless Session bean.
>> I hope this is valid, is it?
>>
>> I would really appreciate any help here :)
>>
>> Erez
>>
> --
> Geir Magnusson Jr 203-247-1713(m)
> geir@4quarters.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
--
Geir Magnusson Jr 203-247-1713(m)
geir@4quarters.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
RE: can't load template
Posted by Erez Efrati <er...@netmedia.net.il>.
Geir,
Yes, I do mean for the "." (dot) to be there, very much like the
"resources.ApplicationResources.properties" in struts and others where
the resource is loaded based on classpath.
Erez
-----Original Message-----
From: Geir Magnusson Jr [mailto:geir@4quarters.com]
Sent: Thursday, March 25, 2004 6:36 AM
To: Velocity Users List
Subject: Re: can't load template
On Mar 24, 2004, at 6:17 PM, Erez Efrati wrote:
> Hi there, I trying to work with the Velocity and keep complaining the
> following error message:
>
> " Unable to find resource 'resources.UserLoginInfo.vm' "
Do you really mean for the 'dot' to be between 'resources' and
'UserLoginInfo.vm'?
geir
>
> My application is contains the Logic (and EJB module) and Web (web
> module). the UserLoginInfo.vm is located under the resources
directory.
> I am working with JBoss 3.2.3 /Tomcat 4.1.29.
>
> Here is my Emailer.java:
>
> Code:
>
>
> /**
> * A utility class that provides API for sending
> * templated emails per application use case.
> * <p>The <code>Emailer</code> uses Velocity SDK to generate
> * the templated emails.
> *
> * @author Erez Efrati
> * @version $Revision:$ $Date:$
> */
> public class Emailer {
>
> /**
> * JNDI context for JavaMail sessions.
> */
> private static final String JNDI_JAVA_MAIL = "java:/Mail";
>
> /**
> * The content type of the HTML email messages.
> */
> private static final String HTML_CONTENT_TYPE =
> "text/html;charset=UTF-8";
>
> /**
> * The user-login-info email template resource name.
> */
> private static final String VM_USER_LOGIN_INFO_REMINDER
>
> = "resources.UserLoginInfo.vm";
>
> // Velocity variable names keys
> private static final String VMVAR_USER = "user";
> private static final String VMVAR_SUBJECT = "subject";
>
> /**
> * the engine instance
> */
> VelocityEngine m_engine = new VelocityEngine ();
>
> // ------------------------------------------------------
> Private Methods
>
>
> /**
> * Configures the engine to use classpath to find
templates
> *
> * @param engine the engine to
> configure
> * @throws Exception thrown if an errors occures
> */
> private void configure (VelocityEngine engine) throws
> Exception
> {
> Properties props = new Properties ();
> props.setProperty
> (VelocityEngine.RESOURCE_LOADER, "classpath");
> props.setProperty ("classpath." +
> VelocityEngine.RESOURCE_LOADER + ".class",
>
> ClasspathResourceLoader.class.getName());
> m_engine.init (props);
> }
>
>
> /**
> * Creates a Velocity context
> */
> private VelocityContext createContext()
> {
> VelocityContext ctx = new VelocityContext ();
> return ctx;
> }
>
> /**
> * Retreives a new JavaMail Mime message
> *
> * @return
> * @throws NamingException
> */
> private MimeMessage createMimeMessage() throws
> NamingException
> {
> Context initCtx = new InitialContext ();
> Session session = (Session)initCtx.lookup
> (JNDI_JAVA_MAIL);
> MimeMessage message = new MimeMessage
> (session);
> return message;
> }
>
> // ------------------------------------------------------
> Public Methods
>
> /**
> * Default constructor, configures the velocity engine.
> *
> * @throws Exception, if an error occures
> */
> public Emailer () throws Exception
> {
> configure (m_engine);
> }
>
>
> /**
> * Sends an email to the specified <code>user</code>
> containing
> * his login information which includes his username and
> password.
> *
> * @param user
> * @throws Exception
> */
> public void sendUserLoginInfo (User user) throws Exception
> {
> // retrieve the email template
> Template template = m_engine.getTemplate
> (VM_USER_LOGIN_INFO_REMINDER);
>
> // prepare the context and store data objects
> in
> it
> VelocityContext ctx = createContext ();
> ctx.put (VMVAR_USER, user);
>
> // merge the template
> StringWriter writer = new StringWriter ();
> template.merge (ctx, writer);
> writer.close ();
>
> // retrieve the message subject and text. The
> subject
> // is formulated as part of the email velocity
> template.
> StringBuffer text = writer.getBuffer();
> String subject = (String)ctx.get
> (VMVAR_SUBJECT);
>
> // create a new message to work with
>
> MimeMessage message = createMimeMessage ();
>
> // retrieve the user's email address
> String to = user.getEmail ();
>
> String from = App.getSupportEmailAddress ();
> message.setFrom (new InternetAddress (from));
> message.addRecipient
(Message.RecipientType.TO,
>
> new InternetAddress (to));
>
> // set the subject and content
> message.setSubject (subject);
> message.setContent (text, HTML_CONTENT_TYPE);
>
> // Send message
> Transport.send (message);
>
> }
>
>
>
>
>
> Why doesn't it work? What am I missing?
>
> One more thing I maybe should point out as well - The emailer
> is called from my 'UserServiceBean' which is a stateless Session bean.
> I hope this is valid, is it?
>
> I would really appreciate any help here :)
>
> Erez
>
--
Geir Magnusson Jr 203-247-1713(m)
geir@4quarters.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: can't load template
Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Mar 24, 2004, at 6:17 PM, Erez Efrati wrote:
> Hi there, I trying to work with the Velocity and keep complaining the
> following error message:
>
> " Unable to find resource 'resources.UserLoginInfo.vm' "
Do you really mean for the 'dot' to be between 'resources' and
'UserLoginInfo.vm'?
geir
>
> My application is contains the Logic (and EJB module) and Web (web
> module). the UserLoginInfo.vm is located under the resources directory.
> I am working with JBoss 3.2.3 /Tomcat 4.1.29.
>
> Here is my Emailer.java:
>
> Code:
>
>
> /**
> * A utility class that provides API for sending
> * templated emails per application use case.
> * <p>The <code>Emailer</code> uses Velocity SDK to generate
> * the templated emails.
> *
> * @author Erez Efrati
> * @version $Revision:$ $Date:$
> */
> public class Emailer {
>
> /**
> * JNDI context for JavaMail sessions.
> */
> private static final String JNDI_JAVA_MAIL = "java:/Mail";
>
> /**
> * The content type of the HTML email messages.
> */
> private static final String HTML_CONTENT_TYPE =
> "text/html;charset=UTF-8";
>
> /**
> * The user-login-info email template resource name.
> */
> private static final String VM_USER_LOGIN_INFO_REMINDER
>
> = "resources.UserLoginInfo.vm";
>
> // Velocity variable names keys
> private static final String VMVAR_USER = "user";
> private static final String VMVAR_SUBJECT = "subject";
>
> /**
> * the engine instance
> */
> VelocityEngine m_engine = new VelocityEngine ();
>
> // ------------------------------------------------------
> Private Methods
>
>
> /**
> * Configures the engine to use classpath to find templates
> *
> * @param engine the engine to
> configure
> * @throws Exception thrown if an errors occures
> */
> private void configure (VelocityEngine engine) throws
> Exception
> {
> Properties props = new Properties ();
> props.setProperty
> (VelocityEngine.RESOURCE_LOADER, "classpath");
> props.setProperty ("classpath." +
> VelocityEngine.RESOURCE_LOADER + ".class",
>
> ClasspathResourceLoader.class.getName());
> m_engine.init (props);
> }
>
>
> /**
> * Creates a Velocity context
> */
> private VelocityContext createContext()
> {
> VelocityContext ctx = new VelocityContext ();
> return ctx;
> }
>
> /**
> * Retreives a new JavaMail Mime message
> *
> * @return
> * @throws NamingException
> */
> private MimeMessage createMimeMessage() throws
> NamingException
> {
> Context initCtx = new InitialContext ();
> Session session = (Session)initCtx.lookup
> (JNDI_JAVA_MAIL);
> MimeMessage message = new MimeMessage
> (session);
> return message;
> }
>
> // ------------------------------------------------------
> Public Methods
>
> /**
> * Default constructor, configures the velocity engine.
> *
> * @throws Exception, if an error occures
> */
> public Emailer () throws Exception
> {
> configure (m_engine);
> }
>
>
> /**
> * Sends an email to the specified <code>user</code>
> containing
> * his login information which includes his username and
> password.
> *
> * @param user
> * @throws Exception
> */
> public void sendUserLoginInfo (User user) throws Exception
> {
> // retrieve the email template
> Template template = m_engine.getTemplate
> (VM_USER_LOGIN_INFO_REMINDER);
>
> // prepare the context and store data objects
> in
> it
> VelocityContext ctx = createContext ();
> ctx.put (VMVAR_USER, user);
>
> // merge the template
> StringWriter writer = new StringWriter ();
> template.merge (ctx, writer);
> writer.close ();
>
> // retrieve the message subject and text. The
> subject
> // is formulated as part of the email velocity
> template.
> StringBuffer text = writer.getBuffer();
> String subject = (String)ctx.get
> (VMVAR_SUBJECT);
>
> // create a new message to work with
>
> MimeMessage message = createMimeMessage ();
>
> // retrieve the user's email address
> String to = user.getEmail ();
>
> String from = App.getSupportEmailAddress ();
> message.setFrom (new InternetAddress (from));
> message.addRecipient (Message.RecipientType.TO,
>
> new InternetAddress (to));
>
> // set the subject and content
> message.setSubject (subject);
> message.setContent (text, HTML_CONTENT_TYPE);
>
> // Send message
> Transport.send (message);
>
> }
>
>
>
>
>
> Why doesn't it work? What am I missing?
>
> One more thing I maybe should point out as well - The emailer
> is called from my 'UserServiceBean' which is a stateless Session bean.
> I hope this is valid, is it?
>
> I would really appreciate any help here :)
>
> Erez
>
--
Geir Magnusson Jr 203-247-1713(m)
geir@4quarters.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org