Commits

Anonymous committed 8e4b376

XW-386
- fix "XWork don't create result using Spring"

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

  • Participants
  • Parent commits b48ada6

Comments (0)

Files changed (12)

File src/java/com/opensymphony/xwork2/DefaultActionInvocation.java

 
         if (resultConfig != null) {
             try {
-                return ObjectFactory.getObjectFactory().buildResult(resultConfig, invocationContext.getContextMap());
+                Result result = ObjectFactory.getObjectFactory().buildResult(resultConfig, invocationContext.getContextMap());
+                return result;
             } catch (Exception e) {
                 LOG.error("There was an exception while instantiating the result of type " + resultConfig.getClassName(), e);
                 throw new XWorkException(e, resultConfig);

File src/java/com/opensymphony/xwork2/config/entities/ResultConfig.java

         params = new LinkedHashMap();
     }
 
-    public ResultConfig(String name, Class clazz) {
+    public ResultConfig(String name, String clazz) {
         this(name, clazz, new LinkedHashMap());
     }
 
-    public ResultConfig(String name, Class clazz, Map params) {
-        this.name = name;
-        this.className = clazz.getName();
-        this.params = params;
-    }
-
     public ResultConfig(String name, String className, Map params) {
         this.name = name;
         this.className = className;

File src/java/com/opensymphony/xwork2/config/entities/ResultTypeConfig.java

  */
 public class ResultTypeConfig extends Located implements Serializable {
 
-    private Class clazz;
+    private String clazz;
     private String name;
+    private String defaultResultParam;
 
     private Map params;
 
     public ResultTypeConfig() {
     }
 
-    public ResultTypeConfig(String name, Class clazz) {
+    public ResultTypeConfig(String name, String clazz, String defaultResultParam) {
         this.name = name;
         this.clazz = clazz;
+        this.defaultResultParam = defaultResultParam;
     }
 
 
-    public void setClazz(Class clazz) {
+    public void setDefaultResultParam(String defaultResultParam) {
+    	this.defaultResultParam = defaultResultParam;
+    }
+    
+    public String getDefaultResultParam() {
+    	return this.defaultResultParam;
+    }
+    
+    public void setClazz(String clazz) {
         this.clazz = clazz;
     }
 
-    public Class getClazz() {
+    public String getClazz() {
         return clazz;
     }
 

File src/test/com/opensymphony/xwork2/config/providers/MockConfigurationProvider.java

         HashMap results = new HashMap();
         HashMap successParams = new HashMap();
         successParams.put("actionName", "bar");
-        results.put("success", new ResultConfig("success", ActionChainResult.class, successParams));
+        results.put("success", new ResultConfig("success", ActionChainResult.class.getName(), successParams));
 
         ActionConfig fooActionConfig = new ActionConfig(null, SimpleAction.class, params, results, null);
         fooActionConfig.setPackageName("defaultPackage");
         results = new HashMap();
         successParams = new HashMap();
         successParams.put("actionName", "bar");
-        results.put("success", new ResultConfig("success", ActionChainResult.class, successParams));
+        results.put("success", new ResultConfig("success", ActionChainResult.class.getName(), successParams));
 
         List interceptors = new ArrayList();
         interceptors.add(new InterceptorMapping("params", new ParametersInterceptor()));
         results = new HashMap();
         successParams = new HashMap();
         successParams.put("actionName", "bar");
-        results.put("success", new ResultConfig("success", ActionChainResult.class, successParams));
+        results.put("success", new ResultConfig("success", ActionChainResult.class.getName(), successParams));
 
         interceptors = new ArrayList();
         interceptors.add(new InterceptorMapping("static-params", new StaticParametersInterceptor()));

File src/test/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderActionsTest.java

         params = new HashMap();
         params.put("foo", "18");
         params.put("bar", "24");
-        results.put("success", new ResultConfig("success", MockResult.class, new HashMap()));
+        results.put("success", new ResultConfig("success", MockResult.class.getName(), new HashMap()));
 
         InterceptorConfig timerInterceptorConfig = new InterceptorConfig("timer", TimerInterceptor.class, new HashMap());
         interceptors.add(new InterceptorMapping("timer", objectFactory.buildInterceptor(timerInterceptorConfig, new HashMap())));
 
         // wildcard action is simple wildcard example
         results = new HashMap();
-        results.put("*", new ResultConfig("*", MockResult.class, new HashMap()));
+        results.put("*", new ResultConfig("*", MockResult.class.getName(), new HashMap()));
 
         ActionConfig wildcardAction = new ActionConfig(null, SimpleAction.class, new HashMap(), results, interceptors);
 
         params.put("foo", "18");
         params.put("bar", "24");
         results = new HashMap();
-        results.put("success", new ResultConfig("success", MockResult.class, new HashMap()));
+        results.put("success", new ResultConfig("success", MockResult.class.getName(), new HashMap()));
 
         ExceptionMappingConfig exceptionConfig = new ExceptionMappingConfig("runtime", "java.lang.RuntimeException", "exception");
         exceptionMappings.add(exceptionConfig);

File src/test/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderExceptionMappingsTest.java

 
         exceptionMappings.add(new ExceptionMappingConfig("spooky-result", "com.opensymphony.xwork2.SpookyException", "spooky-result"));
 
-        results.put("spooky-result", new ResultConfig("spooky-result", MockResult.class, new HashMap()));
+        results.put("spooky-result", new ResultConfig("spooky-result", MockResult.class.getName(), new HashMap()));
 
         Map resultParams = new HashMap();
         resultParams.put("actionName", "bar.vm");
-        results.put("specificLocationResult", new ResultConfig("specificLocationResult", ActionChainResult.class, resultParams));
+        results.put("specificLocationResult", new ResultConfig("specificLocationResult", ActionChainResult.class.getName(), resultParams));
 
         ActionConfig expectedAction = new ActionConfig(null, SimpleAction.class, parameters, results, new ArrayList(), exceptionMappings);
 

File src/test/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderResultTypesTest.java

 		Map result2ParamsMap = result2ResultTypeConfig.getParams();
 		
 		assertEquals(result1ResultTypeConfig.getName(), "result1");
-		assertEquals(result1ResultTypeConfig.getClazz(), MockResult.class);
+		assertEquals(result1ResultTypeConfig.getClazz(), MockResult.class.getName());
 		assertEquals(result2ResultTypeConfig.getName(), "result2");
-		assertEquals(result2ResultTypeConfig.getClazz(), MockResult.class);
+		assertEquals(result2ResultTypeConfig.getClazz(), MockResult.class.getName());
 		assertEquals(result1ParamsMap.size(), 3);
 		assertEquals(result2ParamsMap.size(), 2);
 		assertTrue(result1ParamsMap.containsKey("param1"));

File src/test/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderResultsTest.java

         HashMap parameters = new HashMap();
         HashMap results = new HashMap();
 
-        results.put("chainDefaultTypedResult", new ResultConfig("chainDefaultTypedResult", ActionChainResult.class, new HashMap()));
+        results.put("chainDefaultTypedResult", new ResultConfig("chainDefaultTypedResult", ActionChainResult.class.getName(), new HashMap()));
 
-        results.put("mockTypedResult", new ResultConfig("mockTypedResult", MockResult.class, new HashMap()));
+        results.put("mockTypedResult", new ResultConfig("mockTypedResult", MockResult.class.getName(), new HashMap()));
 
         Map resultParams = new HashMap();
         resultParams.put("actionName", "bar.vm");
-        results.put("specificLocationResult", new ResultConfig("specificLocationResult", ActionChainResult.class, resultParams));
+        results.put("specificLocationResult", new ResultConfig("specificLocationResult", ActionChainResult.class.getName(), resultParams));
 
         resultParams = new HashMap();
         resultParams.put("actionName", "foo.vm");
-        results.put("defaultLocationResult", new ResultConfig("defaultLocationResult", ActionChainResult.class, resultParams));
+        results.put("defaultLocationResult", new ResultConfig("defaultLocationResult", ActionChainResult.class.getName(), resultParams));
 
         resultParams = new HashMap();
         resultParams.put("foo", "bar");
-        results.put("noDefaultLocationResult", new ResultConfig("noDefaultLocationResult", ActionChainResult.class, resultParams));
+        results.put("noDefaultLocationResult", new ResultConfig("noDefaultLocationResult", ActionChainResult.class.getName(), resultParams));
 
         ActionConfig expectedAction = new ActionConfig(null, SimpleAction.class, parameters, results, new ArrayList());
 
         ConfigurationProvider provider = buildConfigurationProvider(filename);
 
         // setup expectations
-        ResultTypeConfig chainResult = new ResultTypeConfig("chain", ActionChainResult.class);
-        ResultTypeConfig mockResult = new ResultTypeConfig("mock", MockResult.class);
+        ResultTypeConfig chainResult = new ResultTypeConfig("chain", ActionChainResult.class.getName(), null);
+        ResultTypeConfig mockResult = new ResultTypeConfig("mock", MockResult.class.getName(), null);
 
         // execute the configuration
         provider.init(configuration);

File src/test/com/opensymphony/xwork2/spring/ActionsFromSpringTest.java

         String result = action.execute();
         assertEquals(Action.INPUT, result);
     }
+    
+    public void testActionWithSpringResult() throws Exception {
+    	        ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(
+    	        		configurationManager.getConfiguration(), null, "simpleActionSpringResult", null);
+    	                
+    	        proxy.execute();
+    	        
+    	        SpringResult springResult = (SpringResult) proxy.getInvocation().getResult();
+    	        assertTrue(springResult.isInitialize());
+    	        assertNotNull(springResult.getStringParameter());
+    }
 }

File src/test/com/opensymphony/xwork2/spring/SpringResult.java

+package com.opensymphony.xwork2.spring;
+
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.Result;
+
+public class SpringResult implements Result {
+
+	private static final long serialVersionUID = -2877126768401198951L;
+
+	private boolean initialize = false;
+
+	//  this String should be populated by spring
+	private String stringParameter;
+
+	public void initialize() {
+		// this method should be called by spring
+		this.initialize = true;
+	}
+
+	public void execute(ActionInvocation invocation) throws Exception {
+		// intetionally empty
+	}
+
+	public void setStringParameter(String stringParameter) {
+		this.stringParameter = stringParameter;
+	}
+
+	public String getStringParameter() {
+		return this.stringParameter;
+	}
+
+	public boolean isInitialize() {
+		return this.initialize;
+	}
+}
+

File src/test/com/opensymphony/xwork2/spring/actionContext-spring.xml

 		</property>
         <property name="beanNames"><value>auto-proxied-action</value></property>
     </bean>
+    
+    <bean id="springResult" class="com.opensymphony.xwork2.spring.SpringResult"
+		init-method="initialize">
+		<property name="stringParameter" value="my string"/>
+	</bean>
 </beans>

File src/test/com/opensymphony/xwork2/spring/actionContext-xwork.xml

     <package name="default">
         <result-types>
             <result-type name="null" class="com.opensymphony.xwork2.result.NullResult" default="true"/>
+            <result-type name="springResult" class="springResult" />
         </result-types>
 
         <interceptors>
         <action name="proxiedAction" class="proxied-action"/>
 
         <action name="autoProxiedAction" class="auto-proxied-action"/>
+        
+        <action name="simpleActionSpringResult" class="simple-action">
+			<result name="error" type="springResult"/>
+		</action>
     </package>
 </xwork>