Anonymous avatar Anonymous committed 2fe9e26

XW-174 - getMethod() now takes a Class to check if the Class has changed between calls as a hack to fix a problem with proxied Actions coming from Spring.

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@368 e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (3)

src/java/com/opensymphony/xwork/DefaultActionInvocation.java

         }
 
         try {
-            Method method = actionConfig.getMethod();
+            Method method = actionConfig.getMethod(action.getClass());
 
             if (action instanceof Proxy) {
                 try {

src/java/com/opensymphony/xwork/config/entities/ActionConfig.java

  */
 package com.opensymphony.xwork.config.entities;
 
-import com.opensymphony.xwork.Action;
-import com.opensymphony.xwork.ObjectFactory;
 import com.opensymphony.xwork.interceptor.Interceptor;
 
 import java.io.Serializable;
-
 import java.lang.reflect.Method;
-
 import java.util.*;
 
 
     protected String className;
     protected String methodName;
     protected String packageName;
+    protected Class cachedClass;
 
     //~ Constructors ///////////////////////////////////////////////////////////
 
      * Returns cached instance of the action method or null if method name was not specified
      *
      * @return cached instance of the action method or null if method name was not specified
+     * @param actionClass - passed in to check that the Action class hasn't changed since last time.
+     * This is really a hack to get around a problem with proxied Actions in Spring.
      */
-    public Method getMethod() throws NoSuchMethodException {
+    public Method getMethod(Class actionClass) throws NoSuchMethodException {
+        if (!actionClass.equals(cachedClass)) {
+            cachedClass = actionClass;
+            method = null;
+        }
         if (method != null) {
             return method;
         }
 
-        Class clazz;
-
-        try {
-            ActionConfig actionConfig = new ActionConfig(null, getClassName(), null, null, null);
-            Action action = ObjectFactory.getObjectFactory().buildAction(actionConfig);
-            clazz = action.getClass();
-        } catch (Exception e) { // TODO: Only doing this because buildAction() throws Exception
-            throw new NoSuchMethodException("Unable to load action: " + e.getMessage());
-        }
-
         if (methodName != null) {
             try {
-                method = clazz.getMethod(methodName, new Class[0]);
+                method = cachedClass.getMethod(methodName, new Class[0]);
             } catch (NoSuchMethodException e) {
                 try {
-                    method = clazz.getMethod("do" + String.valueOf(methodName.charAt(0)).toUpperCase() + methodName.substring(1), new Class[0]);
+                    method = cachedClass.getMethod("do" + String.valueOf(methodName.charAt(0)).toUpperCase() + methodName.substring(1), new Class[0]);
                 } catch (NoSuchMethodException e1) {
                     throw e;
                 }
             }
         } else // return default execute() method if method name is not specified
          {
-            method = clazz.getMethod("execute", new Class[0]);
+            method = cachedClass.getMethod("execute", new Class[0]);
         }
 
         return method;

src/test/com/opensymphony/xwork/config/entities/ActionConfigTest.java

+/*
+ * Copyright (c) 2004 Opensymphony. All Rights Reserved.
+ */
+package com.opensymphony.xwork.config.entities;
+
+import com.opensymphony.xwork.SimpleAction;
+import com.opensymphony.xwork.SimpleFooAction;
+import junit.framework.TestCase;
+
+import java.lang.reflect.Method;
+
+/**
+ * ActionConfigTest
+ *
+ * @author Jason Carreira <jason@zenfrog.com>
+ */
+public class ActionConfigTest extends TestCase {
+    public void testActionClassChangeGetsNewMethod() throws NoSuchMethodException {
+        ActionConfig config = new ActionConfig();
+        Method method1 = config.getMethod(SimpleAction.class);
+        Method method2 = config.getMethod(SimpleFooAction.class);
+        assertNotSame(method1,method2);
+    }
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.