epugh       2003/03/21 21:07:37

  Modified:    proposals/epugh/compositeconfiguration Turbine.java
                        TurbineComplete.properties TurbineConfig.java
                        TurbineConfiguration.xml TurbineTest.java
  Added:       proposals/epugh/compositeconfiguration TurbineTest2.java
  Log:
  Finally got the configuration stuff working, ready for review!
  
  Revision  Changes    Path
  1.2       +40 -70    
jakarta-turbine-2/proposals/epugh/compositeconfiguration/Turbine.java
  
  Index: Turbine.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/proposals/epugh/compositeconfiguration/Turbine.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Turbine.java      19 Mar 2003 17:31:51 -0000      1.1
  +++ Turbine.java      22 Mar 2003 05:07:37 -0000      1.2
  @@ -58,21 +58,17 @@
   import java.io.FileInputStream;
   import java.io.FileNotFoundException;
   import java.io.IOException;
  -
   import java.util.Properties;
  -import java.util.Enumeration;
   
   import javax.servlet.ServletConfig;
   import javax.servlet.ServletContext;
   import javax.servlet.ServletException;
  -
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   
   import org.apache.commons.configuration.Configuration;
   import org.apache.commons.configuration.PropertiesConfiguration;
  -import org.apache.commons.configuration.ConfigurationFactory;
   
   import org.apache.commons.lang.StringUtils;
   
  @@ -89,26 +85,19 @@
   
   import org.apache.turbine.services.TurbineServices;
   import org.apache.turbine.services.avaloncomponent.AvalonComponentService;
  -
   import org.apache.turbine.services.component.ComponentService;
  -
   import org.apache.turbine.services.template.TemplateService;
   import org.apache.turbine.services.template.TurbineTemplate;
  -
   import org.apache.turbine.services.rundata.RunDataService;
   import org.apache.turbine.services.rundata.TurbineRunDataFacade;
  -
   import org.apache.turbine.services.velocity.VelocityService;
   
   import org.apache.turbine.util.RunData;
   import org.apache.turbine.util.ServerData;
   import org.apache.turbine.util.TurbineConfig;
   import org.apache.turbine.util.TurbineException;
  -
   import org.apache.turbine.util.security.AccessControlList;
  -
   import org.apache.turbine.util.template.TemplateInfo;
  -
   import org.apache.turbine.util.uri.URIConstants;
   
   /**
  @@ -119,12 +108,9 @@
    * If you need to override something in the <code>doGet()</code> or
    * <code>doPost()</code> methods, edit the TurbineResources.properties file and
    * specify your own classes there.
  - *
  - * <p> Turbine servlet recognizes the following initialization parameters.
  - *
  + * <p>
  + * Turbine servlet recognizes the following initialization parameters.
    * <ul>
  - * <li><code>resources</code> the implementation of
  - * [EMAIL PROTECTED] org.apache.turbine.services.resources.TurbineResources} to be 
used</li>
    * <li><code>properties</code> the path to TurbineResources.properties file
    * used by the default implementation of <code>ResourceService</code>, relative
    * to the application root.</li>
  @@ -133,7 +119,7 @@
    * support <code>ServletContext.getRealPath(String)</code> method correctly.
    * You can use this parameter to specify the directory within the server's
    * filesystem, that is the base of your web application.</li>
  - * </ul><br>
  + * </ul>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jon S. Stevens</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Brett McLaughlin</a>
  @@ -145,6 +131,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Sean Legassick</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Martin Poeschl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Quinton McCombs</a>
    * @version $Id$
    */
   public class Turbine
  @@ -239,7 +226,6 @@
               try
               {
                   ServletContext context = config.getServletContext();
  -       
   
                   configure(config, context);
   
  @@ -248,7 +234,6 @@
   
                   if (rundataService == null)
                   {
  -                    throw new TurbineException(
                               "No RunData Service configured!");
                   }
   
  @@ -264,29 +249,15 @@
           }
       }
   
  -    private void configure(ServletConfig config, ServletContext context)
  -            throws Exception
  +    private void configure(ServletConfig config, ServletContext context) throws 
