Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In Vitro, the only listener in web.xml is the StartupManager. Here is the relevant section of Vitro’s web.xml:

Panelnoformat

 <!--

StartupManager instantiates and runs the listeners from
 
    StartupManager instantiates and runs the listeners from startup_listeners.txt

All ServletContextListeners should be listed there, not here.
-->
<listener>
 
    All ServletContextListeners should be listed there, not here.           
 -->
 <listener>
   <listener-class>edu.cornell.mannlib.vitro.webapp.startup.StartupManager</listener-class>


 </listener>
Panel

Vitro contains a list of startup listeners in a file at Vitro/webapp/config/startup_listeners.txt. This file is simple text with each line containing the fully-qualified class name of a startup listener. Blank lines are ignored, as are comment lines – lines that begin with a “hash” character. Here is a portion of that file:

Panelnoformat

#

  1. ServletContextListeners for Vitro,
  2. to be instantiated and run by the StartupManager.
    #
Panel

 #
 # ServletContextListeners for Vitro, 
 # to be instantiated and run by the StartupManager.
 #
 
 edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesSetup
Panel

 
 edu.cornell.mannlib.vitro.webapp.config.RevisionInfoSetup
Panel

 
 edu.cornell.mannlib.vitro.webapp.email.FreemarkerEmailFactory$Setup
Panel
  • DefaultThemeSetup needs to run before the JenaDataSourceSetup to allow creation
  • of default portal and tab
    
     
     # DefaultThemeSetup needs to run before the JenaDataSourceSetup to allow creation
     # of default portal and tab
     edu.cornell.mannlib.vitro.webapp.servlet.setup.DefaultThemeSetup
    

    Writing context listeners

    ...

    Here is an example of a basic listener. When contextInitialized() is called, the listener will perform some setup. If there is no problem, a call to StartupStatus.info() reports some basic information about the listener’s actions. If a problem is found, a call to StartupStatus.warning() describes the nature of the problem (by reporting the exception) and how this problem will affect the application.

    Panelnoformat
    
     public static class Setup implements ServletContextListener {

    @Override
    public void
    
        @Override
        public void contextInitialized(ServletContextEvent sce)
    {
    ServletContext ctx =
     {
            ServletContext ctx = sce.getServletContext();

    StartupStatus ss =
    
            StartupStatus ss = StartupStatus.getBean(ctx);
    Panel
    try {
    FreemarkerEmailFactory factory = new
    
     
            try {
                FreemarkerEmailFactory factory = new FreemarkerEmailFactory(ctx);

    
                ctx.setAttribute(ATTRIBUTE_NAME, factory);
    Panel
    if
    
     
                if (factory.isConfigured())
    {
     {
                    ss.info(this, "The system is configured to
    "
    + "send mail to
     "
                            + "send mail to users.");

    } else {
    
                } else {
                    ss.info(this, "Configuration parameters are missing:
    "
    + "the system will not send mail to
     "
                            + "the system will not send mail to users.");

    }
    } catch (Exception e) {
    
                }
            } catch (Exception e) {
                ss.warning(this,

    
                        "Failed to initialize FreemarkerEmailFactory.
    "
    + "The system will not be able to send email "
    + "to
     "
                                + "The system will not be able to send email "
                                + "to users.", e);

    }
    }
    Panel
    @Override
    public void
    
            }
        }
     
        @Override
        public void contextDestroyed(ServletContextEvent sce)
    {
     {
            sce.getServletContext().removeAttribute(ATTRIBUTE_NAME);

    }
    }
    
        }
     }
    

    Note that the StartupManager treats ServletContextListeners just like you would expect from reading the Servlet 2.4 specification:

    ...