tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glenn Nielsen <gl...@voyager.apg.more.net>
Subject Re: cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/factory MailSessionFactory.java ResourceFactory.java
Date Sun, 25 Mar 2001 01:25:49 GMT
Craig,

I have another version of a MailSessionFactory (I thought I had mentioned
I would take care of it).  It is identical to what you just commited,
with one exception.

It uses getInstance() instead of getDefaultInstance().  getDefaultInstance()
creates just one instance of a Session for the entire JVM which would be global
to all web applications.  With getInstance() you can configure different SMTP settings
per web application.

I also have an updated version of the Factory which creates a MimePartDataSource
which allows more generic configuration of SMTP settings like you did below.

Regards,

Glenn

craigmcc@apache.org wrote:
> 
>   /**
>    * <p>Factory class that creates a JNDI named JavaMail Session factory,
>    * which can be used for managing inbound and outbound electronic mail
>    * messages via JavaMail APIs.  All messaging environment properties
>    * described in the JavaMail Specification may be passed to the Session
>    * factory; however the following properties are the most commonly used:</p>
>    * <ul>
>    * <li>
>    * <li><strong>mail.smtp.host</strong> - Hostname for outbound transport
>    *     connections.  Defaults to <code>localhost</code> if not specified.</li>
>    * </ul>
>    *
>    * <p>This factory can be configured in a <code>&lt;DefaultContext&gt;</code>
>    * or <code>&lt;Context&gt;</code> element in your <code>conf/server.xml</code>
>    * configuration file.  An example of factory configuration is:</p>
>    * <pre>
>    * &lt;Resource name="mail/smtp" auth="CONTAINER"
>    *           type="javax.mail.Session"/&gt;
>    * &lt;ResourceParams name="mail/smtp"&gt;
>    *   &lt;parameter&gt;
>    *     &lt;name&gt;factory&lt;/name&gt;
>    *     &lt;value&gt;org.apache.naming.factory.MailSessionFactory&lt;/value&gt;
>    *   &lt;/parameter&gt;
>    *   &lt;parameter&gt;
>    *     &lt;name&gt;mail.smtp.host&lt;/name&gt;
>    *     &lt;value&gt;mail.mycompany.com&lt;/value&gt;
>    *   &lt;/parameter&gt;
>    * &lt;/ResourceParams&gt;
>    * </pre>
>    *
>    * @author Craig R. McClanahan
>    * @version $Revision: 1.1 $ $Date: 2001/03/24 20:52:07 $
>    */
> 
>   public class MailSessionFactory implements ObjectFactory {
> 
> 
>       /**
>        * The Java type for which this factory knows how to create objects.
>        */
>       protected static final String factoryType = "javax.mail.Session";
> 
> 
>       /**
>        * Create and return an object instance based on the specified
>        * characteristics.
>        *
>        * @param refObj Reference information containing our parameters, or null
>        *  if there are no parameters
>        * @param name The name of this object, relative to context, or null
>        *  if there is no name
>        * @param context The context to which name is relative, or null if name
>        *  is relative to the default initial context
>        * @param env Environment variables, or null if there are none
>        *
>        * @exception Exception if an error occurs during object creation
>        */
>       public Object getObjectInstance(Object refObj, Name name, Context context,
>                                     Hashtable env) throws Exception
>       {
> 
>           // Return null if we cannot create an object of the requested type
>         final Reference ref = (Reference) refObj;
>           if (!ref.getClassName().equals(factoryType))
>               return (null);
> 
>           // Create a new Session inside a doPrivileged block, so that JavaMail
>           // can read its default properties without throwing Security
>           // exceptions
>           return AccessController.doPrivileged( new PrivilegedAction() {
>                 public Object run() {
> 
>                       // Create the JavaMail properties we will use
>                       Properties props = new Properties();
>                       props.put("mail.transport.protocol", "smtp");
>                       props.put("mail.smtp.host", "localhost");
>                       Enumeration attrs = ref.getAll();
>                       while (attrs.hasMoreElements()) {
>                           RefAddr attr = (RefAddr) attrs.nextElement();
>                           if ("factory".equals(attr.getType()))
>                               continue;
>                           props.put(attr.getType(), (String) attr.getContent());
>                       }
> 
>                       // Create and return the new Session object
>                       Session session = Session.getDefaultInstance(props, null);
>                       return (session);
> 
>                 }
>             } );
> 
>       }
> 
> 
>   }
> 
> 
> 


----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------

Mime
View raw message