You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jt...@apache.org on 2002/03/05 00:45:35 UTC
cvs commit: jakarta-turbine-3/src/java/org/apache/turbine/exception DefaultExceptionHandler.java
jtaylor 02/03/04 15:45:35
Modified: . build-test.xml default.properties deps.list
src/java/org/apache/turbine Turbine.java
TurbineConstants.java
Added: src/java/org/apache/turbine ExceptionHandler.java
src/java/org/apache/turbine/exception
DefaultExceptionHandler.java
Log:
Breaks out the first attempt at handling an exception thrown by the pipeline
into another 'pluggable' handler. This allows users to define more complicated
error handling if they need it (like advanced logging or emailing of fatal
errors). The default behavior if nothing is configured should be unchanged.
I'm not so sure about the package name (too general?) but I'm following
Jason's suggestion. We can change it in the repository if somebody feels
strongly about it.
Revision Changes Path
1.13 +3 -0 jakarta-turbine-3/build-test.xml
Index: build-test.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-3/build-test.xml,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- build-test.xml 11 Feb 2002 23:58:05 -0000 1.12
+++ build-test.xml 4 Mar 2002 23:45:35 -0000 1.13
@@ -17,6 +17,7 @@
<pathelement location="${commons-beanutils.jar}"/>
<pathelement location="${commons-collections.jar}"/>
<pathelement location="${commons-util.jar}"/>
+ <pathelement location="${commons-io.jar}"/>
<pathelement location="${fulcrum.jar}"/>
<pathelement location="${servlet.jar}"/>
<pathelement location="${stratum.jar}"/>
@@ -241,6 +242,7 @@
<copy file="${commons-beanutils.jar}" todir="${build.dir}/rttest/lib"/>
<copy file="${commons-collections.jar}" todir="${build.dir}/rttest/lib"/>
<copy file="${commons-util.jar}" todir="${build.dir}/rttest/lib"/>
+ <copy file="${commons-io.jar}" todir="${build.dir}/rttest/lib"/>
<copy file="${dom4j.jar}" todir="${build.dir}/rttest/lib"/>
<copy file="${fulcrum.jar}" todir="${build.dir}/rttest/lib"/>
<copy file="${junit.jar}" todir="${build.dir}/rttest/lib"/>
@@ -249,6 +251,7 @@
<copy file="${velocity.jar}" todir="${build.dir}/rttest/lib"/>
<copy file="${jgen.jar}" todir="${build.dir}/rttest/lib"/>
<copy file="${commons-jxpath.jar}" todir="${build.dir}/rttest/lib"/>
+ <copy file="${httpunit.jar}" todir="${build.dir}/rttest/lib"/>
<antcall target="copy-aspectj-runtime"/>
1.18 +1 -0 jakarta-turbine-3/default.properties
Index: default.properties
===================================================================
RCS file: /home/cvs/jakarta-turbine-3/default.properties,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- default.properties 17 Feb 2002 06:41:26 -0000 1.17
+++ default.properties 4 Mar 2002 23:45:35 -0000 1.18
@@ -41,6 +41,7 @@
xmlParserAPIs.jar = ${lib.repo}/xmlParserAPIs-2.0.0.jar
commons-collections.jar = ${lib.repo}/commons-collections.jar
commons-util.jar = ${lib.repo}/commons-util-0.1-dev.jar
+commons-io.jar = ${lib.repo}/commons-io.jar
stratum.jar = ${lib.repo}/stratum-0.1-dev.jar
dom4j.jar = ${lib.repo}/dom4j-1.1.jar
commons-beanutils.jar = ${lib.repo}/commons-beanutils.jar
1.8 +1 -0 jakarta-turbine-3/deps.list
Index: deps.list
===================================================================
RCS file: /home/cvs/jakarta-turbine-3/deps.list,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- deps.list 17 Feb 2002 06:41:26 -0000 1.7
+++ deps.list 4 Mar 2002 23:45:35 -0000 1.8
@@ -4,6 +4,7 @@
commons-beanutils.jar
commons-collections.jar
commons-util-0.1-dev.jar
+commons-io.jar
dom4j-1.1.jar
fulcrum-1.0.jar
httpclient.jar
1.29 +13 -24 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.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- Turbine.java 10 Feb 2002 08:19:30 -0000 1.28
+++ Turbine.java 4 Mar 2002 23:45:35 -0000 1.29
@@ -123,7 +123,7 @@
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
* @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
* @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
- * @version $Id: Turbine.java,v 1.28 2002/02/10 08:19:30 dlr Exp $
+ * @version $Id: Turbine.java,v 1.29 2002/03/04 23:45:35 jtaylor Exp $
*/
public class Turbine
extends HttpServlet
@@ -390,13 +390,7 @@
{
try
{
- // try again with a different target
- data.setTarget(configuration.getString("template.error","/Error.vm"));
- data.setStackTrace(StringUtils.stackTrace(t), t);
-
- // We act as a minimal Pipeline here to run the target
- // set above.
- new DefaultTargetValve().invoke(data, new NullValveContext());
+ exceptionHandler.handleException( data, t );
}
catch (Exception f)
{
@@ -530,6 +524,8 @@
private static Resolver resolver;
+ private static ExceptionHandler exceptionHandler;
+
private static Pipeline pipeline;
private static RunDataService runDataService;
@@ -652,6 +648,15 @@
resolver = (Resolver) Class.forName(resolverClass).newInstance();
resolver.init();
+ // Create the error handler
+
+ String exceptionHandlerClass =
+ configuration.getString( EXCEPTION_HANDLER,
+ "org.apache.turbine.exception.DefaultExceptionHandler" );
+
+ exceptionHandler = ( ExceptionHandler )
+ Class.forName( exceptionHandlerClass ).newInstance();
+
// Set some system properties
Configuration systemProperties = configuration.subset(SYSTEM);
@@ -909,22 +914,6 @@
Date expiryDate = new Date( System.currentTimeMillis() + expiry );
data.getResponse().setHeader(
"Expires", HttpUtils.formatHttpDate(expiryDate));
- }
- }
-
- /**
- * A skeleton {@link org.apache.turbine.ValveContext}
- * implementation to assist in invoking DefaultTargetValve in
- * {@link #handleException(RunData, HttpServletRequest,
- * HttpServletResponse, Throwable)}.
- */
- protected final class NullValveContext implements ValveContext
- {
- /**
- * No-op implementation of ValveContext interface.
- */
- public void invokeNext(RunData ignored)
- {
}
}
}
1.14 +5 -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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- TurbineConstants.java 4 Feb 2002 17:16:05 -0000 1.13
+++ TurbineConstants.java 4 Mar 2002 23:45:35 -0000 1.14
@@ -124,6 +124,11 @@
public static final String MODULE_PACKAGES = "module.packages";
/**
+ * Configuration key for the ExceptionHandler that Turbine will use.
+ */
+ public static final String EXCEPTION_HANDLER = "exceptionHandler.default" ;
+
+ /**
* what resolver Turbine will use
*/
public static final String RESOLVER = "resolver.default";
1.1 jakarta-turbine-3/src/java/org/apache/turbine/ExceptionHandler.java
Index: ExceptionHandler.java
===================================================================
package org.apache.turbine;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", 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/>.
*/
/**
* Interface that defines an exception handler for the Turbine servlet. If a
* throwable is thrown by the pipeline, the servlet will pass the Throwable
* and RunData to the handleException method of the configured ExceptionHandler
* to deal with.
*
* @author <a href="mailto:james@jamestaylor.org">James Taylor</a>
* @version $Id: ExceptionHandler.java,v 1.1 2002/03/04 23:45:35 jtaylor Exp $
*/
public interface ExceptionHandler
{
/**
* This method will be called to handle a throwable thrown by the pipeline
*
* @param data RunData for the request where the error occured
* @param throwable The throwable that was thrown
*
* @throw Exception if an error occurs handling the throwable. Turbine will
* then attempt to provide some minimal handling.
*/
public void handleException( RunData data, Throwable throwable )
throws Exception;
}
1.1 jakarta-turbine-3/src/java/org/apache/turbine/exception/DefaultExceptionHandler.java
Index: DefaultExceptionHandler.java
===================================================================
package org.apache.turbine.exception;
import org.apache.turbine.ExceptionHandler;
import org.apache.turbine.RunData;
import org.apache.turbine.Turbine;
import org.apache.turbine.ValveContext;
import org.apache.turbine.pipeline.DefaultTargetValve;
import org.apache.commons.util.StringUtils;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", 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/>.
*/
/**
* The default exception handler for {@link Turbine}. Populates the RunData
* with information on the throwable, and then renders the template specified
* by the 'template.error' configuration property.
*
* @author <a href="mailto:james@jamestaylor.org">James Taylor</a>
* @version $Id: DefaultExceptionHandler.java,v 1.1 2002/03/04 23:45:35 jtaylor Exp $
*/
public class DefaultExceptionHandler implements ExceptionHandler
{
/**
* @see ExceptionHandler#handleException
*/
public void handleException( RunData data, Throwable throwable )
throws Exception
{
data.setTarget( Turbine.getConfiguration()
.getString( "template.error", "/Error.vm" ) );
data.setStackTrace( StringUtils.stackTrace( throwable ), throwable );
// Simulate a minimal Pipeline here to run the target.
new DefaultTargetValve().invoke(data, new NullValveContext());
}
/**
* A skeleton {@link org.apache.turbine.ValveContext}
* implementation to assist in invoking DefaultTargetValve in
* {@link #handleException(RunData, Throwable)}.
*/
protected final class NullValveContext implements ValveContext
{
/**
* No-op implementation of ValveContext interface.
*/
public void invokeNext(RunData ignored)
{
// Do nothing
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: cvs
commit:jakarta-turbine-3/src/java/org/apache/turbine/exceptionDefaultExcept
ionHandler.java
Posted by Jason van Zyl <jv...@zenplex.com>.
On Mon, 2002-03-04 at 20:34, Jon Scott Stevens wrote:
> on 3/4/02 5:05 PM, "John McNally" <jm...@collab.net> wrote:
>
> > Anyone up for moving the package tags below the license as well?
> >
> > john mcnally
>
> Ya know...the funny thing is that I personally like the package tags at the
> top...at one point a long time ago, I had a reason for this, but I can't
> remember it...i can live with it either way though...-0
I like them at the top, but I don't care either. If there is a standard
way of doing it then I'm all for it.
> -jon
>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
jvz.
Jason van Zyl
jvanzyl@apache.org
http://tambora.zenplex.org
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: cvs
commit:jakarta-turbine-3/src/java/org/apache/turbine/exceptionDefaultExcept
ionHandler.java
Posted by Jon Scott Stevens <jo...@latchkey.com>.
on 3/4/02 5:05 PM, "John McNally" <jm...@collab.net> wrote:
> Anyone up for moving the package tags below the license as well?
>
> john mcnally
Ya know...the funny thing is that I personally like the package tags at the
top...at one point a long time ago, I had a reason for this, but I can't
remember it...i can live with it either way though...-0
-jon
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: cvs
commit:jakarta-turbine-3/src/java/org/apache/turbine/exceptionDefaultExceptionHandler.java
Posted by John McNally <jm...@collab.net>.
Anyone up for moving the package tags below the license as well?
john mcnally
Jon Scott Stevens wrote:
>
> on 3/4/02 3:45 PM, "jtaylor@apache.org" <jt...@apache.org> wrote:
>
> > Index: DefaultExceptionHandler.java
> > ===================================================================
> > package org.apache.turbine.exception;
> >
> > import org.apache.turbine.ExceptionHandler;
> > import org.apache.turbine.RunData;
> > import org.apache.turbine.Turbine;
> > import org.apache.turbine.ValveContext;
> > import org.apache.turbine.pipeline.DefaultTargetValve;
> > import org.apache.commons.util.StringUtils;
> >
> > /* ====================================================================
> > * The Apache Software License, Version 1.1
> > *
>
> Import's typically go below the license.
>
> Please keep with the existing coding conventions.
>
> -jon
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: cvs commit:
jakarta-turbine-3/src/java/org/apache/turbine/exception
DefaultExceptionHandler.java
Posted by Jon Scott Stevens <jo...@latchkey.com>.
on 3/4/02 3:45 PM, "jtaylor@apache.org" <jt...@apache.org> wrote:
> Index: DefaultExceptionHandler.java
> ===================================================================
> package org.apache.turbine.exception;
>
> import org.apache.turbine.ExceptionHandler;
> import org.apache.turbine.RunData;
> import org.apache.turbine.Turbine;
> import org.apache.turbine.ValveContext;
> import org.apache.turbine.pipeline.DefaultTargetValve;
> import org.apache.commons.util.StringUtils;
>
> /* ====================================================================
> * The Apache Software License, Version 1.1
> *
Import's typically go below the license.
Please keep with the existing coding conventions.
-jon
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>