You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by pb...@apache.org on 2007/08/28 03:03:59 UTC

svn commit: r570287 - in /struts/struts1/trunk/core/src: main/java/org/apache/struts/action/ActionServlet.java main/java/org/apache/struts/action/ExceptionHandler.java test/java/org/apache/struts/action/TestActionServlet.java

Author: pbenedict
Date: Mon Aug 27 18:03:59 2007
New Revision: 570287

URL: http://svn.apache.org/viewvc?rev=570287&view=rev
Log:
STR-2924: Allow Exception key to be optional

Modified:
    struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionServlet.java
    struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ExceptionHandler.java
    struts/struts1/trunk/core/src/test/java/org/apache/struts/action/TestActionServlet.java

Modified: struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionServlet.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionServlet.java?rev=570287&r1=570286&r2=570287&view=diff
==============================================================================
--- struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionServlet.java (original)
+++ struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionServlet.java Mon Aug 27 18:03:59 2007
@@ -1217,15 +1217,16 @@
             postProcessConfig(exception, config, false);
         }
 
-        for (int i = 0; i < exceptions.length; i++) {
-            ExceptionConfig exception = exceptions[i];
-
-            // Verify that required fields are all present for the config
-            if (exception.getKey() == null) {
-                handleValueRequiredException("key", exception.getType(),
-                    "global exception config");
-            }
-        }
+// STR-2924
+//        for (int i = 0; i < exceptions.length; i++) {
+//            ExceptionConfig exception = exceptions[i];
+//
+//            // Verify that required fields are all present for the config
+//            if (exception.getKey() == null) {
+//                handleValueRequiredException("key", exception.getType(),
+//                    "global exception config");
+//            }
+//        }
     }
 
     /**
@@ -1394,17 +1395,18 @@
                 }
             }
 
-            // ... and the exception configs
-            ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs();
-
-            for (int j = 0; j < exceptions.length; j++) {
-                ExceptionConfig exception = exceptions[j];
-
-                if (exception.getKey() == null) {
-                    handleValueRequiredException("key", exception.getType(),
-                        "action exception config");
-                }
-            }
+// STR-2924
+//            // ... and the exception configs
+//            ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs();
+//
+//            for (int j = 0; j < exceptions.length; j++) {
+//                ExceptionConfig exception = exceptions[j];
+//
+//                if (exception.getKey() == null) {
+//                    handleValueRequiredException("key", exception.getType(),
+//                        "action exception config");
+//                }
+//            }
         }
     }
 

Modified: struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ExceptionHandler.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ExceptionHandler.java?rev=570287&r1=570286&r2=570287&view=diff
==============================================================================
--- struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ExceptionHandler.java (original)
+++ struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ExceptionHandler.java Mon Aug 27 18:03:59 2007
@@ -144,8 +144,14 @@
             error = ((ModuleException) ex).getActionMessage();
             property = ((ModuleException) ex).getProperty();
         } else {
-            error = new ActionMessage(ae.getKey(), ex.getMessage());
-            property = error.getKey();
+            // STR-2924
+            if (ae.getKey() != null) {
+                error = new ActionMessage(ae.getKey(), ex.getMessage());
+                property = error.getKey();
+            } else {
+                error = null;
+                property = null;
+            }
         }
 
         this.logException(ex);
@@ -274,8 +280,9 @@
      * generated from an <code>Exception</code> during <code>Action</code>
      * delegation. The default implementation is to set an attribute of the
      * request or session, as defined by the scope provided (the scope from
-     * the exception mapping). An <code>ActionMessages</code> instance is
-     * created, the error is added to the collection and the collection is set
+     * the exception mapping), if <code>error</code> is not <code>null</code>. 
+     * Otherwise, an <code>ActionMessages</code> instance is created, the error
+     * is added to the collection and the collection is set
      * under the <code>Globals.ERROR_KEY</code>.</p>
      *
      * @param request  The request we are handling
@@ -288,14 +295,16 @@
      */
     protected void storeException(HttpServletRequest request, String property,
         ActionMessage error, ActionForward forward, String scope) {
-        ActionMessages errors = new ActionMessages();
-
-        errors.add(property, error);
-
-        if ("request".equals(scope)) {
-            request.setAttribute(Globals.ERROR_KEY, errors);
-        } else {
-            request.getSession().setAttribute(Globals.ERROR_KEY, errors);
+        
+        if (error != null) {
+            ActionMessages errors = new ActionMessages();
+            errors.add(property, error);
+    
+            if ("request".equals(scope)) {
+                request.setAttribute(Globals.ERROR_KEY, errors);
+            } else {
+                request.getSession().setAttribute(Globals.ERROR_KEY, errors);
+            }
         }
     }
 

Modified: struts/struts1/trunk/core/src/test/java/org/apache/struts/action/TestActionServlet.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/test/java/org/apache/struts/action/TestActionServlet.java?rev=570287&r1=570286&r2=570287&view=diff
==============================================================================
--- struts/struts1/trunk/core/src/test/java/org/apache/struts/action/TestActionServlet.java (original)
+++ struts/struts1/trunk/core/src/test/java/org/apache/struts/action/TestActionServlet.java Mon Aug 27 18:03:59 2007
@@ -493,8 +493,8 @@
     }
 
     /**
-     * Test that initModuleExceptionConfigs throws an exception when a handler
-     * with a null key is present.
+     * Test that initModuleExceptionConfigs does not throw an exception 
+     * when a handler with a null key is present.
      */
     public void testInitModuleExceptionConfigsNullFormType()
         throws ServletException {
@@ -505,9 +505,9 @@
 
         try {
             actionServlet.initModuleExceptionConfigs(moduleConfig);
-            fail("An exception should've been thrown here.");
-        } catch (UnavailableException e) {
             // success
+        } catch (UnavailableException e) {
+            fail("Exception shouldn't have been thrown here.");
         } catch (Exception e) {
             fail("Unrecognized exception thrown: " + e);
         }