You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by vm...@apache.org on 2002/05/19 22:34:15 UTC

cvs commit: jakarta-cactus/framework/src/java/share/org/apache/cactus/util Configuration.java JspConfiguration.java ServletConfiguration.java

vmassol     02/05/19 13:34:15

  Modified:    documentation/docs/xdocs changes.xml howto_runner.xml
                        howto_tomcat.xml
               framework/src/java/j2ee13/org/apache/cactus/util
                        FilterConfiguration.java
               framework/src/java/share/org/apache/cactus/server/runner
                        ServletTestRunner.java
               framework/src/java/share/org/apache/cactus/util
                        Configuration.java JspConfiguration.java
                        ServletConfiguration.java
  Log:
  no need to have a cactus.properties file anymore (it is possible to configure values using Java system properties - The new ServletTestRunner does this automatically for you).
  
  Revision  Changes    Path
  1.16      +7 -0      jakarta-cactus/documentation/docs/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/documentation/docs/xdocs/changes.xml,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- changes.xml	14 May 2002 22:28:05 -0000	1.15
  +++ changes.xml	19 May 2002 20:34:14 -0000	1.16
  @@ -48,6 +48,13 @@
       </devs>
   
       <release version="1.4 in CVS">
  +      <action dev="VMA" type="update">
  +        It is now possible to specify the Cactus properties as System
  +        properties (the property names are the same as the ones in
  +        <code>cactus.properties</code>). Also if not specified, redirector
  +        names are set by default to "ServletRedirector", "JspRedirector" and
  +        "FilterRedirector".
  +      </action>
         <action dev="VMA" type="add">
           New <link href="howto_tomcat.html">Quick start tutorial</link> that
           explains how to run Cactus tests quickly in Tomcat.
  
  
  
  1.3       +1 -11     jakarta-cactus/documentation/docs/xdocs/howto_runner.xml
  
  Index: howto_runner.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/documentation/docs/xdocs/howto_runner.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- howto_runner.xml	14 May 2002 22:28:05 -0000	1.2
  +++ howto_runner.xml	19 May 2002 20:34:14 -0000	1.3
  @@ -122,17 +122,7 @@
   
         </s2>
   
  -      <s2 title="Step 3 : cactus.properties">
  -
  -        <p>
  -          Lastly, you need to ensure you have put your
  -          <code>cactus.properties</code> file in your webapp
  -          <code>WEB-INF/classes</code> directory.
  -        </p>
  -
  -      </s2>
  -
  -      <s2 title="Step 4 : Executing the tests">
  +      <s2 title="Step 3 : Executing the tests">
   
           <p>
             Open a browser and type <code>http://server:port/mywebapp/ServletTestRunner?suite=mytestcase</code>
  
  
  
  1.2       +3 -28     jakarta-cactus/documentation/docs/xdocs/howto_tomcat.xml
  
  Index: howto_tomcat.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/documentation/docs/xdocs/howto_tomcat.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- howto_tomcat.xml	14 May 2002 22:28:05 -0000	1.1
  +++ howto_tomcat.xml	19 May 2002 20:34:14 -0000	1.2
  @@ -21,7 +21,7 @@
   
         <p>
           This document is a step by step tutorial that explains how to set up
  -        Cactus and run Cactus tests in Tomcat in less than 20 minutes !
  +        Cactus and run Cactus tests in Tomcat in less than 10 minutes !
           (discounting download time of course :-)).
         </p>
         <p>
  @@ -222,32 +222,7 @@
   
       </s1>
   
  -    <s1 title="Step 5 : Configure Cactus">
  -
  -      <p>
  -        This is the last step. Create a file named
  -        <code>cactus.properties</code> with the following content and copy
  -        it to <code>[tomcat root]/webapps/test/WEB-INF/classes</code>.
  -      </p>
  -
  -<source><![CDATA[
  -# Configuration file for Cactus.
  -
  -# Web app Context under which our application to test runs
  -cactus.contextURL = http://localhost:8080/test
  -
  -# Default Servlet Redirector Name. Used by ServletTestCase test cases.
  -cactus.servletRedirectorName = ServletRedirector
  -]]></source>
  -
  -      <note>
  -        This assumes Tomcat is running on port 8080. Modify with your port if
  -        you're using a different one (default is 8080).
  -      </note>
  -
  -    </s1>
  -
  -    <s1 title="Step 6 : Run the test">
  +    <s1 title="Step 5 : Run the test">
   
         <p>
           Time to enjoy our hard work ! Start Tomcat by running
  @@ -264,7 +239,7 @@
   
       </s1>
   
  -    <s1 title="Step 7 : Even more fun !">
  +    <s1 title="Step 6 : Even more fun !">
         <p>
           Ok, that's nice ... But what if I want HTML instead of XML ? Don't
           worry there is a solution. Grab the following
  
  
  
  1.2       +28 -4     jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/util/FilterConfiguration.java
  
  Index: FilterConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/util/FilterConfiguration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FilterConfiguration.java	5 May 2002 14:28:50 -0000	1.1
  +++ FilterConfiguration.java	19 May 2002 20:34:14 -0000	1.2
  @@ -56,21 +56,45 @@
    */
   package org.apache.cactus.util;
   
  +import java.util.MissingResourceException;
  +
   /**
    * Provides acces to Filter specific configuration parameters.
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: FilterConfiguration.java,v 1.1 2002/05/05 14:28:50 vmassol Exp $
  + * @version $Id: FilterConfiguration.java,v 1.2 2002/05/19 20:34:14 vmassol Exp $
    */
   public class FilterConfiguration extends Configuration
   {
       /**
  -     * @return the Filter redirector
  +     * Name of the cactus property that specifies the name of the JSP
  +     * redirector.
  +     */
  +    public static final String CACTUS_FILTER_REDIRECTOR_NAME_PROPERTY =
  +        "cactus.filterRedirectorName";
  +
  +    /**
  +     * Read the Filter redirector name from a System property first and then
  +     * if it fails from the Cactus configuration file and then use the default
  +     * "FilterRedirector" name if it fails.
  +     *
  +     * @return the Filter redirector URL
        */
       public static String getFilterRedirectorURL()
       {
  -        return getContextURL() + "/" +
  -            getConfiguration().getString("cactus.filterRedirectorName");
  +        // Try to read it from a System property first and then if it fails
  +        // from the Cactus configuration file.
  +        String filterRedirectorName =
  +            System.getProperty(CACTUS_FILTER_REDIRECTOR_NAME_PROPERTY);
  +        if (filterRedirectorName == null) {
  +            try {
  +                filterRedirectorName = getConfiguration().getString(
  +                    CACTUS_FILTER_REDIRECTOR_NAME_PROPERTY);
  +            } catch (MissingResourceException e) {
  +                filterRedirectorName = "FilterRedirector";
  +            }
  +        }
  +        return getContextURL() + "/" + filterRedirectorName;
       }
   }
  
  
  
  1.3       +8 -1      jakarta-cactus/framework/src/java/share/org/apache/cactus/server/runner/ServletTestRunner.java
  
  Index: ServletTestRunner.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/runner/ServletTestRunner.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ServletTestRunner.java	13 May 2002 13:36:33 -0000	1.2
  +++ ServletTestRunner.java	19 May 2002 20:34:14 -0000	1.3
  @@ -64,6 +64,7 @@
   import javax.servlet.ServletException;
   
   import org.apache.cactus.util.log.LogService;
  +import org.apache.cactus.util.Configuration;
   import junit.framework.TestResult;
   import junit.framework.Test;
   
  @@ -72,7 +73,7 @@
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: ServletTestRunner.java,v 1.2 2002/05/13 13:36:33 vmassol Exp $
  + * @version $Id: ServletTestRunner.java,v 1.3 2002/05/19 20:34:14 vmassol Exp $
    */
   public class ServletTestRunner extends HttpServlet
   {
  @@ -119,6 +120,12 @@
   
           // Get the XSL stylesheet parameter if any
           String xslParam = theRequest.getParameter(HTTP_XSL_PARAM);
  +
  +        // Set up default Cactus System properties so that there is no need
  +        // to have a cactus.properties file in WEB-INF/classes
  +        System.setProperty(Configuration.CACTUS_CONTEXT_URL_PROPERTY,
  +            "http://" + theRequest.getServerName() + ":" +
  +            theRequest.getServerPort() + theRequest.getContextPath());
   
           // Run the tests
           String xml = run(suiteClassName, xslParam);
  
  
  
  1.5       +29 -5     jakarta-cactus/framework/src/java/share/org/apache/cactus/util/Configuration.java
  
  Index: Configuration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/util/Configuration.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Configuration.java	17 May 2002 12:55:35 -0000	1.4
  +++ Configuration.java	19 May 2002 20:34:14 -0000	1.5
  @@ -60,13 +60,14 @@
   import java.io.IOException;
   import java.util.PropertyResourceBundle;
   import java.util.ResourceBundle;
  +import java.util.MissingResourceException;
   
   /**
    * Provides acces to the Cactus configuration.
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: Configuration.java,v 1.4 2002/05/17 12:55:35 vmassol Exp $
  + * @version $Id: Configuration.java,v 1.5 2002/05/19 20:34:14 vmassol Exp $
    */
   public class Configuration
   {
  @@ -87,10 +88,18 @@
        * Name of property in Cactus configuration file that enables Cactus
        * logging.
        */
  -    private static final String ENABLE_LOGGING_PROPERTY =
  +    public static final String CACTUS_ENABLE_LOGGING_PROPERTY =
           "cactus.enableLogging";
   
       /**
  +     * Name of Cactus property that specify the URL up to the webapp context.
  +     * This is the base URL to call for the redirectors. It is made up of :
  +     * "http://" + serverName + port + "/" + contextName.
  +     */
  +    public static final String CACTUS_CONTEXT_URL_PROPERTY =
  +        "cactus.contextURL";
  +
  +    /**
        * Properties file holding configuration data for Cactus.
        */
       private static ResourceBundle config = null;
  @@ -132,7 +141,14 @@
        */
       public static String getContextURL()
       {
  -        return getConfiguration().getString("cactus.contextURL");
  +        // Try to read it from a System property first and then if it fails
  +        // from the Cactus configuration file.
  +        String contextURL = System.getProperty(CACTUS_CONTEXT_URL_PROPERTY);
  +        if (contextURL == null) {
  +            contextURL =
  +                getConfiguration().getString(CACTUS_CONTEXT_URL_PROPERTY);
  +        }
  +        return contextURL;
       }
   
       /**
  @@ -140,7 +156,15 @@
        */
       public static boolean isLoggingEnabled()
       {
  -        return Boolean.valueOf(getConfiguration().
  -            getString(ENABLE_LOGGING_PROPERTY)).booleanValue();
  +        boolean isLoggingEnabled = false;
  +
  +        try {
  +            isLoggingEnabled = Boolean.valueOf(getConfiguration().
  +                getString(CACTUS_ENABLE_LOGGING_PROPERTY)).booleanValue();
  +        } catch (MissingResourceException e) {
  +            // logging property not found, we disable logging by default
  +            isLoggingEnabled = false;
  +        }
  +        return isLoggingEnabled;
       }
   }
  
  
  
  1.2       +28 -4     jakarta-cactus/framework/src/java/share/org/apache/cactus/util/JspConfiguration.java
  
  Index: JspConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/util/JspConfiguration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JspConfiguration.java	5 May 2002 14:28:50 -0000	1.1
  +++ JspConfiguration.java	19 May 2002 20:34:14 -0000	1.2
  @@ -56,21 +56,45 @@
    */
   package org.apache.cactus.util;
   
  +import java.util.MissingResourceException;
  +
   /**
    * Provides acces to JSP specific configuration parameters.
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: JspConfiguration.java,v 1.1 2002/05/05 14:28:50 vmassol Exp $
  + * @version $Id: JspConfiguration.java,v 1.2 2002/05/19 20:34:14 vmassol Exp $
    */
   public class JspConfiguration extends Configuration
   {
       /**
  -     * @return the JSP redirector
  +     * Name of the cactus property that specifies the name of the JSP
  +     * redirector.
  +     */
  +    public static final String CACTUS_JSP_REDIRECTOR_NAME_PROPERTY =
  +        "cactus.jspRedirectorName";
  +
  +    /**
  +     * Read the JSP redirector name from a System property first and then
  +     * if it fails from the Cactus configuration file and then use the default
  +     * "JspRedirector" name if it fails.
  +     *
  +     * @return the JSP redirector URL
        */
       public static String getJspRedirectorURL()
       {
  -        return getContextURL() + "/" +
  -            getConfiguration().getString("cactus.jspRedirectorName");
  +        // Try to read it from a System property first and then if it fails
  +        // from the Cactus configuration file.
  +        String jspRedirectorName =
  +            System.getProperty(CACTUS_JSP_REDIRECTOR_NAME_PROPERTY);
  +        if (jspRedirectorName == null) {
  +            try {
  +                jspRedirectorName = getConfiguration().getString(
  +                    CACTUS_JSP_REDIRECTOR_NAME_PROPERTY);
  +            } catch (MissingResourceException e) {
  +                jspRedirectorName = "JspRedirector";
  +            }
  +        }
  +        return getContextURL() + "/" + jspRedirectorName;
       }
   }
  
  
  
  1.2       +26 -4     jakarta-cactus/framework/src/java/share/org/apache/cactus/util/ServletConfiguration.java
  
  Index: ServletConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/util/ServletConfiguration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletConfiguration.java	5 May 2002 14:28:50 -0000	1.1
  +++ ServletConfiguration.java	19 May 2002 20:34:14 -0000	1.2
  @@ -56,21 +56,43 @@
    */
   package org.apache.cactus.util;
   
  +import java.util.MissingResourceException;
  +
   /**
    * Provides acces to Servlet specific configuration parameters.
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: ServletConfiguration.java,v 1.1 2002/05/05 14:28:50 vmassol Exp $
  + * @version $Id: ServletConfiguration.java,v 1.2 2002/05/19 20:34:14 vmassol Exp $
    */
   public class ServletConfiguration extends Configuration
   {
       /**
  -     * @return the Servlet redirector
  +     * Name of the cactus property that specifies the name of the Servlet
  +     * redirector.
  +     */
  +    public static final String CACTUS_SERVLET_REDIRECTOR_NAME_PROPERTY =
  +        "cactus.servletRedirectorName";
  +
  +    /**
  +     * Read the Servlet redirector name from a System property first and then
  +     * if it fails from the Cactus configuration file and then use the default
  +     * "ServletRedirector" name if it fails.
  +     *
  +     * @return the Servlet redirector URL
        */
       public static String getServletRedirectorURL()
       {
  -        return getContextURL() + "/" +
  -            getConfiguration().getString("cactus.servletRedirectorName");
  +        String servletRedirectorName =
  +            System.getProperty(CACTUS_SERVLET_REDIRECTOR_NAME_PROPERTY);
  +        if (servletRedirectorName == null) {
  +            try {
  +                servletRedirectorName = getConfiguration().getString(
  +                    CACTUS_SERVLET_REDIRECTOR_NAME_PROPERTY);
  +            } catch (MissingResourceException e) {
  +                servletRedirectorName = "ServletRedirector";
  +            }
  +        }
  +        return getContextURL() + "/" + servletRedirectorName;
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>