1. opensymphony
  2. xwork

Commits

tm_jee  committed da25bd7

XW-516 (interceptor-stack's interceptor parameter overriding does not work when there's nested interceptor-stack)
- make changes to fix an serious issue resulting form previous XW-516 fix that doesn't take into account the ordering of interceptors after param-overriding.

git-svn-id: http://svn.opensymphony.com/svn/xwork/branches/xwork_1-2@1521e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits f0efda4
  • Branches xwork_1-2

Comments (0)

Files changed (3)

File src/java/com/opensymphony/xwork/config/providers/InterceptorBuilder.java

View file
  • Ignore whitespace
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
      */
     private static List constructParameterizedInterceptorReferences(PackageConfig packageConfig, 
     		InterceptorStackConfig stackConfig, Map refParams) {
-        Set result;
-        Map params = new HashMap();
+        List result;
+        Map params = new LinkedHashMap();
         
         /*
          * We strip
                 if ( params.containsKey(name)) {
                     map = (Map) params.get(name);
                 } else {
-                    map = new HashMap();
+                    map = new LinkedHashMap();
                 }
 
                 map.put(key, value);
             }
         }
 
-        result = new LinkedHashSet(stackConfig.getInterceptors());
+        result = new ArrayList(stackConfig.getInterceptors());
 
         for ( Iterator iter = params.keySet().iterator(); iter.hasNext();) {
             String key = (String) iter.next();
             		// if an existing interceptor mapping exists, 
             		// we remove from the result Set, just to make sure 
             		// there's always one unique mapping.
-            		result.remove(mapping);
+            		int index = result.indexOf(mapping);
+            		result.set(index, mapping);
+            	}
+            	else {
+            		result.add(mapping);
             	}
-                result.add(mapping);
             }
             else if (interceptorCfgObj instanceof InterceptorStackConfig){  // interceptor-ref param refer to an interceptor stack
             	
             	for (Iterator i = tmpResult.iterator(); i.hasNext(); ) {
             		InterceptorMapping tmpInterceptorMapping = (InterceptorMapping) i.next();
             		if (result.contains(tmpInterceptorMapping)) {
-            			result.remove(tmpInterceptorMapping);
+            			int index = result.indexOf(tmpInterceptorMapping);
+            			result.set(index, tmpInterceptorMapping);
+            		}
+            		else {
+            			result.add(tmpInterceptorMapping);
             		}
-            		result.add(tmpInterceptorMapping);
             	}
             }
         }
-        return new ArrayList(result);
+        return result;
     }
 }

File src/test/com/opensymphony/xwork/config/providers/XmlConfigurationProviderInterceptorParamOverridingTest.java

View file
  • Ignore whitespace
  */
 package com.opensymphony.xwork.config.providers;
 
-import java.util.Iterator;
 import java.util.List;
 
-import com.opensymphony.xwork.XWorkTestCase;
 import com.opensymphony.xwork.config.ConfigurationManager;
 import com.opensymphony.xwork.config.RuntimeConfiguration;
 import com.opensymphony.xwork.config.entities.ActionConfig;
 import com.opensymphony.xwork.config.entities.InterceptorMapping;
 import com.opensymphony.xwork.config.impl.DefaultConfiguration;
 
+import junit.framework.TestCase;
+
 /**
  * 
  * @author tm_jee
  * @version $Date$ $Id$
  */
-public class XmlConfigurationProviderInterceptorParamOverridingTest extends XWorkTestCase {
+public class XmlConfigurationProviderInterceptorParamOverridingTest extends TestCase {
 
-	public void testInterceptorParamOveriding() throws Exception {
+	public void testParamOveriding() throws Exception {
 		DefaultConfiguration conf = new DefaultConfiguration();
 		XmlConfigurationProvider p = new XmlConfigurationProvider("com/opensymphony/xwork/config/providers/xwork-test-interceptor-param-overriding.xml");
 		ConfigurationManager.addConfigurationProvider(p);
 		assertNotNull(actionTwoInterceptorMapping2);
 		assertNotNull(actionTwoInterceptorMapping3);
 		
-		assertInterceptorParamOneEquals(actionOne, "interceptorOne", "i1p1");
-		assertInterceptorParamTwoEquals(actionOne, "interceptorOne", "i1p2");
-		assertInterceptorParamOneEquals(actionOne, "interceptorTwo", "i2p1" );
-		assertInterceptorParamTwoEquals(actionOne, "interceptorTwo", null);
-		assertInterceptorParamOneEquals(actionOne, "interceptorThree", null);
-		assertInterceptorParamTwoEquals(actionOne, "interceptorThree", null);
+		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping1.getInterceptor()).getParamOne(), "i1p1");
+		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping1.getInterceptor()).getParamTwo(), "i1p2");
+		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping2.getInterceptor()).getParamOne(), "i2p1");
+		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping2.getInterceptor()).getParamTwo(), null);
+		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping3.getInterceptor()).getParamOne(), null);
+		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping3.getInterceptor()).getParamTwo(), null);
+		
+		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping1.getInterceptor()).getParamOne(), null);
+		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping1.getInterceptor()).getParamTwo(), null);
+		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping2.getInterceptor()).getParamOne(), null);
+		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping2.getInterceptor()).getParamTwo(), "i2p2");
+		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping3.getInterceptor()).getParamOne(), "i3p1");
+		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping3.getInterceptor()).getParamTwo(), "i3p2");
 		
