struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r377805 - in /struts/action/branches/STRUTS_1_2_BRANCH: src/examples/org/apache/struts/webapp/exercise/ src/share/org/apache/struts/action/ src/share/org/apache/struts/config/ web/example/WEB-INF/ web/examples/WEB-INF/exercise/ web/examples...
Date Tue, 14 Feb 2006 19:26:17 GMT
Author: niallp
Date: Tue Feb 14 11:26:15 2006
New Revision: 377805

URL: http://svn.apache.org/viewcvs?rev=377805&view=rev
Log:
Fix Bug 38374 in 1.2.x Branch - Validation always skipped with Globals.CANCEL_KEY - thanks
to Paul Benedict for reporting this and providing the patch.

Added:
    struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/InvalidCancelException.java
  (with props)
    struts/action/branches/STRUTS_1_2_BRANCH/web/examples/exercise/html-cancel.jsp   (with
props)
Modified:
    struts/action/branches/STRUTS_1_2_BRANCH/src/examples/org/apache/struts/webapp/exercise/MessageResources.properties
    struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/RequestProcessor.java
    struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/config/ActionConfig.java
    struts/action/branches/STRUTS_1_2_BRANCH/web/example/WEB-INF/struts-config-registration.xml
    struts/action/branches/STRUTS_1_2_BRANCH/web/example/WEB-INF/struts-config.xml
    struts/action/branches/STRUTS_1_2_BRANCH/web/examples/WEB-INF/exercise/struts-config.xml
    struts/action/branches/STRUTS_1_2_BRANCH/web/examples/WEB-INF/validator/struts-config.xml
    struts/action/branches/STRUTS_1_2_BRANCH/web/examples/exercise/index.html

Modified: struts/action/branches/STRUTS_1_2_BRANCH/src/examples/org/apache/struts/webapp/exercise/MessageResources.properties
URL: http://svn.apache.org/viewcvs/struts/action/branches/STRUTS_1_2_BRANCH/src/examples/org/apache/struts/webapp/exercise/MessageResources.properties?rev=377805&r1=377804&r2=377805&view=diff
==============================================================================
--- struts/action/branches/STRUTS_1_2_BRANCH/src/examples/org/apache/struts/webapp/exercise/MessageResources.properties
(original)
+++ struts/action/branches/STRUTS_1_2_BRANCH/src/examples/org/apache/struts/webapp/exercise/MessageResources.properties
Tue Feb 14 11:26:15 2006
@@ -6,6 +6,7 @@
 errors.footer=</table>
 errors.prefix=<tr><td>
 errors.suffix=</td></tr>
+errors.invalidCancel=Cancel is a not an valid operation for this Action.
 
 property1error1=Property 1, Error 1
 property2error1=Property 2, Error 1

Added: struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/InvalidCancelException.java
URL: http://svn.apache.org/viewcvs/struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/InvalidCancelException.java?rev=377805&view=auto
==============================================================================
--- struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/InvalidCancelException.java
(added)
+++ struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/InvalidCancelException.java
Tue Feb 14 11:26:15 2006
@@ -0,0 +1,42 @@
+/*
+ * $Id$
+ *
+ * Copyright 2000-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts.action;
+
+
+/**
+ * <p> Thrown when a token generated by the Cancel tag is found in the
+ * request, but the cancellable property for the Action Mapping is not set.
+ * </p>
+ */
+public class InvalidCancelException extends Exception {
+    /**
+     * <p>Default constructor.</p>
+     */
+    public InvalidCancelException() {
+        super();
+    }
+
+    /**
+     * <p>Construct the exception with the specified message.</p>
+     *
+     * @param message the message
+     */
+    public InvalidCancelException(String message) {
+        super(message);
+    }
+}

Propchange: struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/InvalidCancelException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/InvalidCancelException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/RequestProcessor.java
URL: http://svn.apache.org/viewcvs/struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/RequestProcessor.java?rev=377805&r1=377804&r2=377805&view=diff
==============================================================================
--- struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/RequestProcessor.java
(original)
+++ struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/RequestProcessor.java
Tue Feb 14 11:26:15 2006
@@ -201,10 +201,22 @@
         // Process any ActionForm bean related to this request
         ActionForm form = processActionForm(request, response, mapping);
         processPopulate(request, response, form, mapping);