Exception
       {
  -
  -        String configurationFile =
  -                           findInitParameter(context, config,
  -                                             TurbineConfig.CONFIGURATION_PATH_KEY,
  -                                             
TurbineConfig.CONFIGURATION_PATH_DEFAULT);
  -
  -        String propsFile =
  -                   findInitParameter(context, config,
  -                                     TurbineConfig.PROPERTIES_PATH_KEY,
  -                                     TurbineConfig.PROPERTIES_PATH_DEFAULT);
  -
  +        String configurationFile = findInitParameter(context, config, 
TurbineConfig.CONFIGURATION_PATH_KEY, null);
   
           // Set the application root. This defaults to the webapp
           // context if not otherwise set. This is to allow 2.1 apps
           // to be developed from CVS. This feature will carry over
           // into 3.0.
  -        applicationRoot =
  -            findInitParameter(context, config,
  -                              APPLICATION_ROOT_KEY,
  -                              APPLICATION_ROOT_DEFAULT);
  +        applicationRoot = findInitParameter(context, config, APPLICATION_ROOT_KEY, 
APPLICATION_ROOT_DEFAULT);
   
           webappRoot = config.getServletContext().getRealPath("/");
           // log.info("Web Application root is " + webappRoot);
  @@ -306,29 +277,42 @@
           createRuntimeDirectories(context, config);
   
           //
  -        // Set up logging as soon as possible
  +        // Set up configuration first off
           //
   
  -        String configurationPath = getRealPath(configurationFile);
  -        File testConfigurationFileExists = new File(configurationPath);
  -        if (!testConfigurationFileExists.exists()){
  -            log.info("Configuration file can't be found, defaulting to TR.props:" + 
propsFile);
  +        if (configurationFile != null)
  +        {
  +            String configurationFilePath = new 
File(getApplicationRoot(),configurationFile).toString();
  +            log.info("Loading configuration from " + configurationFilePath);
  +
  +            ConfigurationFactory configurationFactory = new ConfigurationFactory();
  +            log.info("path:" + getApplicationRoot());
  +            configurationFactory.setBasePath(getApplicationRoot());
  +            configurationFactory.setConfigurationFileName(configurationFilePath);
  +
  +            configuration = configurationFactory.getConfiguration();
  +
  +        }
  +        else
  +        {
  +            // if configuration.xml file is null, then try for a 
  +            // traditional TR.props
  +            String propsFile = null;
  +
  +            propsFile = findInitParameter(context, config, 
TurbineConfig.PROPERTIES_PATH_KEY, TurbineConfig.PROPERTIES_PATH_DEFAULT);
  +
  +            log.info("Configuration file not set, defaulting to TR.props:" + 
propsFile);
   
               String propsPath = getRealPath(propsFile);
               configuration = (Configuration) new PropertiesConfiguration(propsPath);
   
           }
  -        else {
  -            log.info("Loading configuration from " + configurationFile);
  -            
  -            ConfigurationFactory configurationFactory = new ConfigurationFactory();
  -            configurationFactory.setConfigurationFileName(configurationPath);
  -            
  -            configuration = configurationFactory.getConfiguration();        
  -        }
   
  -        String log4jFile = configuration.getString(LOG4J_CONFIG_FILE,
  -                                                   LOG4J_CONFIG_FILE_DEFAULT);
  +        //
  +        // Set up logging as soon as possible
  +        //
  +
  +        String log4jFile = configuration.getString(LOG4J_CONFIG_FILE, 
LOG4J_CONFIG_FILE_DEFAULT);
   
           log4jFile = getRealPath(log4jFile);
   
  @@ -879,24 +863,6 @@
       private void loginAction(RunData data)
               throws Exception
       {
  -        // If a User is logging in, we should refresh the
  -        // session here.  Invalidating session and starting a
  -        // new session would seem to be a good method, but I
  -        // (JDM) could not get this to work well (it always
  -        // required the user to login twice).  Maybe related
  -        // to JServ?  If we do not clear out the session, it
  -        // is possible a new User may accidently (if they
  -        // login incorrectly) continue on with information
  -        // associated with the previous User.  Currently the
  -        // only keys stored in the session are "turbine.user"
  -        // and "turbine.acl".
  -
  -        for( Enumeration enum = data.getSession().getAttributeNames();
  -                enum.hasMoreElements(); )
  -        {
  -            String attributeName = (String) enum.nextElement();
  -            data.getSession().removeAttribute(attributeName);
  -        }
           ActionLoader.getInstance().exec(data, data.getAction());
           cleanupTemplateContext(data);
           data.setAction(null);
  @@ -908,6 +874,9 @@
        * <p>
        * This Action must be performed before the Session validation for the
        * session validator to send us back to the Login screen.
  +     * <p>
  +     * The existing session is invalidated before the logout action is
  +     * executed.
        *
        * @param data a RunData object
        *
  @@ -916,6 +885,7 @@
       private void logoutAction(RunData data)
               throws Exception
       {
  +        data.getSession().invalidate();
           ActionLoader.getInstance().exec(data, data.getAction());
           cleanupTemplateContext(data);
           data.setAction(null);
  
  
  
  1.2       +0 -0      
jakarta-turbine-2/proposals/epugh/compositeconfiguration/TurbineComplete.properties
  
  Index: TurbineComplete.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/proposals/epugh/compositeconfiguration/TurbineComplete.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  
  
  
  1.2       +0 -7      
jakarta-turbine-2/proposals/epugh/compositeconfiguration/TurbineConfig.java
  
  Index: TurbineConfig.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/proposals/epugh/compositeconfiguration/TurbineConfig.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TurbineConfig.java        19 Mar 2003 17:31:51 -0000      1.1
  +++ TurbineConfig.java        22 Mar 2003 05:07:37 -0000      1.2
  @@ -116,7 +116,6 @@
        * Turbine.properties file used by Turbine
        */
       public static final String PROPERTIES_PATH_KEY = "properties";
  -    
       /**
          * Servlet initialization parameter name for the path to
          * TurbineConfiguration.xml file used by Turbine
  @@ -130,12 +129,6 @@
       public static final String PROPERTIES_PATH_DEFAULT =
               "/WEB-INF/conf/TurbineResources.properties";
   
  -    /**
  -     * Default value of TurbineResources.properties file path
  -     * (<code>/WEB-INF/conf/TurbineResources.properties</code>).
  -     */
  -    public static final String CONFIGURATION_PATH_DEFAULT =
  -            "/WEB-INF/conf/TurbineConfiguration.xml";
       /** Filenames are looked up in this directory. */
       private File root;
   
  
  
  
  1.2       +2 -2      
jakarta-turbine-2/proposals/epugh/compositeconfiguration/TurbineConfiguration.xml
  
  Index: TurbineConfiguration.xml
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/proposals/epugh/compositeconfiguration/TurbineConfiguration.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TurbineConfiguration.xml  19 Mar 2003 17:31:51 -0000      1.1
  +++ TurbineConfiguration.xml  22 Mar 2003 05:07:37 -0000      1.2
  @@ -1,8 +1,8 @@
   <?xml version="1.0" encoding="ISO-8859-1" ?>
   
   <configuration>
  -  <dom4j className="org.apache.commons.configuration.DOM4JConfiguration" 
fileName="c:/java/jakarta-turbine-2/src/test-cactus/testapp/WEB-INF/conf/TurbineResources.xml"/>
  -  <properties className="org.apache.commons.configuration.PropertiesConfiguration" 
fileName="c:/java/jakarta-turbine-2/src/test-cactus/testapp/WEB-INF/conf/TurbineComplete.properties"/>
  +  <dom4j className="org.apache.commons.configuration.DOM4JConfiguration" 
fileName="/WEB-INF/conf/TurbineResources.xml"/>
  +  <properties className="org.apache.commons.configuration.PropertiesConfiguration" 
fileName="/WEB-INF/conf/TurbineComplete.properties"/>
   </configuration>
   
     
  
  
  
  1.2       +3 -28     
jakarta-turbine-2/proposals/epugh/compositeconfiguration/TurbineTest.java
  
  Index: TurbineTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/proposals/epugh/compositeconfiguration/TurbineTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TurbineTest.java  19 Mar 2003 17:31:51 -0000      1.1
  +++ TurbineTest.java  22 Mar 2003 05:07:37 -0000      1.2
  @@ -63,7 +63,8 @@
   import org.apache.turbine.Turbine;
   import org.apache.commons.configuration.Configuration;
   /**
  - * Test starting up Turbine with various parameters.
  + * Test starting up Turbine with various parameters.  Because I can't get
  + * shutdown to work, I made two tests.
    *
    * @author <a href="[EMAIL PROTECTED]">Eric Pugh</a>
    * @version $Id$
  @@ -164,7 +165,7 @@
       {
           config.setInitParameter(
               "properties",
  -            "/WEB-INF/conf/TurbineComplete.properties");
  +            "WEB-INF/conf/TurbineComplete.properties");
   
           turbine.init(config);
           assertNotNull("Make sure turbine loaded", turbine);
  @@ -176,31 +177,5 @@
               configuration.getString("url.case.folding"));
       }
   
  -    /**
  -     * Simple test that verify that turbine can start up with a
  -     * configuration.xml file
  -     * @throws Exception
  -     */
  -    public void testCreateTurbineWithConfigurationXML() throws Exception
  -    {
  -        config.setInitParameter(
  -            "configuration",
  -            "/WEB-INF/conf/TurbineConfiguration.xml");
  -
     
  -        turbine.init(config);
  -        assertNotNull("Make sure turbine loaded", turbine);
  -
  -        configuration = turbine.getConfiguration();
  -        assertTrue("Make sure we have values", !configuration.isEmpty());
  -        assertEquals(
  -            "Read a config value",
  -            "lower",
  -            configuration.getString("url.case.folding"));
  -
  -        assertEquals(
  -            "Read in an overridden config value",
  -            "WEB-INF/conf/specialIntake.xml",
  -            configuration.getString("services.IntakeService.xml.path"));
  -    }
   }
  
  
  
  1.1                  
jakarta-turbine-2/proposals/epugh/compositeconfiguration/TurbineTest2.java
  
  Index: TurbineTest2.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.turbine;
  
  // Cactus and Junit imports
  import junit.awtui.TestRunner;
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import org.apache.cactus.*;
  
  import org.apache.turbine.Turbine;
  import org.apache.commons.configuration.Configuration;
  /**
   * Test starting up Turbine with various parameters.  Because I can't get
   * shutdown to work, I made two tests.
   *
   * @author <a href="[EMAIL PROTECTED]">Eric Pugh</a>
   * @version $Id: TurbineTest2.java,v 1.1 2003/03/22 05:07:37 epugh Exp $
   */
  public class TurbineTest2 extends ServletTestCase
  {
      private Configuration configuration = null;
      private Turbine turbine = null;
  
      /**
       * Defines the testcase name for JUnit.
       *
       * @param name the testcase's name.
       */
      public TurbineTest2(String name)
      {
          super(name);
      }
  
      /**
       * Start the tests.
       *
       * @param args the arguments. Not used
       */
      public static void main(String args[])
      {
          TestRunner.main(new String[] { TurbineTest2.class.getName()});
      }
  
      /**
       * Creates the test suite.
       *
       * @return a test suite (<code>TestSuite</code>) that includes all methods
       *         starting with "test"
       */
      public static Test suite()
      {
          // All methods starting with "test" will be executed in the test suite.
          return new TestSuite(TurbineTest2.class);
      }
  
      /**
       * This setup will be running server side.  We startup Turbine and
       * get our test port from the properties.  This gets run before
       * each testXXX test.
       */
      protected void setUp() throws Exception
      {
          super.setUp();
          configuration = null;
          turbine = new Turbine();
  
      }
  
      /**
       * After each testXXX test runs, shut down the Turbine servlet.
       */
      protected void tearDown() throws Exception
      {
          if (turbine != null)
          {
              turbine.destroy();
          }
          super.tearDown();
      }
  
      /**
       * Simple test that verify that turbine throws an exception 
       * when all parameters are missing, and the default TR.props
       * doesn't exists
       * @throws Exception
       */
      public void offtestCreateTurbineNoParameters() throws Exception
      {
  //System.out.println("Config:" + config.getInitParameter("properties"))
          try
          {
  
              
              turbine.init(config);
              fail(
                  "Should have thrown a javax.servlet.ServletException "
                      + "because the default TR.props doesn't exist!");
          }
          catch (javax.servlet.ServletException se)
          {
              turbine = null;
          }
          assertTrue("Make sure turbine is null", turbine == null);
      }
  
      /**
       * Simple test that verify that turbine can start up with a
       * configuration.xml file
       * @throws Exception
       */
      public void testCreateTurbineWithConfigurationXML() throws Exception
      {
          config.setInitParameter(
              "configuration",
              "WEB-INF/conf/TurbineConfiguration.xml");
  
    
          turbine.init(config);
          assertNotNull("Make sure turbine loaded", turbine);
  
          configuration = turbine.getConfiguration();
          assertTrue("Make sure we have values", !configuration.isEmpty());
          assertEquals(
              "Read a config value",
              "lower",
              configuration.getString("url.case.folding"));
  
          assertEquals(
              "Read in an overridden config value",
              "WEB-INF/conf/specialIntake.xml",
              configuration.getString("services.IntakeService.xml.path"));
      }
  }
  
  
  

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

Reply via email to