-		assertInterceptorParamOneEquals(actionTwo, "interceptorOne", null);
-		assertInterceptorParamTwoEquals(actionTwo, "interceptorOne", null);
-		assertInterceptorParamOneEquals(actionTwo, "interceptorTwo", null);
-		assertInterceptorParamTwoEquals(actionTwo, "interceptorTwo", "i2p2");
-		assertInterceptorParamOneEquals(actionTwo, "interceptorThree", "i3p1");
-		assertInterceptorParamTwoEquals(actionTwo, "interceptorThree", "i3p2");
-	}
-	
-	protected void assertInterceptorParamOneEquals(ActionConfig actionConfig,String interceptorName,  String paramValue) {
-		List interceptorMappings = actionConfig.getInterceptors();
-		for (Iterator i = interceptorMappings.iterator(); i.hasNext();) {
-			InterceptorMapping interceptorMapping = (InterceptorMapping) i.next();
-			assertNotNull(interceptorMapping.getInterceptor());
-			if (interceptorMapping.getName().equals(interceptorName)) {
-				assertEquals(((InterceptorForTestPurpose)interceptorMapping.getInterceptor()).getParamOne(), paramValue);
-				return;
-			}
-		}
-		fail();
-	}
-	
-	protected void assertInterceptorParamTwoEquals(ActionConfig actionConfig, String interceptorName, String paramValue) {
-		List interceptorMappings = actionConfig.getInterceptors();
-		for (Iterator i = interceptorMappings.iterator(); i.hasNext();) {
-			InterceptorMapping interceptorMapping = (InterceptorMapping) i.next();
-			assertNotNull(interceptorMapping.getInterceptor());
-			if (interceptorMapping.getName().equals(interceptorName)) {
-				assertEquals(((InterceptorForTestPurpose)interceptorMapping.getInterceptor()).getParamTwo(), paramValue);
-				return;
-			}
-		}
-		fail();
 	}
 	
 	protected void tearDown() throws Exception {

File src/test/com/opensymphony/xwork/config/providers/XmlConfigurationProviderInterceptorStackParamOverridingTest.java

View file
  • Ignore whitespace
  */
 package com.opensymphony.xwork.config.providers;
 
-import java.util.Iterator;
 import java.util.List;
 
 import com.opensymphony.xwork.XWorkTestCase;
 
 /**
  * @author tmjee
- *
+ * @version $Date$ $Id$
  */
 public class XmlConfigurationProviderInterceptorStackParamOverridingTest extends XWorkTestCase {
 
 		assertNotNull(actionTwoInterceptorMapping3);
 		
 		
-		assertInterceptorParamOneEquals(actionOne, "interceptorOne", "i1p1");
-		assertInterceptorParamTwoEquals(actionOne, "interceptorOne", "i1p2");
-		assertInterceptorParamOneEquals(actionOne, "interceptorTwo", "i2p1" );
-		assertInterceptorParamTwoEquals(actionOne, "interceptorTwo", null);
-		assertInterceptorParamOneEquals(actionOne, "interceptorThree", null);
-		assertInterceptorParamTwoEquals(actionOne, "interceptorThree", null);
+		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping1.getInterceptor()).getParamOne(), "i1p1");
+		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping1.getInterceptor()).getParamTwo(), "i1p2");
+		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping2.getInterceptor()).getParamOne(), "i2p1");
+		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping2.getInterceptor()).getParamTwo(), null);
+		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping3.getInterceptor()).getParamOne(), null);
+		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping3.getInterceptor()).getParamTwo(), null);
 		
-		assertInterceptorParamOneEquals(actionTwo, "interceptorOne", null);
-		assertInterceptorParamTwoEquals(actionTwo, "interceptorOne", null);
-		assertInterceptorParamOneEquals(actionTwo, "interceptorTwo", null);
-		assertInterceptorParamTwoEquals(actionTwo, "interceptorTwo", "i2p2");
-		assertInterceptorParamOneEquals(actionTwo, "interceptorThree", "i3p1");
-		assertInterceptorParamTwoEquals(actionTwo, "interceptorThree", "i3p2");
-		
-	}
-	
-	protected void assertInterceptorParamOneEquals(ActionConfig actionConfig,String interceptorName,  String paramValue) {
-		List interceptorMappings = actionConfig.getInterceptors();
-		for (Iterator i = interceptorMappings.iterator(); i.hasNext();) {
-			InterceptorMapping interceptorMapping = (InterceptorMapping) i.next();
-			assertNotNull(interceptorMapping.getInterceptor());
-			if (interceptorMapping.getName().equals(interceptorName)) {
-				assertEquals(((InterceptorForTestPurpose)interceptorMapping.getInterceptor()).getParamOne(), paramValue);
-				return;
-			}
-		}
-		fail();
-	}
-	
-	protected void assertInterceptorParamTwoEquals(ActionConfig actionConfig, String interceptorName, String paramValue) {
-		List interceptorMappings = actionConfig.getInterceptors();
-		for (Iterator i = interceptorMappings.iterator(); i.hasNext();) {
-			InterceptorMapping interceptorMapping = (InterceptorMapping) i.next();
-			assertNotNull(interceptorMapping.getInterceptor());
-			if (interceptorMapping.getName().equals(interceptorName)) {
-				assertEquals(((InterceptorForTestPurpose)interceptorMapping.getInterceptor()).getParamTwo(), paramValue);
-				return;
-			}
-		}
-		fail();
+		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping1.getInterceptor()).getParamOne(), null);
+		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping1.getInterceptor()).getParamTwo(), null);
+		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping2.getInterceptor()).getParamOne(), null);
+		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping2.getInterceptor()).getParamTwo(), "i2p2");
+		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping3.getInterceptor()).getParamOne(), "i3p1");
+		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping3.getInterceptor()).getParamTwo(), "i3p2");
 	}
 	
 	protected void tearDown() throws Exception {