You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jm...@apache.org on 2001/12/19 19:52:17 UTC

cvs commit: jakarta-turbine-3/src/java/org/apache/turbine Turbine.java TurbineConstants.java

jmcnally    01/12/19 10:52:17

  Modified:    conf     TurbineResources.properties
               conf/master TurbineResources.master
               src/java/org/apache/turbine Turbine.java
                        TurbineConstants.java
  Log:
  added a mode configuration property to set whether the application will run
  as a normal standalone webapp, or if it will be integrated so that it is
  invoked by another application.  In the integrated case exceptions will be
  passed up to the calling application.  Also provided a request based method
  for specifying the mode, as the application may run in a mixed fashion.
  
  Moved the exception handling code into handleException.  Some was being handled
  directly by the doGet method while other errors were passed to the handleException
  method.
  (formatting is off, to keep the patch easier to read.  Will fix in an upcoming
  patch.)
  
  Revision  Changes    Path
  1.19      +21 -1     jakarta-turbine-3/conf/TurbineResources.properties
  
  Index: TurbineResources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/conf/TurbineResources.properties,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- TurbineResources.properties	2001/11/29 17:13:47	1.18
  +++ TurbineResources.properties	2001/12/19 18:52:17	1.19
  @@ -1,5 +1,5 @@
   # -------------------------------------------------------------------
  -# $Id: TurbineResources.properties,v 1.18 2001/11/29 17:13:47 mikeh Exp $
  +# $Id: TurbineResources.properties,v 1.19 2001/12/19 18:52:17 jmcnally Exp $
   #
   # This is the configuration file for Turbine.
   #
  @@ -85,6 +85,26 @@
   # category to DEBUG to see generated sql queries
   
   log4j.category.org.apache.fulcrum.db = INFO, torque
  +
  +# -------------------------------------------------------------------
  +#
  +#  M O D E
  +#
  +# -------------------------------------------------------------------
  +# If this turbine app will always be invoked from another application
  +# mode can be set to integrated which will cause Turbine to pass any
  +# errors up to the application that invoked Turbine.  Under standalone
  +# operation, Turbine swallows the error after sending an error page
  +# as the response.  If this Turbine application operates both as a 
  +# normal webapp and can be invoked from another application, set the 
  +# mode to standalone and see the Turbine servlet's javadoc for method
  +# to set the mode on a request basis.
  +#
  +# Possible values: standalone, integrated
  +# Default: standalone
  +# -------------------------------------------------------------------
  +
  +turbine.mode = standalone
   
   # -------------------------------------------------------------------
   #
  
  
  
  1.13      +21 -1     jakarta-turbine-3/conf/master/TurbineResources.master
  
  Index: TurbineResources.master
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/conf/master/TurbineResources.master,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TurbineResources.master	2001/11/29 17:03:37	1.12
  +++ TurbineResources.master	2001/12/19 18:52:17	1.13
  @@ -1,5 +1,5 @@
   # -------------------------------------------------------------------
  -# $Id: TurbineResources.master,v 1.12 2001/11/29 17:03:37 mikeh Exp $
  +# $Id: TurbineResources.master,v 1.13 2001/12/19 18:52:17 jmcnally Exp $
   #
   # This is the configuration file for Turbine.
   #
  @@ -85,6 +85,26 @@
   # category to DEBUG to see generated sql queries
   
   log4j.category.org.apache.fulcrum.db = INFO, torque
  +
  +# -------------------------------------------------------------------
  +#
  +#  M O D E
  +#
  +# -------------------------------------------------------------------
  +# If this turbine app will always be invoked from another application
  +# mode can be set to integrated which will cause Turbine to pass any
  +# errors up to the application that invoked Turbine.  Under standalone
  +# operation, Turbine swallows the error after sending an error page
  +# as the response.  If this Turbine application operates both as a 
  +# normal webapp and can be invoked from another application, set the 
  +# mode to standalone and see the Turbine servlet's javadoc for method
  +# to set the mode on a request basis.
  +#
  +# Possible values: standalone, integrated
  +# Default: standalone
  +# -------------------------------------------------------------------
  +
  +turbine.mode = standalone
   
   # -------------------------------------------------------------------
   #
  
  
  
  1.14      +57 -44    jakarta-turbine-3/src/java/org/apache/turbine/Turbine.java
  
  Index: Turbine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/Turbine.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Turbine.java	2001/12/04 05:00:39	1.13
  +++ Turbine.java	2001/12/19 18:52:17	1.14
  @@ -103,6 +103,13 @@
    * filesystem, that is the base of your web application.</li>
    * </ul><br>
    *
  + * If this servlet will always be invoked from another, set the TR.prop
  + * turbine.mode = integrated.  If this servlet will operate in a mixed
  + * case of standalone and integrated, set turbine.mode = standalone and
  + * integrated operation can be specified on a request basis by 
  + * <code>request.setAttribute("org.apache.turbine.integrated.request.key", 
  + * Boolean.TRUE);</code> prior to passing control to this servlet.
  + *
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
    * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
    * @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
  @@ -111,7 +118,7 @@
    * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
    * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
  - * @version $Id: Turbine.java,v 1.13 2001/12/04 05:00:39 jmcnally Exp $
  + * @version $Id: Turbine.java,v 1.14 2001/12/19 18:52:17 jmcnally Exp $
    */
   public class Turbine
       extends HttpServlet
  @@ -273,33 +280,12 @@
               // in catalina there is also a ValveContext which
               // can alter the execution path of the valves. What
               // is listed below here could eventually be anything :-)
  -            try
  -            {
  -                pipeline.process(data);
  -                pipeline.preExecuteAction(data);
  -                pipeline.executeAction(data);
  -                pipeline.postExecuteAction(data);
  -            }
  -            catch (Exception e)
  -            {
  -                data.setTarget(configuration
  -                    .getString("template.error","/Error.vm"));
  -                data.setStackTrace(StringUtils.stackTrace(e),e);
  -            }
  -            try
  -            {
  -                pipeline.execute(data);
  -                pipeline.finished(data);
  -            }
  -            catch (Exception f)
  -            {
  -                // try again with a different target
  -                data.setTarget(configuration
  -                    .getString("template.error","/Error.vm"));
  -                data.setStackTrace(StringUtils.stackTrace(f),f);
  -                pipeline.execute(data);
  -                pipeline.finished(data);
  -            }
  +            pipeline.process(data);
  +            pipeline.preExecuteAction(data);
  +            pipeline.executeAction(data);
  +            pipeline.postExecuteAction(data);
  +            pipeline.execute(data);
  +            pipeline.finished(data);
   
               /*
               TODO: Move this logic into the pipeline.
  @@ -314,28 +300,17 @@
               }
               */
           }
  -        catch (Exception e)
  -        {
  -            handleException(data, res, e);
  -        }
           catch (Throwable t)
           {
  -            handleException(data, res, t);
  +            handleException(data, req, res, t);
           }
           finally
           {
  -            // Make sure to close the outputstream when we are done.
  -            try
  -            {
  -                if (data.getOut() != null)
  -                {
  -                    data.getOut().close();
  -                }
  -            }
  -            catch (Exception ignored)
  -            {
  -            }
  +            closeOutputStream(data);
   
  +            // if the RunData has been added to the request, we assume
  +            // Turbine is being invoked from another servlet that will
  +            // handle returning the RunData.
               if ( req.getAttribute(RUNDATA_REQUEST_KEY) == null ) 
               {
                   // Return the used RunData to the factory for recycling.
  @@ -370,6 +345,21 @@
           return "Turbine Servlet @VERSION@";
       }
   
  +    private void closeOutputStream(RunData data)
  +    {
  +        // Make sure to close the outputstream when we are done.
  +        try
  +        {
  +            if (data.getOut() != null)
  +            {
  +                data.getOut().close();
  +            }
  +        }
  +        catch (Exception ignored)
  +        {
  +        }
  +    }
  +
       /**
        * This method is about making sure that we catch and display
        * errors to the screen in one fashion or another. What happens is
  @@ -384,13 +374,34 @@
        * @param e The exception to report.
        */
       private final void handleException(RunData data,
  +                                       HttpServletRequest req,
                                          HttpServletResponse res,
                                          Throwable t)
  +        throws ServletException
       {
           // make sure that the stack trace makes it the log
           Log.error("Turbine.handleException: " + t.getMessage());
           Log.error(t);
   
  +        if ( INTEGRATED.equals(configuration.getProperty(MODE)) ||
  +             req.getAttribute(INTEGRATED_REQUEST_KEY) != null ) 
  +        {
  +            // leave error handling to the invoking application
  +            throw new ServletException(t);
  +        }
  +        else 
  +        {        
  +        try
  +        {
  +            // try again with a different target
  +            data.setTarget(configuration
  +                           .getString("template.error","/Error.vm"));
  +            data.setStackTrace(StringUtils.stackTrace(t), t);
  +            pipeline.execute(data);
  +            pipeline.finished(data);
  +        }
  +        catch (Exception f)
  +        {
           String mimeType = "text/plain";
   
           try
  @@ -450,6 +461,8 @@
                   // ignored
               }
               Log.error (reallyScrewedNow.getMessage(), reallyScrewedNow );
  +        }
  +        }
           }
       }
   
  
  
  
  1.10      +23 -0     jakarta-turbine-3/src/java/org/apache/turbine/TurbineConstants.java
  
  Index: TurbineConstants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/TurbineConstants.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TurbineConstants.java	2001/12/04 05:00:39	1.9
  +++ TurbineConstants.java	2001/12/19 18:52:17	1.10
  @@ -333,6 +333,29 @@
       public static final String SYSTEM = "system";
   
   
  +    /**
  +     * Request key where a RunData object may be stored.  Useful in cases
  +     * where one application is invoked by another.
  +     */
       public static final String RUNDATA_REQUEST_KEY = 
           "org.apache.turbine.RunData.request.key";
  +
  +    /**
  +     * Request key for standalone vs. integrated operation.  If an object
  +     * exists under this key, integrated operation will be assumed
  +     * regardless of MODE set in the configuration.
  +     */
  +    public static final String INTEGRATED_REQUEST_KEY = 
  +        "org.apache.turbine.integrated.request.key";
  +
  +    /**
  +     * Configuration key for standalone vs. integrated operation.
  +     */
  +    public static final String MODE = "turbine.mode";
  +
  +    /**
  +     * Configuration value for MODE property, if not set to integrated, 
  +     * standalone is assumed.
  +     */
  +    public static final String INTEGRATED = "integrated";
   }
  
  
  

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