Fix to codebehind's unknown action handler based on Wes' patch

WW-2607


git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@651927 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jeromy Evans
2008-04-27 11:43:40 +00:00
parent 0a76d80364
commit e9cb4945cf
2 changed files with 34 additions and 12 deletions
@@ -41,10 +41,7 @@ import com.opensymphony.xwork2.UnknownHandler;
import com.opensymphony.xwork2.XWorkException;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationException;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.PackageConfig;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
import com.opensymphony.xwork2.config.entities.*;
import com.opensymphony.xwork2.config.providers.InterceptorBuilder;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.logging.Logger;
@@ -119,10 +116,15 @@ public class CodebehindUnknownHandler implements UnknownHandler {
return actionConfig;
}
/** Create a new ActionConfig in the default package, with the default interceptor stack and a single result */
protected ActionConfig buildActionConfig(String path, String namespace, String actionName, ResultTypeConfig resultTypeConfig) {
PackageConfig pkg = configuration.getPackageConfig(defaultPackageName);
final PackageConfig pkg = configuration.getPackageConfig(defaultPackageName);
return new ActionConfig.Builder(defaultPackageName, "execute", ActionSupport.class.getName())
.addInterceptors(InterceptorBuilder.constructInterceptorReference(pkg, pkg.getFullDefaultInterceptorRef(),
.addInterceptors(InterceptorBuilder.constructInterceptorReference(new InterceptorLocator() {
public Object getInterceptorConfig(String name) {
return pkg.getAllInterceptorConfigs().get(name); // recurse package hiearchy
}
}, pkg.getFullDefaultInterceptorRef(),
Collections.EMPTY_MAP, null, objectFactory))
.addResultConfig(new ResultConfig.Builder(Action.SUCCESS, resultTypeConfig.getClassName())
.addParams(resultTypeConfig.getParams())
@@ -33,12 +33,9 @@ import org.apache.struts2.dispatcher.ServletDispatcherResult;
import com.mockobjects.dynamic.C;
import com.mockobjects.dynamic.Mock;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxyFactory;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.Result;
import com.opensymphony.xwork2.*;
import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.util.XWorkTestCaseHelper;
public class CodebehindUnknownHandlerTest extends StrutsTestCase {
@@ -98,7 +95,30 @@ public class CodebehindUnknownHandlerTest extends StrutsTestCase {
assertTrue(url.toString().endsWith("struts-plugin.xml"));
mockServletContext.verify();
}
/**
* Assert that an unknown action like /foo maps to ActionSupport with a ServletDispatcherResult to /foo.jsp
*/
public void testBuildActionConfigForUnknownAction() throws MalformedURLException {
URL url = new URL("file:/foo.jsp");
mockServletContext.expectAndReturn("getResource", C.args(C.eq("/foo.jsp")), url);
ActionConfig actionConfig = handler.handleUnknownAction("/", "foo");
// we need a package
assertEquals("codebehind-default", actionConfig.getPackageName());
// a non-empty interceptor stack
assertTrue(actionConfig.getInterceptors().size() > 0);
// ActionSupport as the implementation
assertEquals(ActionSupport.class.getName(), actionConfig.getClassName());
// with one result
assertEquals(1, actionConfig.getResults().size());
// named success
assertNotNull(actionConfig.getResults().get("success"));
// of ServletDispatcherResult type
assertEquals(ServletDispatcherResult.class.getName(), actionConfig.getResults().get("success").getClassName());
// and finally pointing to foo.jsp!
assertEquals("/foo.jsp", actionConfig.getResults().get("success").getParams().get("location"));
}
public static class SomeResult implements Result {
public String location;