Author: plightbo
Date: Fri May 19 13:00:43 2006
New Revision: 407897

URL: http://svn.apache.org/viewvc?rev=407897&view=rev
Log:
- avoid NPE in XworkException
- executeAndWait interceptor is smarter now (works with validation). it's still 
ugly, but much better
- console doesn't spit out the full URL w/ params
- some fixes left over from refactoring in quickstart

Modified:
    
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/interceptor/ExecuteAndWaitInterceptor.java
    
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/quickstart/MultiWebApplicationContext.java
    
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/quickstart/QuickStart.java
    
struts/action2/trunk/core/src/main/resources/org/apache/struts/action2/interceptor/debugging/console.ftl
    
struts/action2/trunk/core/src/main/resources/org/apache/struts/action2/interceptor/wait.ftl
    struts/action2/trunk/core/src/main/resources/struts-default.xml

Modified: 
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/interceptor/ExecuteAndWaitInterceptor.java
URL: 
http://svn.apache.org/viewvc/struts/action2/trunk/core/src/main/java/org/apache/struts/action2/interceptor/ExecuteAndWaitInterceptor.java?rev=407897&r1=407896&r2=407897&view=diff
==============================================================================
--- 
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/interceptor/ExecuteAndWaitInterceptor.java
 (original)
+++ 
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/interceptor/ExecuteAndWaitInterceptor.java
 Fri May 19 13:00:43 2006
@@ -22,6 +22,7 @@
 import com.opensymphony.xwork.ActionProxy;
 import com.opensymphony.xwork.config.entities.ResultConfig;
 import com.opensymphony.xwork.interceptor.Interceptor;
+import com.opensymphony.xwork.interceptor.MethodFilterInterceptor;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -157,7 +158,7 @@
  * <!-- END SNIPPET: example -->
  *
  */
