Commits

Anonymous committed 690fb06

WW-293: Token session store works now. ActionContext is no longer saved with ActionInvocation and re-constituted, only ValueStack (ActionContext was too much to serialize)

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@39573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (5)

lib/core/xwork-1.0-beta.jar

Binary file modified.

src/java/com/opensymphony/webwork/dispatcher/ApplicationMap.java

  */
 package com.opensymphony.webwork.dispatcher;
 
+import java.io.Serializable;
+
 import java.util.AbstractMap;
 import java.util.Enumeration;
 import java.util.HashSet;
  * @author Rickard Öberg (rickard@middleware-company.com)
  * @version $Revision$
  */
-public class ApplicationMap extends AbstractMap {
+public class ApplicationMap extends AbstractMap implements Serializable {
     //~ Instance fields ////////////////////////////////////////////////////////
 
     ServletContext context;

src/java/com/opensymphony/webwork/dispatcher/SessionMap.java

  */
 package com.opensymphony.webwork.dispatcher;
 
+import java.io.Serializable;
+
 import java.util.AbstractMap;
 import java.util.Enumeration;
 import java.util.HashSet;
  * @author Rickard Öberg (rickard@middleware-company.com)
  * @version $Revision$
  */
-public class SessionMap extends AbstractMap {
+public class SessionMap extends AbstractMap implements Serializable {
     //~ Instance fields ////////////////////////////////////////////////////////
 
     HttpSession session;

src/java/com/opensymphony/webwork/util/InvocationSessionStore.java

 
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ActionInvocation;
+import com.opensymphony.xwork.util.OgnlValueStack;
+
+import java.io.Serializable;
 
 import java.util.HashMap;
 import java.util.Map;
     //~ Methods ////////////////////////////////////////////////////////////////
 
     /**
-    * Checks the Map in the Session for the key and the token. If the DefaultActionInvocation is saved in the Session, it
-    * gets the DefaultActionInvocation and ActionContext saved in the Session and sets the ActionContext into the
-    * ActionContext ThreadLocal and returns the DefaultActionInvocation.
-    * @param key the name the DefaultActionInvocation and ActionContext were saved as
-    * @return the DefaultActionInvocation saved using the key, or null if none was found
-    */
+     * Checks the Map in the Session for the key and the token. If the
+     * ActionInvocation is saved in the Session, the ValueStack from the
+     * ActionProxy associated with the ActionInvocation is set into the
+     * ActionContext and the ActionInvocation is returned.
+     * @param key the name the DefaultActionInvocation and ActionContext were saved as
+     * @return the DefaultActionInvocation saved using the key, or null if none was found
+     */
     public static ActionInvocation loadInvocation(String key, String token) {
         InvocationContext invocationContext = (InvocationContext) getInvocationMap().get(key);
 
             return null;
         }
 
-        ActionContext.setContext(invocationContext.context);
+        OgnlValueStack stack = invocationContext.invocation.getProxy().getValueStack();
+        ActionContext.getContext().setValueStack(stack);
 
         return invocationContext.invocation;
     }
     * @param invocation
     */
     public static void storeInvocation(String key, String token, ActionInvocation invocation) {
-        ActionContext context = ActionContext.getContext();
-        InvocationContext invocationContext = new InvocationContext(invocation, context, token);
+        InvocationContext invocationContext = new InvocationContext(invocation, token);
         Map invocationMap = getInvocationMap();
         invocationMap.put(key, invocationContext);
         setInvocationMap(invocationMap);
 
     //~ Inner Classes //////////////////////////////////////////////////////////
 
-    private static class InvocationContext {
-        ActionContext context;
+    private static class InvocationContext implements Serializable {
         ActionInvocation invocation;
         String token;
 
-        public InvocationContext(ActionInvocation invocation, ActionContext context, String token) {
+        public InvocationContext(ActionInvocation invocation, String token) {
             this.invocation = invocation;
-            this.context = context;
             this.token = token;
         }
     }

src/test/com/opensymphony/webwork/util/InvocationSessionStoreTest.java

  */
 package com.opensymphony.webwork.util;
 
-import com.opensymphony.webwork.TestAction;
+import com.mockobjects.dynamic.Mock;
 
-import com.opensymphony.xwork.Action;
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ActionInvocation;
 import com.opensymphony.xwork.ActionProxy;
-import com.opensymphony.xwork.ActionProxyFactory;
-import com.opensymphony.xwork.config.Configuration;
-import com.opensymphony.xwork.config.ConfigurationManager;
-import com.opensymphony.xwork.config.ConfigurationProvider;
-import com.opensymphony.xwork.config.entities.ActionConfig;
-import com.opensymphony.xwork.config.entities.PackageConfig;
-import com.opensymphony.xwork.interceptor.Interceptor;
-
-import junit.framework.Assert;
+import com.opensymphony.xwork.util.OgnlValueStack;
+
 import junit.framework.TestCase;
 
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 
 public class InvocationSessionStoreTest extends TestCase {
     //~ Static fields/initializers /////////////////////////////////////////////
 
-    private static final String ACTION_NAME = "com.opensymphony.webwork.util.InvocationSessionStoreTest.action";
     private static final String INVOCATION_KEY = "com.opensymphony.webwork.util.InvocationSessionStoreTest.invocation";
     private static final String TOKEN_VALUE = "com.opensymphony.webwork.util.InvocationSessionStoreTest.token";
 
     //~ Instance fields ////////////////////////////////////////////////////////
 
-    private Map extraContext;
+    private ActionInvocation invocation;
     private Map session;
+    private Mock invocationMock;
+    private OgnlValueStack stack;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
     public void testStore() {
-        try {
-            ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("", ACTION_NAME, extraContext);
-            assertEquals(Action.SUCCESS, proxy.execute());
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail();
-        }
+        assertNull(InvocationSessionStore.loadInvocation(INVOCATION_KEY, TOKEN_VALUE));
+        InvocationSessionStore.storeInvocation(INVOCATION_KEY, TOKEN_VALUE, invocation);
+        assertNotNull(InvocationSessionStore.loadInvocation(INVOCATION_KEY, TOKEN_VALUE));
+        assertEquals(invocation, InvocationSessionStore.loadInvocation(INVOCATION_KEY, TOKEN_VALUE));
     }
 
-    protected void setUp() throws Exception {
-        ConfigurationManager.clearConfigurationProviders();
-        ConfigurationManager.addConfigurationProvider(new InvocationSessionStoreTestConfigurationProvider());
-        ConfigurationManager.getConfiguration().reload();
-
-        session = new HashMap();
-        extraContext = new HashMap();
-        extraContext.put(ActionContext.SESSION, session);
-    }
-
-    //~ Inner Classes //////////////////////////////////////////////////////////
-
-    class InvocationSessionStoreTestConfigurationProvider implements ConfigurationProvider {
-        public void destroy() {
-        }
-
-        /**
-        * Initializes the configuration object.
-        */
-        public void init(Configuration configuration) {
-            PackageConfig defaultPackageConfig = new PackageConfig();
-
-            List interceptors = new ArrayList();
-            interceptors.add(new InvocationSessionStoreTestInterceptor());
-
-            ActionConfig testActionConfig = new ActionConfig(null, TestAction.class, null, null, interceptors);
-            defaultPackageConfig.addActionConfig(ACTION_NAME, testActionConfig);
-
-            configuration.addPackageConfig("defaultPackage", defaultPackageConfig);
-        }
-
-        /**
-         * Tells whether the ConfigurationProvider should reload its configuration
-         * @return
-         */
-        public boolean needsReload() {
-            return false;
-        }
+    public void testValueStackReset() {
+        ActionContext actionContext = ActionContext.getContext();
+        assertEquals(stack, actionContext.getValueStack());
+        InvocationSessionStore.storeInvocation(INVOCATION_KEY, TOKEN_VALUE, invocation);
+        actionContext.setValueStack(null);
+        assertNull(actionContext.getValueStack());
+        InvocationSessionStore.loadInvocation(INVOCATION_KEY, TOKEN_VALUE);
+        assertEquals(stack, actionContext.getValueStack());
     }
 
-    class InvocationSessionStoreTestInterceptor implements Interceptor {
-        public void destroy() {
-        }
+    protected void setUp() throws Exception {
+        ActionContext actionContext = ActionContext.getContext();
+        session = new HashMap();
+        actionContext.setSession(session);
 
-        public void init() {
-        }
+        invocationMock = new Mock(ActionInvocation.class);
+        invocation = (ActionInvocation) invocationMock.proxy();
 
-        public String intercept(ActionInvocation invocation) throws Exception {
-            assertNull(InvocationSessionStore.loadInvocation(INVOCATION_KEY, TOKEN_VALUE));
+        stack = new OgnlValueStack();
+        actionContext.setValueStack(stack);
 
-            ActionContext context = ActionContext.getContext();
-            InvocationSessionStore.storeInvocation(INVOCATION_KEY, TOKEN_VALUE, invocation);
+        Mock proxyMock = new Mock(ActionProxy.class);
+        proxyMock.matchAndReturn("getValueStack", stack);
 
-            ActionContext newContext = new ActionContext(extraContext);
-            ActionContext.setContext(newContext);
-            Assert.assertEquals(newContext, ActionContext.getContext());
-            Assert.assertEquals(invocation, InvocationSessionStore.loadInvocation(INVOCATION_KEY, TOKEN_VALUE));
-            Assert.assertEquals(context, ActionContext.getContext());
+        ActionProxy proxy = (ActionProxy) proxyMock.proxy();
 
-            return Action.SUCCESS;
-        }
+        invocationMock.matchAndReturn("getProxy", proxy);
     }
 }