-        if (!processValidate(request, response, form, mapping)) {
+        
+        // Validate any fields of the ActionForm bean, if applicable
+        try {
+            if (!processValidate(request, response, form, mapping)) {
+                return;
+            }
+        } catch (InvalidCancelException e) {
+            ActionForward forward = processException(request, response, e, form, mapping);
+            processForwardConfig(request, response, forward);
             return;
+        } catch (IOException e) {
+            throw e;
+        } catch (ServletException e) {
+            throw e;
         }
-
+            
         // Process a forward or include specified by this mapping
         if (!processForward(request, response, mapping)) {
             return;
@@ -897,22 +909,33 @@
      *
      * @exception IOException if an input/output error occurs
      * @exception ServletException if a servlet exception occurs
+     * @exception InvalidCancelException if a cancellation is attempted 
+     *              without the proper action configuration
      */
     protected boolean processValidate(HttpServletRequest request,
                                       HttpServletResponse response,
                                       ActionForm form,
                                       ActionMapping mapping)
-        throws IOException, ServletException {
+        throws IOException, ServletException, InvalidCancelException {
 
         if (form == null) {
             return (true);
         }
-                                              // Was this request cancelled?
+        
+        // Was this request cancelled? If it has been, the mapping also
+        // needs to state whether the cancellation is permissable; otherwise
+        // the cancellation is considered to be a symptom of a programmer
+        // error or a spoof.
         if (request.getAttribute(Globals.CANCEL_KEY) != null) {
-            if (log.isDebugEnabled()) {
-                log.debug(" Cancelled transaction, skipping validation");
+            if (mapping.getCancellable()) {
+                if (log.isDebugEnabled()) {
+                    log.debug(" Cancelled transaction, skipping validation");
+                }
+                return (true);
+            } else {
+                request.removeAttribute(Globals.CANCEL_KEY);
+                throw new InvalidCancelException();
             }
-            return (true);
         }
 
         // Has validation been turned off for this mapping?

Modified: struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/config/ActionConfig.java
URL: http://svn.apache.org/viewcvs/struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/config/ActionConfig.java?rev=377805&r1=377804&r2=377805&view=diff
==============================================================================
--- struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/config/ActionConfig.java
(original)
+++ struts/action/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/config/ActionConfig.java
Tue Feb 14 11:26:15 2006
@@ -525,7 +525,39 @@
         }
         this.validate = validate;
     }
+    
+    /**
+     * <p>Can this Action be cancelled? [false]</p> <p> By default, when
an
+     * Action is cancelled, validation is bypassed and the Action should not
+     * execute the business operation. If a request tries to cancel an Action
+     * when cancellable is not set, a "InvalidCancelException" is thrown.</p>
+     * @since Struts 1.2.9
+     */ 
+    protected boolean cancellable = false;
 
+    /**
+     * <p>Accessor for cancellable property</p>
+     *
+     * @return True if Action can be cancelled
+     * @since  Struts 1.2.9
+     */
+    public boolean getCancellable() {
+        return (this.cancellable);
+    }
+
+    /**
+     * <p>Mutator for for cancellable property</p>
+     *
+     * @param cancellable
+     * @since Struts 1.2.9
+     */
+    public void setCancellable(boolean cancellable) {
+        if (configured) {
+            throw new IllegalStateException("Configuration is frozen");
+        }
+        this.cancellable = cancellable;
+    }
+    
 
     // --------------------------------------------------------- Public Methods
 
@@ -775,6 +807,10 @@
             sb.append(",type=");
             sb.append(type);
         }
+        sb.append(",validate=");
+        sb.append(validate);
+        sb.append(",cancellable=");
+        sb.append(cancellable);
         return (sb.toString());
 
     }

Modified: struts/action/branches/STRUTS_1_2_BRANCH/web/example/WEB-INF/struts-config-registration.xml
URL: http://svn.apache.org/viewcvs/struts/action/branches/STRUTS_1_2_BRANCH/web/example/WEB-INF/struts-config-registration.xml?rev=377805&r1=377804&r2=377805&view=diff
==============================================================================
--- struts/action/branches/STRUTS_1_2_BRANCH/web/example/WEB-INF/struts-config-registration.xml
(original)
+++ struts/action/branches/STRUTS_1_2_BRANCH/web/example/WEB-INF/struts-config-registration.xml
Tue Feb 14 11:26:15 2006
@@ -5,7 +5,7 @@
 <!--
  $Header: /home/cvs/jakarta-struts/web/example/WEB-INF/struts-config-registration.xml,v 1.8
2004/09/02 03:43:15 niallp Exp $
  $Revision: 1.8 $
- $Date: 2004/09/02 03:43:15 $
+ $Date$
 
  Copyright 2000-2004 Apache Software Foundation
 
@@ -63,7 +63,9 @@
                type="org.apache.struts.webapp.example.Save{1}Action"
                name="{1}Form"
               scope="request"
-              input="{1}"/>
+              input="{1}">
+      <set-property property="cancellable" value="true"/>
+    </action>
 
   </action-mappings>
 

Modified: struts/action/branches/STRUTS_1_2_BRANCH/web/example/WEB-INF/struts-config.xml
URL: http://svn.apache.org/viewcvs/struts/action/branches/STRUTS_1_2_BRANCH/web/example/WEB-INF/struts-config.xml?rev=377805&r1=377804&r2=377805&view=diff
==============================================================================
--- struts/action/branches/STRUTS_1_2_BRANCH/web/example/WEB-INF/struts-config.xml (original)
+++ struts/action/branches/STRUTS_1_2_BRANCH/web/example/WEB-INF/struts-config.xml Tue Feb
14 11:26:15 2006
@@ -5,7 +5,7 @@
 <!--
  $Header: /home/cvs/jakarta-struts/web/example/WEB-INF/struts-config.xml,v 1.43 2004/09/02
03:43:15 niallp Exp $
  $Revision: 1.43 $
- $Date: 2004/09/02 03:43:15 $
+ $Date$
 
  Copyright 2000-2004 Apache Software Foundation
 
@@ -90,6 +90,7 @@
                   name="LogonForm"
                  scope="request"
                  input="logon">
+         <set-property property="cancellable" value="true"/>
          <exception
                    key="expired.password"
                   type="org.apache.struts.webapp.example.ExpiredPasswordException"
@@ -118,6 +119,7 @@
                   name="SubscriptionForm"
                  scope="request"
                  input="subscription">
+         <set-property property="cancellable" value="true"/>
          <forward name="subscription"    path="/subscription.jsp"/>
          <forward name="success"         path="/EditRegistration.do?action=Edit"/>
        </action>

Modified: struts/action/branches/STRUTS_1_2_BRANCH/web/examples/WEB-INF/exercise/struts-config.xml
URL: http://svn.apache.org/viewcvs/struts/action/branches/STRUTS_1_2_BRANCH/web/examples/WEB-INF/exercise/struts-config.xml?rev=377805&r1=377804&r2=377805&view=diff
==============================================================================
--- struts/action/branches/STRUTS_1_2_BRANCH/web/examples/WEB-INF/exercise/struts-config.xml
(original)
+++ struts/action/branches/STRUTS_1_2_BRANCH/web/examples/WEB-INF/exercise/struts-config.xml
Tue Feb 14 11:26:15 2006
@@ -24,6 +24,24 @@
   <action-mappings>
     <action path="/welcome" forward="/index.html" />
     <action path="/bean-write-2" forward="/bean-write-2.jsp" />
+    <action path="/html-cancel" forward="/html-cancel.jsp"/>
+    <action path="/html-cancel-true" name="testbean"
+                input="/html-cancel.jsp" cancellable="true" validate="true"
+                forward="/welcome.do"/>
+    <action path="/html-cancel-false" name="testbean"
+                input="/html-cancel.jsp" cancellable="false" validate="true"
+                forward="/welcome.do">
+            <exception
+                    key="errors.invalidCancel"
+                    type="org.apache.struts.action.InvalidCancelException"
+                    path="/html-cancel.jsp"/>
+    </action>
+    <action path="/html-cancel-exception" name="testbean"
+                input="/html-cancel.jsp" cancellable="false" validate="true"
+                forward="/welcome.do"/>
+    <action path="/html-cancel-novalidate" name="testbean"
+                input="/html-cancel.jsp" cancellable="false" validate="false"
+                forward="/welcome.do"/>
     <action path="/html-img" forward="/html-img.jsp" />
      <!-- :FIXME: ImageAction should compute module prefix -->
     <action path="/html-img-action" type="org.apache.struts.webapp.exercise.ImageAction"
parameter="/exercise/struts-power.gif"/>

Modified: struts/action/branches/STRUTS_1_2_BRANCH/web/examples/WEB-INF/validator/struts-config.xml
URL: http://svn.apache.org/viewcvs/struts/action/branches/STRUTS_1_2_BRANCH/web/examples/WEB-INF/validator/struts-config.xml?rev=377805&r1=377804&r2=377805&view=diff
==============================================================================
--- struts/action/branches/STRUTS_1_2_BRANCH/web/examples/WEB-INF/validator/struts-config.xml
(original)
+++ struts/action/branches/STRUTS_1_2_BRANCH/web/examples/WEB-INF/validator/struts-config.xml
Tue Feb 14 11:26:15 2006
@@ -50,6 +50,7 @@
     <action path="/registration-submit" type="org.apache.struts.webapp.validator.RegistrationAction"
name="registrationForm" scope="request" validate="true" input="input">
       <forward name="input" path="/registration.do" />
       <forward name="success" path="/index.jsp" />
+      <set-property property="cancellable" value="true"/>
     </action>
     <action path="/jsRegistration" forward="/jsRegistration.jsp" />
     <!-- Multi-Part Registration Action -->
@@ -58,12 +59,14 @@
       <forward name="success" path="/welcome.do" />
       <forward name="input1" path="/multiRegistration1.jsp" />
       <forward name="input2" path="/multiRegistration2.jsp" />
+      <set-property property="cancellable" value="true"/>
     </action>
     <!-- Type Action -->
     <action path="/type" forward="/type.jsp" />
     <action path="/type-submit" type="org.apache.struts.webapp.validator.TypeAction" name="typeForm"
scope="request" validate="true" input="input">
       <forward name="input" path="/type.do" />
       <forward name="success" path="/welcome.do" />
+      <set-property property="cancellable" value="true"/>
     </action>
     <!-- JavaScript Type Action -->
     <action path="/editJsType" type="org.apache.struts.webapp.validator.EditTypeAction"
scope="request" validate="false">
@@ -72,6 +75,7 @@
     <action path="/jsType" forward="/jsType.jsp" />
     <action path="/jsType-submit" type="org.apache.struts.webapp.validator.TypeAction"
name="jsTypeForm" scope="request" validate="true" input="/jsType.jsp">
       <forward name="success" path="/welcome.do" />
+      <set-property property="cancellable" value="true"/>
     </action>
 
     <!-- Bundles Examples -->
@@ -79,6 +83,7 @@
     <action path="/validateBundleExamples" type="org.apache.struts.actions.ForwardAction"
name="bundlesForm" scope="request" 
             parameter="/validator/welcome.do" validate="true" input="input" >
             <forward name="input" path="/viewBundleExamples.do" />
+      <set-property property="cancellable" value="true"/>
     </action>
 
     <!-- JavaScript Bundles Examples -->
@@ -86,6 +91,7 @@
     <action path="/validateJsBundleExamples" type="org.apache.struts.actions.ForwardAction"
name="bundlesForm" scope="request" 
             parameter="/validator/welcome.do" validate="true" input="input" >
             <forward name="input" path="/viewJsBundleExamples.do" />
+      <set-property property="cancellable" value="true"/>
     </action>
 
     <!-- validwhen Examples -->
@@ -93,6 +99,7 @@
     <action path="/validateValidWhenExamples" type="org.apache.struts.actions.ForwardAction"
name="validWhenForm" scope="request" 
             parameter="/validator/welcome.do" validate="true" input="input" >
             <forward name="input" path="/viewValidWhenExamples.do" />
+      <set-property property="cancellable" value="true"/>
     </action>
 
     <!-- Locale Action -->

Added: struts/action/branches/STRUTS_1_2_BRANCH/web/examples/exercise/html-cancel.jsp
URL: http://svn.apache.org/viewcvs/struts/action/branches/STRUTS_1_2_BRANCH/web/examples/exercise/html-cancel.jsp?rev=377805&view=auto
==============================================================================
--- struts/action/branches/STRUTS_1_2_BRANCH/web/examples/exercise/html-cancel.jsp (added)
+++ struts/action/branches/STRUTS_1_2_BRANCH/web/examples/exercise/html-cancel.jsp Tue Feb
14 11:26:15 2006
@@ -0,0 +1,98 @@
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
+<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
+<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
+<html:html>
+    <head>
+        <title>
+            <title>Test struts-html:cancel Tag</title>
+        </title>
+        <html:base/>
+    </head>
+
+    <body bgcolor="white">
+
+    <p><strong>Cancel Not Allowed - Error Message</strong></p>
+
+    <p>
+        Pressing the Cancel button should display an error
+        message, since Cancellable is not set for this Action
+        but an Exception handler has been configured to handle
+        the throw exception.
+    </p>
+
+    <logic:messagesPresent>
+    <p>
+        <font color="red"><strong>
+            <html:messages id="msg">
+                <bean:write name="msg"/>
+            </html:messages>
+         </strong></font>
+    </p>
+    </logic:messagesPresent>
+
+    <p>
+        <html:form action="/html-cancel-false">
+            <html:submit property="submit"/>
+            &#160;
+            <html:reset/>
+            <html:cancel/>
+        </html:form>
+    </p>
+
+    <hr/>
+
+    <p><strong>Cancel Not Allowed - Exception</strong></p>
+    <p>
+        Pressing this Cancel button should throw an 
+        <code>org.apache.struts.action.InvalidCancelException</code>
+        since Cancellable is not set for this Action and no exception
+        handler was configured.
+    </p>
+
+    <p>
+        <html:form action="/html-cancel-exception">
+            <html:submit property="submit"/>
+            &#160;
+            <html:reset/>
+            <html:cancel/>
+        </html:form>
+    </p>
+
+    <hr/>
+
+    <p><strong>Cancel Allowed  (Validate true)</strong></p>
+    <p>
+        Pressing this Cancel button should return to the Welcome page,
+        as Cancellable is set to true for this Action.
+    </p>
+
+    <p>
+        <html:form action="/html-cancel-true">
+            <html:submit property="submit"/>
+            &#160;
+            <html:reset/>
+            <html:cancel/>
+        </html:form>
+    </p>
+    <hr/>
+
+    <p><strong>Cancel Not Allowed - Exception (Validate false)</strong></p>
+    <p>
+        Pressing this Cancel button should throw an 
+        <code>org.apache.struts.action.InvalidCancelException</code>
+        since Cancellable is not set for this Action even though
+        the mapping is set to NOT validate.
+    </p>
+
+    <p>
+        <html:form action="/html-cancel-novalidate">
+            <html:submit property="submit"/>
+            &#160;
+            <html:reset/>
+            <html:cancel/>
+        </html:form>
+    </p>
+
+    </body>
+</html:html>

Propchange: struts/action/branches/STRUTS_1_2_BRANCH/web/examples/exercise/html-cancel.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/action/branches/STRUTS_1_2_BRANCH/web/examples/exercise/html-cancel.jsp
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: struts/action/branches/STRUTS_1_2_BRANCH/web/examples/exercise/index.html
URL: http://svn.apache.org/viewcvs/struts/action/branches/STRUTS_1_2_BRANCH/web/examples/exercise/index.html?rev=377805&r1=377804&r2=377805&view=diff
==============================================================================
--- struts/action/branches/STRUTS_1_2_BRANCH/web/examples/exercise/index.html (original)
+++ struts/action/branches/STRUTS_1_2_BRANCH/web/examples/exercise/index.html Tue Feb 14 11:26:15
2006
@@ -42,6 +42,8 @@
   <h3>HTML Tags</h3>
 
   <ul>
+    <li><a href="html-cancel.do">&lt;html:cancel&gt;</a></li>
+
     <li><a href="html-img.do">&lt;html:img&gt;</a></li>
 
     <li><a href="html-link.do">&lt;html:link&gt;</a></li>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message