Author: jeromy Date: Sun Apr 27 04:43:40 2008 New Revision: 651927 URL: http://svn.apache.org/viewvc?rev=651927&view=rev Log: Fix to codebehind's unknown action handler based on Wes' patch WW-2607
Modified: struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/codebehind/CodebehindUnknownHandler.java struts/struts2/trunk/plugins/codebehind/src/test/java/org/apache/struts2/codebehind/CodebehindUnknownHandlerTest.java Modified: struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/codebehind/CodebehindUnknownHandler.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/codebehind/CodebehindUnknownHandler.java?rev=651927&r1=651926&r2=651927&view=diff ============================================================================== --- struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/codebehind/CodebehindUnknownHandler.java (original) +++ struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/codebehind/CodebehindUnknownHandler.java Sun Apr 27 04:43:40 2008 @@ -41,10 +41,7 @@ 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 @@ 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()) Modified: struts/struts2/trunk/plugins/codebehind/src/test/java/org/apache/struts2/codebehind/CodebehindUnknownHandlerTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/codebehind/src/test/java/org/apache/struts2/codebehind/CodebehindUnknownHandlerTest.java?rev=651927&r1=651926&r2=651927&view=diff ============================================================================== --- struts/struts2/trunk/plugins/codebehind/src/test/java/org/apache/struts2/codebehind/CodebehindUnknownHandlerTest.java (original) +++ struts/struts2/trunk/plugins/codebehind/src/test/java/org/apache/struts2/codebehind/CodebehindUnknownHandlerTest.java Sun Apr 27 04:43:40 2008 @@ -33,12 +33,9 @@ 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 @@ 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;