craigmcc    2003/08/31 14:53:00

  Modified:    contrib/struts-chain/src/conf chain-config.xml
               contrib/struts-chain/src/java/org/apache/struts/chain
                        Constants.java
               contrib/struts-chain/src/java/org/apache/struts/chain/legacy
                        CatalogConfiguratorPlugIn.java
                        ComposableRequestProcessor.java
  Added:       contrib/struts-chain/src/java/org/apache/struts/chain
                        AbstractExceptionHandler.java ExceptionCatcher.java
               contrib/struts-chain/src/java/org/apache/struts/chain/servlet
                        ExceptionHandler.java
  Log:
  Add an exception catcher early in the standard command chain that implements
  the usual Struts 1.1 behavior (calling an ExceptionHandler and optionally
  forwarding based on the result).  This necessitated a modification to the
  API of the postprocess() method in org.apache.commons.chain.Filter, so you'll
  need to refresh your version of commons-chain to 20030901 or later as well.
  
  Revision  Changes    Path
  1.3       +33 -3     jakarta-struts/contrib/struts-chain/src/conf/chain-config.xml
  
  Index: chain-config.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/conf/chain-config.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- chain-config.xml  30 Aug 2003 23:18:56 -0000      1.2
  +++ chain-config.xml  31 Aug 2003 21:53:00 -0000      1.3
  @@ -62,7 +62,7 @@
   
              processPath             SelectAction (which also does processMapping)
   
  -           processException        NOT SUPPORTED YET
  +           processException        ExceptionCatcher / ExceptionHandler
   
              processLocale           SelectLocale
   
  @@ -107,6 +107,12 @@
              optional="true"/>
   
   
  +      <!-- Establish exception handling filter -->
  +      <command
  +          className="org.apache.struts.chain.ExceptionCatcher"
  +   exceptionCommand="servlet-exception"/>
  +
  +
         <!-- Identify the Locale for this request -->
         <command
             className="org.apache.struts.chain.servlet.SelectLocale"/>
  @@ -153,7 +159,31 @@
             className="org.apache.struts.chain.servlet.PerformForward"/>
   
   
  -   </chain>
  +    </chain>
  +
  +
  +    <!-- ========== Servlet Exception Handler Chain ======================== -->
  +
  +    <chain     name="servlet-exception">
  +
  +      <!--
  +            This chain is designed to be invoked (by o.a.s.c.ExceptionCatcher)
  +            if an unhandled exception is thrown by any subsequent command
  +            in a processing chain (including the one that invokes a Struts
  +            action).  The standard definition of this chain supports the
  +            exception mapping of Struts 1.1, but can be replaced in order
  +            to handle exceptions differently.
  +      -->
  +
  +      <!-- Execute the configured exception handler (if any) -->
  +      <command
  +          className="org.apache.struts.chain.servlet.ExceptionHandler"/>
  +
  +      <!-- Follow the returned ActionForward (if any) -->
  +      <command
  +          className="org.apache.struts.chain.servlet.PerformForward"/>
  +
  +    </chain>
   
   
   </chains>
  
  
  
  1.3       +19 -4     
jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/Constants.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Constants.java    30 Aug 2003 23:18:56 -0000      1.2
  +++ Constants.java    31 Aug 2003 21:53:00 -0000      1.3
  @@ -112,6 +112,21 @@
   
   
       /**
  +     * <p>The default context attribute under which our
  +     * <code>Catalog</code> will be stored.</p>
  +     */
  +    public static final String CATALOG_KEY = "catalog";
  +
  +
  +    /**
  +     * <p>The default context attribute under which an
  +     * <code>Exception</code> will be stored before passing
  +     * it to an exception handler chain.</p>
  +     */
  +    public static final String EXCEPTION_KEY = "exception";
  +
  +
  +    /**
        * <p>The default context attribute under which the
        * <code>ForwardConfig</code> for the current request
        * will be stored.</p>
  @@ -158,7 +173,7 @@
        * <p>The context attribute under which the <code>Catalog</code> containing
        * our defined command chains has been stored.</p>
        */
  -    public static final String CATALOG_KEY =
  +    public static final String CATALOG_ATTR =
           "org.apache.struts.chain.CATALOG";
   
   
  
  
  
  1.1                  
jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/AbstractExceptionHandler.java
  
  Index: AbstractExceptionHandler.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/AbstractExceptionHandler.java,v
 1.1 2003/08/31 21:53:00 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2003/08/31 21:53:00 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Struts", and "Apache Software
   *    Foundation" 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"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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.struts.chain;
  
  
  import org.apache.commons.chain.Command;
  import org.apache.commons.chain.Context;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.struts.chain.Constants;
  import org.apache.struts.config.ActionConfig;
  import org.apache.struts.config.ExceptionConfig;
  import org.apache.struts.config.ForwardConfig;
  import org.apache.struts.config.ModuleConfig;
  
  
  /**
   * <p>Invoke the local or global exception handler configured for the
   * exception class that occurred.</p>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2003/08/31 21:53:00 $
   */
  
  public abstract class AbstractExceptionHandler implements Command {
  
  
      // ------------------------------------------------------ Instance Variables
  
  
      private String actionConfigKey = Constants.ACTION_CONFIG_KEY;
      private String exceptionKey = Constants.EXCEPTION_KEY;
      private String forwardConfigKey = Constants.FORWARD_CONFIG_KEY;
      private String moduleConfigKey = Constants.MODULE_CONFIG_KEY;
  
      private static final Log log =
          LogFactory.getLog(AbstractExceptionHandler.class);
  
  
      // -------------------------------------------------------------- Properties
  
  
      /**
       * <p>Return the context attribute key under which the
       * <code>ActionConfig</code> for the currently selected application
       * action is stored.</p>
       */
      public String getActionConfigKey() {
  
          return (this.actionConfigKey);
  
      }
  
  
      /**
       * <p>Set the context attribute key under which the
       * <code>ActionConfig</code> for the currently selected application
       * action is stored.</p>
       *
       * @param actionConfigKey The new context attribute key
       */
      public void setActionConfigKey(String actionConfigKey) {
  
          this.actionConfigKey = actionConfigKey;
  
      }
  
  
      /**
       * <p>Return the context attribute key under which any
       * thrown exception will be stored.</p>
       */
      public String getExceptionKey() {
  
          return (this.exceptionKey);
  
      }
  
  
      /**
       * <p>Set the context attribute key under which any
       * thrown exception will be stored.</p>
       *
       * @param exceptionKey The new context attribute key
       */
      public void setExceptionKey(String exceptionKey) {
  
          this.exceptionKey = exceptionKey;
  
      }
  
  
      /**
       * <p>Return the context attribute key under which the
       * <code>ForwardConfig</code> for the currently selected application
       * action is stored.</p>
       */
      public String getForwardConfigKey() {
  
          return (this.forwardConfigKey);
  
      }
  
  
      /**
       * <p>Set the context attribute key under which the
       * <code>ForwardConfig</code> for the currently selected application
       * action is stored.</p>
       *
       * @param forwardConfigKey The new context attribute key
       */
      public void setForwardConfigKey(String forwardConfigKey) {
  
          this.forwardConfigKey = forwardConfigKey;
  
      }
  
  
      /**
       * <p>Return the context attribute key under which the
       * <code>ModuleConfig</code> for the currently selected application
       * action is stored.</p>
       */
      public String getModuleConfigKey() {
  
          return (this.moduleConfigKey);
  
      }
  
  
      /**
       * <p>Set the context attribute key under which the
       * <code>ModuleConfig</code> for the currently selected application
       * action is stored.</p>
       *
       * @param moduleConfigKey The new context attribute key
       */
      public void setModuleConfigKey(String moduleConfigKey) {
  
          this.moduleConfigKey = moduleConfigKey;
  
      }
  
  
      // ---------------------------------------------------------- Public Methods
  
  
      /**
       * <p>Invoke the appropriate <code>Action</code> for this request, and cache
       * the returned <code>ActionForward</code>.</p>
       *
       * @param context The <code>Context</code> for the current request
       *
       * @exception InvalidPathException if no valid
       *  action can be identified for this request
       *
       * @return <code>false</code> if a <code>ForwardConfig</code> is returned,
       *  else <code>true</code> to complete processing
       */
      public boolean execute(Context context) throws Exception {
  
          // Look up the exception that was thrown
          Exception exception = (Exception)
              context.getAttributes().get(getExceptionKey());
          if (exception == null) {
              log.warn("No Exception found under key '" +
                       getExceptionKey() + "'");
              return (true);
          }
  
          // Look up the local or global exception handler configuration
          ExceptionConfig exceptionConfig = null;
          ActionConfig actionConfig = (ActionConfig)
              context.getAttributes().get(getActionConfigKey());
          ModuleConfig moduleConfig = (ModuleConfig)
              context.getAttributes().get(getModuleConfigKey());
          if (actionConfig != null) {
              exceptionConfig =
                  actionConfig.findExceptionConfig(exception.getClass().getName());
          } else {
              exceptionConfig =
                  moduleConfig.findExceptionConfig(exception.getClass().getName());
          }
  
          // Handle the exception in the configured manner
          if (exceptionConfig == null) {
              log.warn("Unhandled exception", exception);
              throw exception;
          }
          ForwardConfig forwardConfig =
              handle(context, exception, exceptionConfig,
                     actionConfig, moduleConfig);
          if (forwardConfig != null) {
              context.getAttributes().put(getForwardConfigKey(), forwardConfig);
              return (false);
          } else {
              return (true);
          }
  
      }
  
  
      // ------------------------------------------------------- Protected Methods
  
  
      /**
       * <p>Perform the required handling of the specified exception.</p>
       *
       * @param context The <code>Context</code> for this request
       * @param exception The exception being handled
       * @param exceptionConfig The corresponding [EMAIL PROTECTED] ExceptionConfig}
       * @param actionConfig The [EMAIL PROTECTED] ActionConfig} for this request
       * @param moduleConfig The [EMAIL PROTECTED] ModuleConfig} for this request
       *
       * @return the <code>ForwardConfig</code> to be processed next (if any),
       *  or <code>null</code> if processing has been completed
       */
      protected abstract ForwardConfig handle(Context context,
                                              Exception exception,
                                              ExceptionConfig exceptionConfig,
                                              ActionConfig actionConfig,
                                              ModuleConfig moduleConfig)
          throws Exception;
  
  
  }
  
  
  
  1.1                  
jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/ExceptionCatcher.java
  
  Index: ExceptionCatcher.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/ExceptionCatcher.java,v
 1.1 2003/08/31 21:53:00 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2003/08/31 21:53:00 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Struts", and "Apache Software
   *    Foundation" 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"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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.struts.chain;
  
  
  import org.apache.commons.chain.Catalog;
  import org.apache.commons.chain.Command;
  import org.apache.commons.chain.Context;
  import org.apache.commons.chain.Filter;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.struts.chain.Constants;
  
  
  /**
   * <p>Intercept any exception thrown by a subsequent <code>Command</code>
   * in this processing chain, and fire the configured exception handler chain
   * after storing the exception that has occurred into the <code>Context</code>.
   * </p>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2003/08/31 21:53:00 $
   */
  
  public class ExceptionCatcher implements Filter {
  
  
      // ------------------------------------------------------ Instance Variables
  
  
      private String catalogKey = Constants.CATALOG_KEY;
      private String exceptionCommand = null;
      private String exceptionKey = Constants.EXCEPTION_KEY;
  
      private static final Log log = LogFactory.getLog(ExceptionCatcher.class);
  
  
      // -------------------------------------------------------------- Properties
  
  
      /**
       * <p>Return the context attribute key under which the
       * <code>Catalog</code> we perform lookups in is stored.</p>
       */
      public String getCatalogKey() {
  
          return (this.catalogKey);
  
      }
  
  
      /**
       * <p>Set the context attribute key under which the
       * <code>Catalog</code> we perform lookups in is stored.</p>
       *
       * @param catalogKey The new context attribute key
       */
      public void setCatalogKey(String catalogKey) {
  
          this.catalogKey = catalogKey;
  
      }
  
  
      /**
       * <p>Return the name of the command to be executed
       * if an exception occurs.</p>
       */
      public String getExceptionCommand() {
  
          return (this.exceptionCommand);
  
      }
  
  
      /**
       * <p>Set the name of the command to be executed
       * if an exception occurs.</p>
       *
       * @param exceptionCommand The name of the chain to be executed
       */
      public void setExceptionCommand(String exceptionCommand) {
  
          this.exceptionCommand = exceptionCommand;
  
      }
  
  
      /**
       * <p>Return the context attribute key under which any
       * thrown exception will be stored.</p>
       */
      public String getExceptionKey() {
  
          return (this.exceptionKey);
  
      }
  
  
      /**
       * <p>Set the context attribute key under which any
       * thrown exception will be stored.</p>
       *
       * @param exceptionKey The new context attribute key
       */
      public void setExceptionKey(String exceptionKey) {
  
          this.exceptionKey = exceptionKey;
  
      }
  
  
      // ---------------------------------------------------------- Public Methods
  
  
      /**
       * <p>Clear any existing stored exception and pass the <code>context</code>
       * on to the remainder of the current chain.</p>
       *
       * @param context The <code>Context</code> for the current request
       *
       * @return <code>false</code> so that processing continues
       */
      public boolean execute(Context context) throws Exception {
  
          context.getAttributes().remove(getExceptionKey());
          return (false);
  
      }
  
  
      /**
       * <p>If an exception was thrown by a subsequent <code>Command</code>,
       * pass it on to the specified exception handling chain.  Otherwise,
       * do nothing.</p>
       *
       * @param context The [EMAIL PROTECTED] Context} to be processed by this
       *  [EMAIL PROTECTED] Filter}
       * @param exception The <code>Exception</code> (if any) that was thrown
       *  by the last [EMAIL PROTECTED] Command} that was executed; otherwise
       *  <code>null</code>
       */ 
      public boolean postprocess(Context context, Exception exception) {
  
          // Do nothing if there was no exception thrown
          if (exception == null) {
              return (false);
          }
  
          // Stash the exception in the specified context attribute
          if (log.isDebugEnabled()) {
              log.debug("Attempting to handle a thrown exception");
          }
          context.getAttributes().put(getExceptionKey(), exception);
  
          // Execute the specified command
          try {
              Catalog catalog = (Catalog)
                  context.getAttributes().get(getCatalogKey());
              Command command = catalog.getCommand(getExceptionCommand());
              if (log.isTraceEnabled()) {
                  log.trace("Calling handler command '" + getExceptionCommand()
                            + "'");
              }
              command.execute(context);
          } catch (Exception e) {
              log.warn("Exception from handler command '" +
                       getExceptionCommand() + "'", e);
              throw new IllegalStateException("Exception chain threw exception");
          }
          return (true);
  
      }
  
  
  
  }
  
  
  
  1.3       +5 -5      
jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/legacy/CatalogConfiguratorPlugIn.java
  
  Index: CatalogConfiguratorPlugIn.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/legacy/CatalogConfiguratorPlugIn.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CatalogConfiguratorPlugIn.java    30 Aug 2003 23:18:56 -0000      1.2
  +++ CatalogConfiguratorPlugIn.java    31 Aug 2003 21:53:00 -0000      1.3
  @@ -172,11 +172,11 @@
   
           // Retrieve or create the Catalog instance we will be updating
           Catalog catalog = (Catalog)
  -            servlet.getServletContext().getAttribute(Constants.CATALOG_KEY);
  +            servlet.getServletContext().getAttribute(Constants.CATALOG_ATTR);
           if (catalog == null) {
               log.info("Creating new Catalog instance");
               catalog = new CatalogBase();
  -            servlet.getServletContext().setAttribute(Constants.CATALOG_KEY,
  +            servlet.getServletContext().setAttribute(Constants.CATALOG_ATTR,
                                                        catalog);
           }
   
  
  
  
  1.3       +7 -6      
jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/legacy/ComposableRequestProcessor.java
  
  Index: ComposableRequestProcessor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/legacy/ComposableRequestProcessor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ComposableRequestProcessor.java   30 Aug 2003 23:18:56 -0000      1.2
  +++ ComposableRequestProcessor.java   31 Aug 2003 21:53:00 -0000      1.3
  @@ -150,7 +150,7 @@
                    + moduleConfig.getPrefix() + "'");
           super.init(servlet, moduleConfig);
           this.catalog = (Catalog)
  -            servlet.getServletContext().getAttribute(Constants.CATALOG_KEY);
  +            servlet.getServletContext().getAttribute(Constants.CATALOG_ATTR);
           if (this.catalog == null) {
               // FIXME - i18n
               throw new ServletException("No Catalog has been configured");
  @@ -176,7 +176,8 @@
           // Create and populate a Context for this request
           ServletWebContext context = new ServletWebContext();
           context.initialize(getServletContext(), request, response);
  -        context.getAttributes().put("catalog", this.catalog);
  +        context.getAttributes().put(Constants.CATALOG_KEY,
  +                                    this.catalog);
           context.getAttributes().put(Constants.ACTION_SERVLET_KEY,
                                       this.servlet);
           context.getAttributes().put(Constants.MODULE_CONFIG_KEY,
  
  
  
  1.1                  
jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet/ExceptionHandler.java
  
  Index: ExceptionHandler.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet/ExceptionHandler.java,v
 1.1 2003/08/31 21:53:00 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2003/08/31 21:53:00 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Struts", and "Apache Software
   *    Foundation" 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"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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.struts.chain.servlet;
  
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import org.apache.commons.chain.Context;
  import org.apache.commons.chain.web.servlet.ServletWebContext;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.struts.chain.AbstractExceptionHandler;
  import org.apache.struts.chain.Constants;
  import org.apache.struts.chain.util.ClassUtils;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionMapping;
  import org.apache.struts.config.ActionConfig;
  import org.apache.struts.config.ExceptionConfig;
  import org.apache.struts.config.ForwardConfig;
  import org.apache.struts.config.ModuleConfig;
  
  
  /**
   * <p>Handle the specified exception.</p>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2003/08/31 21:53:00 $
   */
  
  public class ExceptionHandler extends AbstractExceptionHandler {
  
  
      // ------------------------------------------------------ Instance Variables
  
  
      private String actionFormKey = Constants.ACTION_FORM_KEY;
  
      private static final Log log = LogFactory.getLog(ExceptionHandler.class);
  
  
      // -------------------------------------------------------------- Properties
  
  
      /**
       * <p>Return the context attribute key under which the
       * <code>ActionForm</code> for the currently selected application
       * action is stored.</p>
       */
      public String getActionFormKey() {
  
          return (this.actionFormKey);
  
      }
  
  
      /**
       * <p>Set the context attribute key under which the
       * <code>ActionForm</code> for the currently selected application
       * action is stored.</p>
       *
       * @param actionFormKey The new context attribute key
       */
      public void setActionFormKey(String actionFormKey) {
  
          this.actionFormKey = actionFormKey;
  
      }
  
  
      // ------------------------------------------------------- Protected Methods
  
  
      protected ForwardConfig handle(Context context,
                                     Exception exception,
                                     ExceptionConfig exceptionConfig,
                                     ActionConfig actionConfig,
                                     ModuleConfig moduleConfig)
          throws Exception {
  
          // Look up the remaining properties needed for this handler
          ServletWebContext swcontext = (ServletWebContext) context;
          ActionForm actionForm = (ActionForm)
              swcontext.getAttributes().get(getActionFormKey());
          HttpServletRequest request = swcontext.getRequest();
          HttpServletResponse response = swcontext.getResponse();
  
          // Handle this exception
          org.apache.struts.action.ExceptionHandler handler =
              (org.apache.struts.action.ExceptionHandler)
              ClassUtils.getApplicationInstance(exceptionConfig.getHandler());
          return (handler.execute(exception,
                                  exceptionConfig,
                                  (ActionMapping) actionConfig,
                                  actionForm,
                                  request,
                                  response));
  
      }
  
  
  }
  
  
  

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

Reply via email to