Since I ran into this problem I've stated to dive into the issues of
class loading in JBoss which is not a light subject, to say the least.
What do you mean by "the Singleton model"? Did you solve it? Going back
to 3.2.1 is not an option. Some while ago I started working with some
package called SecurityFilter and it had also problems of class loading
nature. The problem was related to the way the class loader was
selected, which is used to load the resource/classes. They had it
working under Tomcat as standalone so I went and made a small one-line
fix and made it work for JBoss. Maybe this is the same story here. Class
loading issues make me go crazy sometimes :)

Please let me know if you come up with something.

Thanks,

Erez E

-----Original Message-----
From: John Randall [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 25, 2004 1:57 AM
To: Velocity Users List
Subject: RE: can't load template

I am having the same problem when I upgraded to Jboss 3.2.3.
Everything worked before in Jboss 3.2.1. I think it has something to do
with the Singleton model.

-----Original Message-----
From: Erez Efrati [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 24, 2004 5:17 PM
To: [EMAIL PROTECTED]
Subject: 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

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to