-public class ExecuteAndWaitInterceptor implements Interceptor {
+public class ExecuteAndWaitInterceptor extends MethodFilterInterceptor {
        
        private static final long serialVersionUID = -2754639196749652512L;
 
@@ -177,22 +178,31 @@
         return new BackgroundProcess(name + "BackgroundThread", 
actionInvocation, threadPriority);
     }
 
-    public String intercept(ActionInvocation actionInvocation) throws 
Exception {
+    protected String doIntercept(ActionInvocation actionInvocation) throws 
Exception {
         ActionProxy proxy = actionInvocation.getProxy();
         String name = proxy.getActionName();
         ActionContext context = actionInvocation.getInvocationContext();
         Map session = context.getSession();
 
+        Boolean secondTime = (Boolean) context.get(KEY);
+        if (secondTime == null) {
+            context.put(KEY, true);
+            secondTime = false;
+        } else {
+            secondTime = true;
+        }
+
         synchronized (session) {
             BackgroundProcess bp = (BackgroundProcess) session.get(KEY + name);
 
-            if (bp == null) {
+            if (secondTime && bp == null) {
                 bp = getNewBackgroundProcess(name, actionInvocation, 
threadPriority);
                 session.put(KEY + name, bp);
                 performInitialDelay(bp); // first time let some time pass 
before showing wait page
+                secondTime = false;
             }
 
-            if (!bp.isDone()) {
+            if (!secondTime && bp != null && !bp.isDone()) {
                 actionInvocation.getStack().push(bp.getAction());
                 Map results = proxy.getConfig().getResults();
                 if (!results.containsKey(WAIT)) {
@@ -202,12 +212,12 @@
                             "'! This requires FreeMarker support and won't 
work if you don't have it installed");
                     // no wait result? hmm -- let's try to do dynamically put 
it in for you!
                     ResultConfig rc = new ResultConfig(WAIT, 
"org.apache.struts.action2.views.freemarker.FreemarkerResult",
-                            Collections.singletonMap("location", 
"org/apache/struts/action2/interceptor/wait.ftl"));
+                            Collections.singletonMap("location", 
"/org/apache/struts/action2/interceptor/wait.ftl"));
                     results.put(WAIT, rc);
                 }
 
                 return WAIT;
-            } else {
+            } else if (!secondTime && bp != null && bp.isDone()) {
                 session.remove(KEY + name);
                 actionInvocation.getStack().push(bp.getAction());
 
@@ -217,6 +227,12 @@
                 }
 
                 return bp.getResult();
+            } else {
+                // this is the first instance of the interceptor and there is 
no existing action
+                // already run in the background, so let's just let this pass 
through. We assume
+                // the action invocation will be run in the background on the 
subsequent pass through
+                // this interceptor
+                return actionInvocation.invoke();
             }
         }
     }

Modified: 
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/quickstart/MultiWebApplicationContext.java
URL: 
http://svn.apache.org/viewvc/struts/action2/trunk/core/src/main/java/org/apache/struts/action2/quickstart/MultiWebApplicationContext.java?rev=407897&r1=407896&r2=407897&view=diff
==============================================================================
--- 
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/quickstart/MultiWebApplicationContext.java
 (original)
+++ 
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/quickstart/MultiWebApplicationContext.java
 Fri May 19 13:00:43 2006
@@ -87,8 +87,8 @@
         // Alright, let's just hack this to work in IDEA
         if (uriInContext.equals("/struts-action")) {
             // we do this check to support both "quickstart:showcase" and 
"quickstart" (using quickstart.xml)
-            if (new 
File("../../action/src/main/resources/META-INF/taglib.tld").exists()) {
-                return 
FileResource.newResource("../../action/src/main/resources/META-INF/taglib.tld");
+            if (new 
File("../../core/src/main/resources/META-INF/taglib.tld").exists()) {
+                return 
FileResource.newResource("../../core/src/main/resources/META-INF/taglib.tld");
             } else {
                 return 
FileResource.newResource("src/main/resources/META-INF/taglib.tld");
             }

Modified: 
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/quickstart/QuickStart.java
URL: 
http://svn.apache.org/viewvc/struts/action2/trunk/core/src/main/java/org/apache/struts/action2/quickstart/QuickStart.java?rev=407897&r1=407896&r2=407897&view=diff
==============================================================================
--- 
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/quickstart/QuickStart.java
 (original)
+++ 
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/quickstart/QuickStart.java
 Fri May 19 13:00:43 2006
@@ -174,7 +174,8 @@
         System.out.println("");
         
System.out.println("********************************************************");
         System.out.println("Quick-started at http://localhost:"; + c.getPort() 
+ c.getContext());
-        System.out.println("You may now edit your Java source files and web 
files.");
+        System.out.println("You may now edit your Java classes and web files 
without");
+        System.out.println(" deploying or restarting.");
         
System.out.println("********************************************************");
     }
 

Modified: 
struts/action2/trunk/core/src/main/resources/org/apache/struts/action2/interceptor/debugging/console.ftl
URL: 
http://svn.apache.org/viewvc/struts/action2/trunk/core/src/main/resources/org/apache/struts/action2/interceptor/debugging/console.ftl?rev=407897&r1=407896&r2=407897&view=diff
==============================================================================
--- 
struts/action2/trunk/core/src/main/resources/org/apache/struts/action2/interceptor/debugging/console.ftl
 (original)
+++ 
struts/action2/trunk/core/src/main/resources/org/apache/struts/action2/interceptor/debugging/console.ftl
 Fri May 19 13:00:43 2006
@@ -1,7 +1,7 @@
 <html>
 <head>
     <script language="javascript">
-    var baseUrl = "<@ww.url value="/struts"/>";
+    var baseUrl = "<@saf.url value="/struts" includeParams="none"/>";
     window.open(baseUrl+"/webconsole.html", 'OGNL 
Console','width=500,height=450,'+
         'status=no,toolbar=no,menubar=no');
     </script>    

Modified: 
struts/action2/trunk/core/src/main/resources/org/apache/struts/action2/interceptor/wait.ftl
URL: 
http://svn.apache.org/viewvc/struts/action2/trunk/core/src/main/resources/org/apache/struts/action2/interceptor/wait.ftl?rev=407897&r1=407896&r2=407897&view=diff
==============================================================================
--- 
struts/action2/trunk/core/src/main/resources/org/apache/struts/action2/interceptor/wait.ftl
 (original)
+++ 
struts/action2/trunk/core/src/main/resources/org/apache/struts/action2/interceptor/wait.ftl
 Fri May 19 13:00:43 2006
@@ -1,6 +1,6 @@
 <html>
     <head>
-        <meta http-equiv="refresh" content="5;url=<@ww.url 
includeParams="all"/>"/>
+        <meta http-equiv="refresh" content="5;url=<@saf.url 
includeParams="none"/>"/>
     </head>
     <body>
         Please wait while we process your request...

Modified: struts/action2/trunk/core/src/main/resources/struts-default.xml
URL: 
http://svn.apache.org/viewvc/struts/action2/trunk/core/src/main/resources/struts-default.xml?rev=407897&r1=407896&r2=407897&view=diff
==============================================================================
--- struts/action2/trunk/core/src/main/resources/struts-default.xml (original)
+++ struts/action2/trunk/core/src/main/resources/struts-default.xml Fri May 19 
13:00:43 2006
@@ -94,13 +94,6 @@
                 <interceptor-ref name="basicStack"/>
             </interceptor-stack>
 
-            <!-- Sample execute and wait stack.
-                 Note: execAndWait should always be the *last* interceptor. -->
-            <interceptor-stack name="executeAndWaitStack">
-                <interceptor-ref name="basicStack"/>
-                <interceptor-ref name="execAndWait"/>
-            </interceptor-stack>
-
             <!-- An example of the params-prepare-params trick. This stack
                  is exactly the same as the defaultStack, except that it
                  includes one extra interceptor before the prepare interceptor:
@@ -171,6 +164,18 @@
                  old name -->
             <interceptor-stack name="completeStack">
                 <interceptor-ref name="defaultStack"/>
+            </interceptor-stack>
+
+            <!-- Sample execute and wait stack.
+                 Note: execAndWait should always be the *last* interceptor. -->
+            <interceptor-stack name="executeAndWaitStack">
+                <interceptor-ref name="execAndWait">
+                    <param name="excludeMethods">input,back,cancel</param>
+                </interceptor-ref>
+                <interceptor-ref name="defaultStack"/>
+                <interceptor-ref name="execAndWait">
+                    <param name="excludeMethods">input,back,cancel</param>
+                </interceptor-ref>
             </interceptor-stack>
         </interceptors>
 


Reply via email to