diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/freemarker/CustomFreemarkerManager.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/freemarker/CustomFreemarkerManager.java index a38a9cdd2..9b712c065 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/freemarker/CustomFreemarkerManager.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/freemarker/CustomFreemarkerManager.java @@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.struts2.views.freemarker.FreemarkerManager; import org.apache.struts2.views.freemarker.ScopesHashModel; -import com.opensymphony.xwork2.util.OgnlValueStack; +import com.opensymphony.xwork2.ognl.OgnlValueStack; import com.opensymphony.xwork2.util.ValueStack; /** diff --git a/apps/showcase/src/main/resources/struts.xml b/apps/showcase/src/main/resources/struts.xml index 9071f4a9b..a4e8f283a 100644 --- a/apps/showcase/src/main/resources/struts.xml +++ b/apps/showcase/src/main/resources/struts.xml @@ -12,6 +12,7 @@ + diff --git a/core/src/main/java/org/apache/struts2/StrutsConstants.java b/core/src/main/java/org/apache/struts2/StrutsConstants.java index e2773b786..c20960e3a 100644 --- a/core/src/main/java/org/apache/struts2/StrutsConstants.java +++ b/core/src/main/java/org/apache/struts2/StrutsConstants.java @@ -165,4 +165,16 @@ public final class StrutsConstants { /** The name of the parameter to determine whether static method access will be allowed in OGNL expressions or not */ public static final String STRUTS_ALLOW_STATIC_METHOD_ACCESS = "struts.ognl.allowStaticMethodAccess"; + /** The com.opensymphony.xwork2.validator.ActionValidatorManager implementation class */ + public static final String STRUTS_ACTIONVALIDATORMANAGER = "struts.actionValidatorManager"; + + /** The {@link com.opensymphony.xwork2.util.ValueStackFactory} implementation class */ + public static final String STRUTS_VALUESTACKFACTORY = "struts.valueStackFactory"; + + /** The {@link com.opensymphony.xwork2.reflection.ReflectionProvider} implementation class */ + public static final String STRUTS_REFLECTIONPROVIDER = "struts.reflectionProvider"; + + /** The {@link com.opensymphony.xwork2.reflection.ReflectionContextFactory} implementation class */ + public static final String STRUTS_REFLECTIONCONTEXTFACTORY = "struts.reflectionContextFactory"; + } diff --git a/core/src/main/java/org/apache/struts2/components/ActionComponent.java b/core/src/main/java/org/apache/struts2/components/ActionComponent.java index 4cead49e4..45feff4cb 100644 --- a/core/src/main/java/org/apache/struts2/components/ActionComponent.java +++ b/core/src/main/java/org/apache/struts2/components/ActionComponent.java @@ -120,6 +120,7 @@ public class ActionComponent extends ContextBean { protected HttpServletResponse res; protected HttpServletRequest req; + protected ValueStackFactory valueStackFactory; protected ActionProxyFactory actionProxyFactory; protected ActionProxy proxy; protected String name; @@ -141,6 +142,11 @@ public class ActionComponent extends ContextBean { public void setActionProxyFactory(ActionProxyFactory actionProxyFactory) { this.actionProxyFactory = actionProxyFactory; } + + @Inject + public void setValueStackFactory(ValueStackFactory valueStackFactory) { + this.valueStackFactory = valueStackFactory; + } public boolean end(Writer writer, String body) { boolean end = super.end(writer, "", false); @@ -192,7 +198,7 @@ public class ActionComponent extends ContextBean { res, servletContext); - ValueStack newStack = ValueStackFactory.getFactory().createValueStack(stack); + ValueStack newStack = valueStackFactory.createValueStack(stack); extraContext.put(ActionContext.VALUE_STACK, newStack); // add page context, such that ServletDispatcherResult will do an include diff --git a/core/src/main/java/org/apache/struts2/components/Bean.java b/core/src/main/java/org/apache/struts2/components/Bean.java index 009fa7131..6f39640a2 100644 --- a/core/src/main/java/org/apache/struts2/components/Bean.java +++ b/core/src/main/java/org/apache/struts2/components/Bean.java @@ -30,8 +30,8 @@ import org.apache.struts2.views.annotations.StrutsTagAttribute; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.ClassLoaderUtil; import com.opensymphony.xwork2.ObjectFactory; -import com.opensymphony.xwork2.util.OgnlUtil; import com.opensymphony.xwork2.util.ValueStack; +import com.opensymphony.xwork2.util.reflection.ReflectionProvider; /** * @@ -101,6 +101,7 @@ public class Bean extends ContextBean { protected Object bean; protected String name; protected ObjectFactory objectFactory; + protected ReflectionProvider reflectionProvider; public Bean(ValueStack stack) { super(stack); @@ -110,6 +111,11 @@ public class Bean extends ContextBean { public void setObjectFactory(ObjectFactory objectFactory) { this.objectFactory = objectFactory; } + + @Inject + public void setReflectionProvider(ReflectionProvider prov) { + this.reflectionProvider = prov; + } public boolean start(Writer writer) { boolean result = super.start(writer); @@ -142,7 +148,7 @@ public class Bean extends ContextBean { } public void addParameter(String key, Object value) { - OgnlUtil.setProperty(key, value, bean, getStack().getContext()); + reflectionProvider.setProperty(key, value, bean, getStack().getContext()); } @StrutsTagAttribute(description="The class name of the bean to be instantiated (must respect JavaBean specification)", diff --git a/core/src/main/java/org/apache/struts2/components/Component.java b/core/src/main/java/org/apache/struts2/components/Component.java index 425f5b5f6..5f0de1b4b 100644 --- a/core/src/main/java/org/apache/struts2/components/Component.java +++ b/core/src/main/java/org/apache/struts2/components/Component.java @@ -342,7 +342,7 @@ public class Component { boolean includeContext, boolean encodeResult, boolean forceAddSchemeHostAndPort, boolean escapeAmp) { String finalAction = findString(action); - String finalMethod = method != null ? findString(method) : method; + String finalMethod = method != null ? findString(method) : method; String finalNamespace = determineNamespace(namespace, getStack(), req); ActionMapping mapping = new ActionMapping(finalAction, finalNamespace, finalMethod, parameters); String uri = actionMapper.getUriFromActionMapping(mapping); diff --git a/core/src/main/java/org/apache/struts2/components/Debug.java b/core/src/main/java/org/apache/struts2/components/Debug.java index 99492df39..fb1d5675a 100644 --- a/core/src/main/java/org/apache/struts2/components/Debug.java +++ b/core/src/main/java/org/apache/struts2/components/Debug.java @@ -20,8 +20,9 @@ */ package org.apache.struts2.components; +import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.ValueStack; -import com.opensymphony.xwork2.util.OgnlUtil; +import com.opensymphony.xwork2.util.reflection.ReflectionProvider; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletRequest; @@ -38,11 +39,20 @@ import org.apache.struts2.StrutsException; description="Prints debugging information") public class Debug extends UIBean { public static final String TEMPLATE = "debug"; + + protected ReflectionProvider reflectionProvider; + + public Debug(ValueStack stack, HttpServletRequest request, HttpServletResponse response) { super(stack, request, response); } + @Inject + public void setReflectionProvider(ReflectionProvider prov) { + this.reflectionProvider = prov; + } + protected String getDefaultTemplate() { return TEMPLATE; } @@ -57,7 +67,7 @@ public class Debug extends UIBean { Object o = iter.next(); Map values; try { - values = OgnlUtil.getBeanMap(o); + values = reflectionProvider.getBeanMap(o); } catch (Exception e) { throw new StrutsException("Caught an exception while getting the property values of " + o, e); } diff --git a/core/src/main/java/org/apache/struts2/components/Form.java b/core/src/main/java/org/apache/struts2/components/Form.java index 4d2706c2c..fdd6829eb 100644 --- a/core/src/main/java/org/apache/struts2/components/Form.java +++ b/core/src/main/java/org/apache/struts2/components/Form.java @@ -28,7 +28,7 @@ import com.opensymphony.xwork2.config.entities.InterceptorMapping; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.interceptor.MethodFilterInterceptorUtil; import com.opensymphony.xwork2.util.ValueStack; -import com.opensymphony.xwork2.validator.ActionValidatorManagerFactory; +import com.opensymphony.xwork2.validator.ActionValidatorManager; import com.opensymphony.xwork2.validator.FieldValidator; import com.opensymphony.xwork2.validator.ValidationInterceptor; import com.opensymphony.xwork2.validator.Validator; @@ -107,6 +107,7 @@ public class Form extends ClosingUIBean { protected Configuration configuration; protected ObjectFactory objectFactory; protected UrlRenderer urlRenderer; + protected ActionValidatorManager actionValidatorManager; public Form(ValueStack stack, HttpServletRequest request, HttpServletResponse response) { super(stack, request, response); @@ -143,6 +144,11 @@ public class Form extends ClosingUIBean { public void setUrlRenderer(UrlRenderer urlRenderer) { this.urlRenderer = urlRenderer; } + + @Inject + public void setActionValidatorManager(ActionValidatorManager mgr) { + this.actionValidatorManager = mgr; + } /* @@ -264,7 +270,7 @@ public class Form extends ClosingUIBean { return Collections.EMPTY_LIST; } - List all = ActionValidatorManagerFactory.getInstance().getValidators(actionClass, (String) getParameters().get("actionName")); + List all = actionValidatorManager.getValidators(actionClass, (String) getParameters().get("actionName")); List validators = new ArrayList(); for (Validator validator : all) { if (validator instanceof FieldValidator) { diff --git a/core/src/main/java/org/apache/struts2/components/Include.java b/core/src/main/java/org/apache/struts2/components/Include.java index 1fde759c8..f3f169827 100644 --- a/core/src/main/java/org/apache/struts2/components/Include.java +++ b/core/src/main/java/org/apache/struts2/components/Include.java @@ -115,7 +115,7 @@ public class Include extends Component { } @Inject(StrutsConstants.STRUTS_I18N_ENCODING) - public static void setDefaultEncoding(String encoding) { + public void setDefaultEncoding(String encoding) { defaultEncoding = encoding; } diff --git a/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java b/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java index 560d5f8f3..e88881643 100644 --- a/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java +++ b/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java @@ -47,7 +47,11 @@ import com.opensymphony.xwork2.inject.Factory; import com.opensymphony.xwork2.inject.Scope; import com.opensymphony.xwork2.util.ClassLoaderUtil; import com.opensymphony.xwork2.util.LocalizedTextUtil; +import com.opensymphony.xwork2.util.ValueStackFactory; import com.opensymphony.xwork2.util.location.LocatableProperties; +import com.opensymphony.xwork2.util.reflection.ReflectionContextFactory; +import com.opensymphony.xwork2.util.reflection.ReflectionProvider; +import com.opensymphony.xwork2.validator.ActionValidatorManager; /** * Selects the implementations of key framework extension points, using the loaded @@ -161,6 +165,10 @@ public class BeanSelectionProvider implements ConfigurationProvider { alias(FreemarkerManager.class, StrutsConstants.STRUTS_FREEMARKER_MANAGER_CLASSNAME, builder, props); alias(VelocityManager.class, StrutsConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME, builder, props); alias(UrlRenderer.class, StrutsConstants.STRUTS_URL_RENDERER, builder, props); + alias(ActionValidatorManager.class, StrutsConstants.STRUTS_ACTIONVALIDATORMANAGER, builder, props); + alias(ValueStackFactory.class, StrutsConstants.STRUTS_VALUESTACKFACTORY, builder, props); + alias(ReflectionProvider.class, StrutsConstants.STRUTS_REFLECTIONPROVIDER, builder, props); + alias(ReflectionContextFactory.class, StrutsConstants.STRUTS_REFLECTIONCONTEXTFACTORY, builder, props); if ("true".equalsIgnoreCase(props.getProperty(StrutsConstants.STRUTS_DEVMODE))) { props.setProperty(StrutsConstants.STRUTS_I18N_RELOAD, "true"); diff --git a/core/src/main/java/org/apache/struts2/config/MethodConfigurationProvider.java b/core/src/main/java/org/apache/struts2/config/MethodConfigurationProvider.java index 64590066c..15f190cbc 100644 --- a/core/src/main/java/org/apache/struts2/config/MethodConfigurationProvider.java +++ b/core/src/main/java/org/apache/struts2/config/MethodConfigurationProvider.java @@ -27,6 +27,7 @@ import com.opensymphony.xwork2.config.RuntimeConfiguration; import com.opensymphony.xwork2.config.entities.ActionConfig; import com.opensymphony.xwork2.config.entities.PackageConfig; import com.opensymphony.xwork2.inject.ContainerBuilder; +import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.location.LocatableProperties; import com.opensymphony.xwork2.ObjectFactory; @@ -141,24 +142,11 @@ public class MethodConfigurationProvider implements ConfigurationProvider { * Updates ObjectFactory property. * @param factory */ + @Inject public void setObjectFactory(ObjectFactory factory) { this.factory = factory; } - /** - * Provides ObjectFactory property. - * @return - * @throws ConfigurationException if ObjectFactory has not been set. - */ - private ObjectFactory getObjectFactory() throws ConfigurationException { - if (factory == null) { - factory = ObjectFactory.getObjectFactory(); - if (factory == null) throw new - ConfigurationException("MethodConfigurationProvider.getObjectFactory: ObjectFactory==null"); - } - return factory; - } - /** * Verifies that character at a String position is upper case. * @param pos Position to test @@ -205,7 +193,6 @@ public class MethodConfigurationProvider implements ConfigurationProvider { String className = actionConfig.getClassName(); Set actionMethods = new HashSet(); Class actionClass; - ObjectFactory factory = getObjectFactory(); try { actionClass = factory.getClassInstance(className); } catch (ClassNotFoundException e) { diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java index 1fddee7d5..712d9cb94 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java @@ -40,7 +40,11 @@ import org.apache.commons.logging.LogFactory; import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsConstants; import org.apache.struts2.StrutsStatics; -import org.apache.struts2.config.*; +import org.apache.struts2.config.BeanSelectionProvider; +import org.apache.struts2.config.ClasspathConfigurationProvider; +import org.apache.struts2.config.DefaultPropertiesProvider; +import org.apache.struts2.config.LegacyPropertiesConfigurationProvider; +import org.apache.struts2.config.StrutsXmlConfigurationProvider; import org.apache.struts2.config.ClasspathConfigurationProvider.ClasspathPageLocator; import org.apache.struts2.config.ClasspathConfigurationProvider.PageLocator; import org.apache.struts2.dispatcher.mapper.ActionMapping; @@ -51,25 +55,26 @@ import org.apache.struts2.util.ClassLoaderUtils; import org.apache.struts2.util.ObjectFactoryDestroyable; import org.apache.struts2.views.freemarker.FreemarkerManager; -import com.opensymphony.xwork2.util.FileManager; -import com.opensymphony.xwork2.*; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionProxy; +import com.opensymphony.xwork2.ActionProxyFactory; +import com.opensymphony.xwork2.ObjectFactory; import com.opensymphony.xwork2.Result; import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.ConfigurationException; import com.opensymphony.xwork2.config.ConfigurationManager; import com.opensymphony.xwork2.config.ConfigurationProvider; import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider; -import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer; -import com.opensymphony.xwork2.conversion.ObjectTypeDeterminerFactory; import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.inject.ContainerBuilder; import com.opensymphony.xwork2.inject.Inject; +import com.opensymphony.xwork2.util.FileManager; import com.opensymphony.xwork2.util.LocalizedTextUtil; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.ValueStackFactory; +import com.opensymphony.xwork2.util.location.LocatableProperties; import com.opensymphony.xwork2.util.location.Location; import com.opensymphony.xwork2.util.location.LocationUtils; -import com.opensymphony.xwork2.util.location.LocatableProperties; import com.opensymphony.xwork2.util.profiling.UtilTimerStack; import freemarker.template.Template; @@ -155,18 +160,6 @@ public class Dispatcher { */ public static void setInstance(Dispatcher instance) { Dispatcher.instance.set(instance); - - // Tie the ObjectFactory threadlocal instance to this Dispatcher instance - if (instance != null) { - Container cont = instance.getContainer(); - if (cont != null) { - ObjectFactory.setObjectFactory(cont.getInstance(ObjectFactory.class)); - } else { - LOG.warn("This dispatcher instance doesn't have a container, so the object factory won't be set."); - } - } else { - ObjectFactory.setObjectFactory(null); - } } /** @@ -190,6 +183,8 @@ public class Dispatcher { private ServletContext servletContext; private Map initParams; + private ValueStackFactory valueStackFactory; + /** * Create the Dispatcher instance for a given ServletContext and set of initialization parameters. @@ -207,7 +202,7 @@ public class Dispatcher { * @param mode New setting */ @Inject(StrutsConstants.STRUTS_DEVMODE) - public static void setDevMode(String mode) { + public void setDevMode(String mode) { devMode = "true".equals(mode); } @@ -216,7 +211,7 @@ public class Dispatcher { * @param val New setting */ @Inject(value=StrutsConstants.STRUTS_LOCALE, required=false) - public static void setDefaultLocale(String val) { + public void setDefaultLocale(String val) { defaultLocale = val; } @@ -225,7 +220,7 @@ public class Dispatcher { * @param val New setting */ @Inject(StrutsConstants.STRUTS_I18N_ENCODING) - public static void setDefaultEncoding(String val) { + public void setDefaultEncoding(String val) { defaultEncoding = val; } @@ -234,9 +229,14 @@ public class Dispatcher { * @param val New setting */ @Inject(StrutsConstants.STRUTS_MULTIPART_SAVEDIR) - public static void setMultipartSaveDir(String val) { + public void setMultipartSaveDir(String val) { multipartSaveDir = val; } + + @Inject + public void setValueStackFactory(ValueStackFactory valueStackFactory) { + this.valueStackFactory = valueStackFactory; + } /** * Releases all instances bound to this dispatcher instance. @@ -392,9 +392,6 @@ Caused by: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyExcepti boolean reloadi18n = Boolean.valueOf(container.getInstance(String.class, StrutsConstants.STRUTS_I18N_RELOAD)); LocalizedTextUtil.setReloadBundles(reloadi18n); - ObjectTypeDeterminer objectTypeDeterminer = container.getInstance(ObjectTypeDeterminer.class); - ObjectTypeDeterminerFactory.setInstance(objectTypeDeterminer); - return container; } @@ -444,6 +441,7 @@ Caused by: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyExcepti init_AliasStandardObjects() ; // [7] Container container = init_PreloadConfiguration(); + container.inject(this); init_CheckConfigurationReloading(container); init_CheckWebLogicWorkaround(container); @@ -474,7 +472,7 @@ Caused by: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyExcepti // If there was a previous value stack, then create a new copy and pass it in to be used by the new Action ValueStack stack = (ValueStack) request.getAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY); if (stack != null) { - extraContext.put(ActionContext.VALUE_STACK, ValueStackFactory.getFactory().createValueStack(stack)); + extraContext.put(ActionContext.VALUE_STACK, valueStackFactory.createValueStack(stack)); } String timerKey = "Handling request from Dispatcher"; diff --git a/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java index 3df75d925..41d7ca0ee 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java @@ -161,22 +161,22 @@ public class FilterDispatcher implements StrutsStatics, Filter { /** * Store state of StrutsConstants.STRUTS_SERVE_STATIC_CONTENT setting. */ - private static boolean serveStatic; + private boolean serveStatic; /** * Store state of StrutsConstants.STRUTS_SERVE_STATIC_BROWSER_CACHE setting. */ - private static boolean serveStaticBrowserCache; + private boolean serveStaticBrowserCache; /** * Store state of StrutsConstants.STRUTS_I18N_ENCODING setting. */ - private static String encoding; + private String encoding; /** * Provide ActionMapper instance, set by injection. */ - private static ActionMapper actionMapper; + private ActionMapper actionMapper; /** * Provide FilterConfig instance, set on init. @@ -199,6 +199,7 @@ public class FilterDispatcher implements StrutsStatics, Filter { dispatcher = createDispatcher(filterConfig); dispatcher.init(); + dispatcher.getContainer().inject(this); String param = filterConfig.getInitParameter("packages"); String packages = "org.apache.struts2.static template org.apache.struts2.interceptor.debugging"; @@ -244,7 +245,7 @@ public class FilterDispatcher implements StrutsStatics, Filter { * @param val New setting */ @Inject(StrutsConstants.STRUTS_SERVE_STATIC_CONTENT) - public static void setServeStaticContent(String val) { + public void setServeStaticContent(String val) { serveStatic = "true".equals(val); } @@ -253,7 +254,7 @@ public class FilterDispatcher implements StrutsStatics, Filter { * @param val New setting */ @Inject(StrutsConstants.STRUTS_SERVE_STATIC_BROWSER_CACHE) - public static void setServeStaticBrowserCache(String val) { + public void setServeStaticBrowserCache(String val) { serveStaticBrowserCache = "true".equals(val); } @@ -262,7 +263,7 @@ public class FilterDispatcher implements StrutsStatics, Filter { * @param val New setting */ @Inject(StrutsConstants.STRUTS_I18N_ENCODING) - public static void setEncoding(String val) { + public void setEncoding(String val) { encoding = val; } @@ -271,7 +272,7 @@ public class FilterDispatcher implements StrutsStatics, Filter { * @param mapper New instance */ @Inject - public static void setActionMapper(ActionMapper mapper) { + public void setActionMapper(ActionMapper mapper) { actionMapper = mapper; } diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ServletActionRedirectResult.java b/core/src/main/java/org/apache/struts2/dispatcher/ServletActionRedirectResult.java index e840b5230..d009a62ed 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/ServletActionRedirectResult.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/ServletActionRedirectResult.java @@ -27,6 +27,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.struts2.dispatcher.mapper.ActionMapper; import org.apache.struts2.dispatcher.mapper.ActionMapping; import org.apache.struts2.views.util.UrlHelper; @@ -34,6 +36,8 @@ import org.apache.struts2.views.util.UrlHelper; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.config.entities.ResultConfig; import com.opensymphony.xwork2.inject.Inject; +import com.opensymphony.xwork2.util.reflection.ReflectionException; +import com.opensymphony.xwork2.util.reflection.ReflectionExceptionHandler; /** * @@ -111,12 +115,14 @@ import com.opensymphony.xwork2.inject.Inject; * * @see ActionMapper */ -public class ServletActionRedirectResult extends ServletRedirectResult { +public class ServletActionRedirectResult extends ServletRedirectResult implements ReflectionExceptionHandler { private static final long serialVersionUID = -9042425229314584066L; /** The default parameter */ public static final String DEFAULT_PARAM = "actionName"; + + private static final Log LOG = LogFactory.getLog(ServletActionRedirectResult.class); protected String actionName; protected String namespace; @@ -225,4 +231,9 @@ public class ServletActionRedirectResult extends ServletRedirectResult { return this; } + public void handle(ReflectionException ex) { + // Only log as debug as they are probably parameters to be appended to the url + LOG.debug(ex.getMessage(), ex); + } + } diff --git a/core/src/main/java/org/apache/struts2/impl/StrutsActionProxy.java b/core/src/main/java/org/apache/struts2/impl/StrutsActionProxy.java index 252b368ae..101953a51 100644 --- a/core/src/main/java/org/apache/struts2/impl/StrutsActionProxy.java +++ b/core/src/main/java/org/apache/struts2/impl/StrutsActionProxy.java @@ -23,6 +23,7 @@ package org.apache.struts2.impl; import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.DefaultActionProxy; import java.util.Map; @@ -31,9 +32,9 @@ public class StrutsActionProxy extends DefaultActionProxy { private static final long serialVersionUID = -2434901249671934080L; - public StrutsActionProxy(String namespace, String actionName, Map extraContext, + public StrutsActionProxy(ActionInvocation inv, String namespace, String actionName, Map extraContext, boolean executeResult, boolean cleanupContext) throws Exception { - super(namespace, actionName, extraContext, executeResult, cleanupContext); + super(inv, namespace, actionName, extraContext, executeResult, cleanupContext); } public String execute() throws Exception { diff --git a/core/src/main/java/org/apache/struts2/impl/StrutsActionProxyFactory.java b/core/src/main/java/org/apache/struts2/impl/StrutsActionProxyFactory.java index ea821722b..566cad54e 100644 --- a/core/src/main/java/org/apache/struts2/impl/StrutsActionProxyFactory.java +++ b/core/src/main/java/org/apache/struts2/impl/StrutsActionProxyFactory.java @@ -24,19 +24,17 @@ package org.apache.struts2.impl; import java.util.Map; +import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.ActionProxy; +import com.opensymphony.xwork2.DefaultActionInvocation; +import com.opensymphony.xwork2.DefaultActionProxy; import com.opensymphony.xwork2.DefaultActionProxyFactory; public class StrutsActionProxyFactory extends DefaultActionProxyFactory { - public ActionProxy createActionProxy(String namespace, String actionName, Map extraContext) - throws Exception { - return createActionProxy(namespace, actionName, extraContext, true, true); - } - - public ActionProxy createActionProxy(String namespace, String actionName, Map extraContext, - boolean executeResult, boolean cleanupContext) throws Exception { - ActionProxy proxy = new StrutsActionProxy(namespace, actionName, extraContext, executeResult, cleanupContext); + public ActionProxy createActionProxy(ActionInvocation inv, String namespace, String actionName, Map extraContext, boolean executeResult, boolean cleanupContext) throws Exception { + + ActionProxy proxy = new StrutsActionProxy(inv, namespace, actionName, extraContext, executeResult, cleanupContext); container.inject(proxy); proxy.prepare(); return proxy; diff --git a/core/src/main/java/org/apache/struts2/impl/StrutsObjectFactory.java b/core/src/main/java/org/apache/struts2/impl/StrutsObjectFactory.java index 9ffb6456f..e4642a635 100644 --- a/core/src/main/java/org/apache/struts2/impl/StrutsObjectFactory.java +++ b/core/src/main/java/org/apache/struts2/impl/StrutsObjectFactory.java @@ -28,7 +28,6 @@ import com.opensymphony.xwork2.config.ConfigurationException; import com.opensymphony.xwork2.config.entities.InterceptorConfig; import com.opensymphony.xwork2.config.entities.ResultConfig; import com.opensymphony.xwork2.interceptor.Interceptor; -import com.opensymphony.xwork2.util.OgnlUtil; import java.util.HashMap; import java.util.Map; @@ -51,7 +50,7 @@ public class StrutsObjectFactory extends ObjectFactory { // interceptor instances are long-lived and used across user sessions, so don't try to pass in any extra // context Object o = buildBean(className, null); - OgnlUtil.setProperties(params, o); + reflectionProvider.setProperties(params, o); if (o instanceof Interceptor) { Interceptor interceptor = (Interceptor) o; @@ -92,7 +91,7 @@ public class StrutsObjectFactory extends ObjectFactory { return null; Object result = buildBean(resultClassName, extraContext); - OgnlUtil.setProperties(resultConfig.getParams(), result, extraContext); + reflectionProvider.setProperties(resultConfig.getParams(), result, extraContext); if (result instanceof Result) return (Result) result; diff --git a/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java index 826b58236..36a74b592 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java @@ -50,6 +50,7 @@ import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.interceptor.Interceptor; import com.opensymphony.xwork2.interceptor.PreResultListener; import com.opensymphony.xwork2.util.ValueStack; +import com.opensymphony.xwork2.util.reflection.ReflectionProvider; /** * @@ -116,6 +117,7 @@ public class DebuggingInterceptor implements Interceptor { private FreemarkerManager freemarkerManager; private boolean consoleEnabled = false; + private ReflectionProvider reflectionProvider; @Inject(StrutsConstants.STRUTS_DEVMODE) public void setDevMode(String mode) { @@ -126,6 +128,11 @@ public class DebuggingInterceptor implements Interceptor { public void setFreemarkerManager(FreemarkerManager mgr) { this.freemarkerManager = mgr; } + + @Inject + public void setReflectionProvider(ReflectionProvider reflectionProvider) { + this.reflectionProvider = reflectionProvider; + } /** * Unused. @@ -226,7 +233,7 @@ public class DebuggingInterceptor implements Interceptor { try { StringWriter writer = new StringWriter(); ObjectToHTMLWriter htmlWriter = new ObjectToHTMLWriter(writer); - htmlWriter.write(rootObject, rootObjectExpression); + htmlWriter.write(reflectionProvider, rootObject, rootObjectExpression); String html = writer.toString(); writer.close(); diff --git a/core/src/main/java/org/apache/struts2/interceptor/debugging/ObjectToHTMLWriter.java b/core/src/main/java/org/apache/struts2/interceptor/debugging/ObjectToHTMLWriter.java index aae5ba830..205db7a0c 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/debugging/ObjectToHTMLWriter.java +++ b/core/src/main/java/org/apache/struts2/interceptor/debugging/ObjectToHTMLWriter.java @@ -28,9 +28,8 @@ import java.util.List; import java.util.Map; import java.util.Set; -import ognl.OgnlException; - -import com.opensymphony.xwork2.util.OgnlUtil; +import com.opensymphony.xwork2.util.reflection.ReflectionException; +import com.opensymphony.xwork2.util.reflection.ReflectionProvider; /** * Writes an object as a table, where each field can be expanded if it is an Object/Collection/Array @@ -45,8 +44,8 @@ class ObjectToHTMLWriter { } @SuppressWarnings("unchecked") - public void write(Object root, String expr) throws IntrospectionException, - OgnlException { + public void write(ReflectionProvider reflectionProvider, Object root, String expr) throws IntrospectionException, + ReflectionException { prettyWriter.startNode("table"); prettyWriter.addAttribute("class", "debugTable"); @@ -76,7 +75,7 @@ class ObjectToHTMLWriter { } } else { //print properties - Map properties = OgnlUtil.getBeanMap(root); + Map properties = reflectionProvider.getBeanMap(root); for (Map.Entry property : properties.entrySet()) { String name = property.getKey(); Object value = property.getValue(); diff --git a/core/src/main/java/org/apache/struts2/util/Sorter.java b/core/src/main/java/org/apache/struts2/util/Sorter.java deleted file mode 100644 index d6bb88c08..000000000 --- a/core/src/main/java/org/apache/struts2/util/Sorter.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * $Id$ - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.struts2.util; - -import java.util.Comparator; - -import com.opensymphony.xwork2.util.ValueStack; -import com.opensymphony.xwork2.util.ValueStackFactory; - - -/** - * Sorters. Utility sorters for use with the "sort" tag. - * - * @see org.apache.struts2.views.jsp.iterator.SortIteratorTag - * @see SortIteratorFilter - */ -public class Sorter { - - public Comparator getAscending() { - return new Comparator() { - public int compare(Object o1, Object o2) { - if (o1 instanceof Comparable) { - return ((Comparable) o1).compareTo(o2); - } else { - String s1 = o1.toString(); - String s2 = o2.toString(); - - return s1.compareTo(s2); - } - } - }; - } - - public Comparator getAscending(final String anExpression) { - return new Comparator() { - private ValueStack stack = ValueStackFactory.getFactory().createValueStack(); - - public int compare(Object o1, Object o2) { - // Get value for first object - stack.push(o1); - - Object v1 = stack.findValue(anExpression); - stack.pop(); - - // Get value for second object - stack.push(o2); - - Object v2 = stack.findValue(anExpression); - stack.pop(); - - // Ensure non-null - if (v1 == null) { - v1 = ""; - } - - if (v2 == null) { - v2 = ""; - } - - // Compare them - if (v1 instanceof Comparable && v1.getClass().equals(v2.getClass())) { - return ((Comparable) v1).compareTo(v2); - } else { - String s1 = v1.toString(); - String s2 = v2.toString(); - - return s1.compareTo(s2); - } - } - }; - } - - public Comparator getComparator(String anExpression, boolean ascending) { - if (ascending) { - return getAscending(anExpression); - } else { - return getDescending(anExpression); - } - } - - public Comparator getDescending() { - return new Comparator() { - public int compare(Object o1, Object o2) { - if (o2 instanceof Comparable) { - return ((Comparable) o2).compareTo(o1); - } else { - String s1 = o1.toString(); - String s2 = o2.toString(); - - return s2.compareTo(s1); - } - } - }; - } - - public Comparator getDescending(final String anExpression) { - return new Comparator() { - private ValueStack stack = ValueStackFactory.getFactory().createValueStack(); - - public int compare(Object o1, Object o2) { - // Get value for first object - stack.push(o1); - - Object v1 = stack.findValue(anExpression); - stack.pop(); - - // Get value for second object - stack.push(o2); - - Object v2 = stack.findValue(anExpression); - stack.pop(); - - // Ensure non-null - if (v1 == null) { - v1 = ""; - } - - if (v2 == null) { - v2 = ""; - } - - // Compare them - if (v2 instanceof Comparable && v1.getClass().equals(v2.getClass())) { - return ((Comparable) v2).compareTo(v1); - } else { - String s1 = v1.toString(); - String s2 = v2.toString(); - - return s2.compareTo(s1); - } - } - }; - } -} diff --git a/core/src/main/java/org/apache/struts2/util/StrutsTestCaseHelper.java b/core/src/main/java/org/apache/struts2/util/StrutsTestCaseHelper.java index 29e926edb..4d62bea5e 100644 --- a/core/src/main/java/org/apache/struts2/util/StrutsTestCaseHelper.java +++ b/core/src/main/java/org/apache/struts2/util/StrutsTestCaseHelper.java @@ -26,7 +26,10 @@ import java.util.Map; import org.apache.struts2.dispatcher.Dispatcher; import org.springframework.mock.web.MockServletContext; +import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.util.LocalizedTextUtil; +import com.opensymphony.xwork2.util.ValueStack; +import com.opensymphony.xwork2.util.ValueStackFactory; /** * Generic test setup methods to be used with any unit testing framework. @@ -48,10 +51,17 @@ public class StrutsTestCaseHelper { Dispatcher du = new Dispatcher(new MockServletContext(), params); du.init(); Dispatcher.setInstance(du); + + // Reset the value stack + ValueStack stack = du.getContainer().getInstance(ValueStackFactory.class).createValueStack(); + stack.getContext().put(ActionContext.CONTAINER, du.getContainer()); + ActionContext.setContext(new ActionContext(stack.getContext())); + return du; } public static void tearDown() throws Exception { Dispatcher.setInstance(null); + ActionContext.setContext(null); } } diff --git a/core/src/main/java/org/apache/struts2/util/StrutsUtil.java b/core/src/main/java/org/apache/struts2/util/StrutsUtil.java index 5d0273b81..2aef5daaa 100644 --- a/core/src/main/java/org/apache/struts2/util/StrutsUtil.java +++ b/core/src/main/java/org/apache/struts2/util/StrutsUtil.java @@ -44,8 +44,10 @@ import org.apache.commons.logging.LogFactory; import org.apache.struts2.views.jsp.ui.OgnlTool; import org.apache.struts2.views.util.UrlHelper; +import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.util.TextUtils; import com.opensymphony.xwork2.util.ValueStack; +import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ObjectFactory; @@ -61,7 +63,7 @@ public class StrutsUtil { protected HttpServletRequest request; protected HttpServletResponse response; protected Map classes = new Hashtable(); - protected OgnlTool ognl = OgnlTool.getInstance(); + protected OgnlTool ognl; protected ValueStack stack; @@ -69,6 +71,7 @@ public class StrutsUtil { this.stack = stack; this.request = request; this.response = response; + this.ognl = ((Container)stack.getContext().get(ActionContext.CONTAINER)).getInstance(OgnlTool.class); } diff --git a/core/src/main/java/org/apache/struts2/validators/DWRValidator.java b/core/src/main/java/org/apache/struts2/validators/DWRValidator.java index cb2a81de5..7281ee5f0 100644 --- a/core/src/main/java/org/apache/struts2/validators/DWRValidator.java +++ b/core/src/main/java/org/apache/struts2/validators/DWRValidator.java @@ -37,7 +37,9 @@ import org.apache.struts2.dispatcher.SessionMap; import uk.ltd.getahead.dwr.WebContextFactory; import com.opensymphony.xwork2.Action; +import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.ActionProxy; +import com.opensymphony.xwork2.ActionProxyFactory; import com.opensymphony.xwork2.DefaultActionInvocation; import com.opensymphony.xwork2.DefaultActionProxy; import com.opensymphony.xwork2.ObjectFactory; @@ -46,6 +48,7 @@ import com.opensymphony.xwork2.ValidationAware; import com.opensymphony.xwork2.ValidationAwareSupport; import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.entities.ActionConfig; +import com.opensymphony.xwork2.inject.Inject; /** *

@@ -66,6 +69,13 @@ import com.opensymphony.xwork2.config.entities.ActionConfig; */ public class DWRValidator { private static final Log LOG = LogFactory.getLog(DWRValidator.class); + + private ActionProxyFactory actionProxyFactory; + + @Inject + public void setActionProxyFactory(ActionProxyFactory fac) { + this.actionProxyFactory = fac; + } public ValidationAwareSupport doPost(String namespace, String action, Map params) throws Exception { HttpServletRequest req = WebContextFactory.get().getHttpServletRequest(); @@ -92,9 +102,8 @@ public class DWRValidator { try { Configuration cfg = du.getConfigurationManager().getConfiguration(); - ValidatorActionProxy proxy = new ValidatorActionProxy(namespace, action, ctx); - cfg.getContainer().inject(proxy); - proxy.prepare(); + ActionInvocation inv = new ValidatorActionInvocation(ctx, true); + ActionProxy proxy = actionProxyFactory.createActionProxy(inv, namespace, action, ctx, true, true); proxy.execute(); Object a = proxy.getAction(); @@ -118,8 +127,8 @@ public class DWRValidator { public static class ValidatorActionInvocation extends DefaultActionInvocation { private static final long serialVersionUID = -7645433725470191275L; - protected ValidatorActionInvocation(ObjectFactory objectFactory, UnknownHandler handler, ActionProxy proxy, Map extraContext) throws Exception { - super(objectFactory, handler, proxy, extraContext, true); + protected ValidatorActionInvocation(Map extraContext, boolean pushAction) throws Exception { + super(extraContext, pushAction); } protected String invokeAction(Object action, ActionConfig actionConfig) throws Exception { @@ -127,16 +136,4 @@ public class DWRValidator { } } - public static class ValidatorActionProxy extends DefaultActionProxy { - private static final long serialVersionUID = 5754781916414047963L; - - protected ValidatorActionProxy(String namespace, String actionName, Map extraContext) throws Exception { - super(namespace, actionName, extraContext, false, true); - } - - public void prepare() throws Exception { - super.prepare(); - invocation = new ValidatorActionInvocation(objectFactory, unknownHandler, this, extraContext); - } - } } diff --git a/core/src/main/java/org/apache/struts2/views/jsp/TagUtils.java b/core/src/main/java/org/apache/struts2/views/jsp/TagUtils.java index 5d1a12367..556f339f9 100644 --- a/core/src/main/java/org/apache/struts2/views/jsp/TagUtils.java +++ b/core/src/main/java/org/apache/struts2/views/jsp/TagUtils.java @@ -52,7 +52,7 @@ public class TagUtils { ValueStack stack = (ValueStack) req.getAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY); if (stack == null) { - stack = ValueStackFactory.getFactory().createValueStack(); + stack = Dispatcher.getInstance().getContainer().getInstance(ValueStackFactory.class).createValueStack(); HttpServletResponse res = (HttpServletResponse) pageContext.getResponse(); Dispatcher du = Dispatcher.getInstance(); diff --git a/core/src/main/java/org/apache/struts2/views/jsp/ui/OgnlTool.java b/core/src/main/java/org/apache/struts2/views/jsp/ui/OgnlTool.java index 64f0d31be..6fbfc10f3 100644 --- a/core/src/main/java/org/apache/struts2/views/jsp/ui/OgnlTool.java +++ b/core/src/main/java/org/apache/struts2/views/jsp/ui/OgnlTool.java @@ -23,24 +23,30 @@ package org.apache.struts2.views.jsp.ui; import ognl.Ognl; import ognl.OgnlException; -import com.opensymphony.xwork2.util.OgnlUtil; +import com.opensymphony.xwork2.inject.Inject; +import com.opensymphony.xwork2.ognl.OgnlUtil; /** */ public class OgnlTool { - private static OgnlTool instance = new OgnlTool(); - private OgnlTool() { + private OgnlUtil ognlUtil; + + public OgnlTool() { } + + @Inject + public void setOgnlUtil(OgnlUtil ognlUtil) { + this.ognlUtil = ognlUtil; + } + + - public static OgnlTool getInstance() { - return instance; - } public Object findValue(String expr, Object context) { try { - return Ognl.getValue(OgnlUtil.compile(expr), context); + return Ognl.getValue(ognlUtil.compile(expr), context); } catch (OgnlException e) { return null; } diff --git a/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java b/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java index 3ad854d43..577a390e5 100644 --- a/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java +++ b/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java @@ -32,6 +32,8 @@ import org.apache.struts2.views.jsp.ui.OgnlTool; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.conversion.impl.XWorkConverter; +import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.ValueStack; @@ -51,13 +53,6 @@ public class ContextUtil { public static final String STRUTS = "struts"; public static final String ACTION = "action"; - public static boolean altSyntax; - - @Inject(StrutsConstants.STRUTS_TAG_ALTSYNTAX) - public static void setAltSyntax(String val) { - altSyntax = "true".equals(val); - } - public static Map getStandardContext(ValueStack stack, HttpServletRequest req, HttpServletResponse res) { HashMap map = new HashMap(); map.put(REQUEST, req); @@ -67,7 +62,7 @@ public class ContextUtil { map.put(SESSION, req.getSession(false)); map.put(BASE, req.getContextPath()); map.put(STACK, stack); - map.put(OGNL, OgnlTool.getInstance()); + map.put(OGNL, ((Container)stack.getContext().get(ActionContext.CONTAINER)).getInstance(OgnlTool.class)); map.put(STRUTS, new StrutsUtil(stack, req, res)); ActionInvocation invocation = (ActionInvocation) stack.getContext().get(ActionContext.ACTION_INVOCATION); @@ -86,12 +81,12 @@ public class ContextUtil { // We didn't make altSyntax static cause, if so, struts.configuration.xml.reload will not work // plus the Configuration implementation should cache the properties, which the framework's // configuration implementation does - return altSyntax ||( + return "true".equals(((Container)context.get(ActionContext.CONTAINER)).getInstance(String.class, StrutsConstants.STRUTS_TAG_ALTSYNTAX)) ||( (context.containsKey("useAltSyntax") && context.get("useAltSyntax") != null && "true".equals(context.get("useAltSyntax").toString()))); } - + /** * Returns a String for overriding the default templateSuffix if templateSuffix is on the stack * @param context stack's context diff --git a/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java b/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java index 529108f1d..e617e96bd 100644 --- a/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java +++ b/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java @@ -38,6 +38,8 @@ import org.apache.commons.logging.LogFactory; import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsConstants; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.TextParseUtil; import com.opensymphony.xwork2.util.ValueStack; @@ -62,25 +64,6 @@ public class UrlHelper { private static final String AMP = "&"; - private static int httpPort = DEFAULT_HTTP_PORT; - private static int httpsPort = DEFAULT_HTTPS_PORT; - private static String customEncoding; - - @Inject(StrutsConstants.STRUTS_URL_HTTP_PORT) - public static void setHttpPort(String val) { - httpPort = Integer.parseInt(val); - } - - @Inject(StrutsConstants.STRUTS_URL_HTTPS_PORT) - public static void setHttpsPort(String val) { - httpsPort = Integer.parseInt(val); - } - - @Inject(StrutsConstants.STRUTS_I18N_ENCODING) - public static void setCustomEncoding(String val) { - customEncoding = val; - } - public static String buildUrl(String action, HttpServletRequest request, HttpServletResponse response, Map params) { return buildUrl(action, request, response, params, null, true, true); } @@ -97,6 +80,11 @@ public class UrlHelper { StringBuffer link = new StringBuffer(); boolean changedScheme = false; + + // FIXME: temporary hack until class is made a properly injected bean + Container cont = ActionContext.getContext().getContainer(); + int httpPort = Integer.parseInt(cont.getInstance(String.class, StrutsConstants.STRUTS_URL_HTTP_PORT)); + int httpsPort = Integer.parseInt(cont.getInstance(String.class, StrutsConstants.STRUTS_URL_HTTPS_PORT)); // only append scheme if it is different to the current scheme *OR* // if we explicity want it to be appended by having forceAddSchemeHostAndPort = true @@ -301,6 +289,11 @@ public class UrlHelper { private static String getEncodingFromConfiguration() { final String encoding; + + // FIXME: temporary hack until class is made a properly injected bean + Container cont = ActionContext.getContext().getContainer(); + String customEncoding = cont.getInstance(String.class, StrutsConstants.STRUTS_I18N_ENCODING); + if (customEncoding != null) { encoding = customEncoding; } else { diff --git a/core/src/main/resources/struts-default.xml b/core/src/main/resources/struts-default.xml index a2b9585eb..983c9da02 100644 --- a/core/src/main/resources/struts-default.xml +++ b/core/src/main/resources/struts-default.xml @@ -57,22 +57,45 @@ + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/src/test/java/org/apache/struts2/components/FormButtonTest.java b/core/src/test/java/org/apache/struts2/components/FormButtonTest.java index 5dde9fef4..af4fd0891 100644 --- a/core/src/test/java/org/apache/struts2/components/FormButtonTest.java +++ b/core/src/test/java/org/apache/struts2/components/FormButtonTest.java @@ -24,6 +24,7 @@ import org.apache.struts2.StrutsTestCase; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; +import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.ValueStackFactory; @@ -36,7 +37,7 @@ public class FormButtonTest extends StrutsTestCase { public void testPopulateComponentHtmlId1() throws Exception { MockHttpServletRequest req = new MockHttpServletRequest(); MockHttpServletResponse res = new MockHttpServletResponse(); - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); Form form = new Form(stack, req, res); form.getParameters().put("id", "formId"); @@ -52,7 +53,7 @@ public class FormButtonTest extends StrutsTestCase { public void testPopulateComponentHtmlId2() throws Exception { MockHttpServletRequest req = new MockHttpServletRequest(); MockHttpServletResponse res = new MockHttpServletResponse(); - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); Form form = new Form(stack, req, res); form.getParameters().put("id", "formId"); @@ -68,7 +69,7 @@ public class FormButtonTest extends StrutsTestCase { public void testPopulateComponentHtmlId3() throws Exception { MockHttpServletRequest req = new MockHttpServletRequest(); MockHttpServletResponse res = new MockHttpServletResponse(); - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); Form form = new Form(stack, req, res); form.getParameters().put("id", "formId"); @@ -85,7 +86,7 @@ public class FormButtonTest extends StrutsTestCase { public void testPopulateComponentHtmlId4() throws Exception { MockHttpServletRequest req = new MockHttpServletRequest(); MockHttpServletResponse res = new MockHttpServletResponse(); - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); Submit submit = new Submit(stack, req, res); submit.setId("submitId"); @@ -98,7 +99,7 @@ public class FormButtonTest extends StrutsTestCase { public void testPopulateComponentHtmlId5() throws Exception { MockHttpServletRequest req = new MockHttpServletRequest(); MockHttpServletResponse res = new MockHttpServletResponse(); - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); Submit submit = new Submit(stack, req, res); submit.setName("submitName"); @@ -111,7 +112,7 @@ public class FormButtonTest extends StrutsTestCase { public void testPopulateComponentHtmlId6() throws Exception { MockHttpServletRequest req = new MockHttpServletRequest(); MockHttpServletResponse res = new MockHttpServletResponse(); - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); Submit submit = new Submit(stack, req, res); submit.setAction("submitAction"); diff --git a/core/src/test/java/org/apache/struts2/components/FormTest.java b/core/src/test/java/org/apache/struts2/components/FormTest.java index 95e50010a..f8a05de4f 100644 --- a/core/src/test/java/org/apache/struts2/components/FormTest.java +++ b/core/src/test/java/org/apache/struts2/components/FormTest.java @@ -36,6 +36,7 @@ public class FormTest extends AbstractUITagTest { public void testTestFormGetValidators() { Form form = new Form(stack, request, response); + container.inject(form); form.getParameters().put("actionClass", TestAction.class); List v = form.getValidators("foo"); assertEquals(1, v.size()); diff --git a/core/src/test/java/org/apache/struts2/components/PropertyTest.java b/core/src/test/java/org/apache/struts2/components/PropertyTest.java index 32cc69167..1de88e09e 100644 --- a/core/src/test/java/org/apache/struts2/components/PropertyTest.java +++ b/core/src/test/java/org/apache/struts2/components/PropertyTest.java @@ -26,8 +26,10 @@ import java.util.Map; import junit.framework.TestCase; import ognl.Ognl; +import org.apache.struts2.StrutsTestCase; import org.apache.struts2.util.StrutsTypeConverter; +import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.conversion.impl.XWorkConverter; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.ValueStackFactory; @@ -35,9 +37,9 @@ import com.opensymphony.xwork2.util.ValueStackFactory; /** * */ -public class PropertyTest extends TestCase { +public class PropertyTest extends StrutsTestCase { public void testNormalBehaviour() { - final ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + final ValueStack stack = ActionContext.getContext().getValueStack(); stack.push(new FooBar("foo-value", "bar-value")); final Property property = new Property(stack); property.setDefault("default"); @@ -46,7 +48,7 @@ public class PropertyTest extends TestCase { } public void testDefaultShouldBeOutputIfBeanNotAvailable() { - final ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + final ValueStack stack = ActionContext.getContext().getValueStack(); final Property property = new Property(stack); property.setDefault("default"); property.setValue("foo"); @@ -54,7 +56,7 @@ public class PropertyTest extends TestCase { } public void testDefaultShouldBeOutputIfPropertyIsNull() { - final ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + final ValueStack stack = ActionContext.getContext().getValueStack(); stack.push(new FooBar(null, "bar-value")); final Property property = new Property(stack); property.setDefault("default"); @@ -63,7 +65,7 @@ public class PropertyTest extends TestCase { } public void testTopValueShouldReturnTopOfValueStack() { - final ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + final ValueStack stack = ActionContext.getContext().getValueStack(); stack.push(new FooBar("foo-value", "bar-value")); final Property property = new Property(stack); property.setDefault("default"); @@ -72,7 +74,7 @@ public class PropertyTest extends TestCase { } public void testTypeConverterShouldBeUsed() { - final ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + final ValueStack stack = ActionContext.getContext().getValueStack(); Ognl.setTypeConverter(stack.getContext(), new TestDefaultConverter()); stack.push(new FooBar("foo-value", "bar-value")); @@ -83,7 +85,7 @@ public class PropertyTest extends TestCase { } public void testTypeConverterReturningNullShouldLeadToDisplayOfDefaultValue() { - final ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + final ValueStack stack = ActionContext.getContext().getValueStack(); Ognl.setTypeConverter(stack.getContext(), new TestDefaultConverter()); stack.push(new FooBar("foo-value", null)); diff --git a/core/src/test/java/org/apache/struts2/components/UIBeanTest.java b/core/src/test/java/org/apache/struts2/components/UIBeanTest.java index cf380a698..2924224df 100644 --- a/core/src/test/java/org/apache/struts2/components/UIBeanTest.java +++ b/core/src/test/java/org/apache/struts2/components/UIBeanTest.java @@ -24,6 +24,7 @@ import org.apache.struts2.StrutsTestCase; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; +import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.ValueStackFactory; @@ -34,7 +35,7 @@ import com.opensymphony.xwork2.util.ValueStackFactory; public class UIBeanTest extends StrutsTestCase { public void testPopulateComponentHtmlId1() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); MockHttpServletRequest req = new MockHttpServletRequest(); MockHttpServletResponse res = new MockHttpServletResponse(); @@ -50,7 +51,7 @@ public class UIBeanTest extends StrutsTestCase { } public void testPopulateComponentHtmlIdWithOgnl() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); MockHttpServletRequest req = new MockHttpServletRequest(); MockHttpServletResponse res = new MockHttpServletResponse(); @@ -66,7 +67,7 @@ public class UIBeanTest extends StrutsTestCase { } public void testPopulateComponentHtmlId2() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); MockHttpServletRequest req = new MockHttpServletRequest(); MockHttpServletResponse res = new MockHttpServletResponse(); diff --git a/core/src/test/java/org/apache/struts2/config/MethodConfigurationProviderTest.java b/core/src/test/java/org/apache/struts2/config/MethodConfigurationProviderTest.java index 8a426c14e..f04dd21fc 100644 --- a/core/src/test/java/org/apache/struts2/config/MethodConfigurationProviderTest.java +++ b/core/src/test/java/org/apache/struts2/config/MethodConfigurationProviderTest.java @@ -29,6 +29,7 @@ import com.opensymphony.xwork2.config.ConfigurationManager; import com.opensymphony.xwork2.config.entities.*; import com.opensymphony.xwork2.config.impl.DefaultConfiguration; import com.opensymphony.xwork2.ActionSupport; +import com.opensymphony.xwork2.ObjectFactory; import junit.framework.TestCase; @@ -61,7 +62,6 @@ public class MethodConfigurationProviderTest extends TestCase { * Creates a mock Dispatcher and seeds Configuration. */ public void setUp() { - InternalConfigurationManager configurationManager = new InternalConfigurationManager(); dispatcher = new Dispatcher(new MockServletContext(), new HashMap()); dispatcher.setConfigurationManager(configurationManager); @@ -93,6 +93,7 @@ public class MethodConfigurationProviderTest extends TestCase { provider = new MethodConfigurationProvider(); provider.init(configuration); + provider.setObjectFactory(new ObjectFactory()); provider.loadPackages(); } diff --git a/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java b/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java index 8b116ee87..ab886ae8b 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java @@ -23,16 +23,31 @@ package org.apache.struts2.dispatcher; import java.util.HashMap; import java.util.Locale; +import javax.servlet.FilterConfig; +import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.StrutsConstants; import org.apache.struts2.StrutsTestCase; +import org.apache.struts2.dispatcher.FilterDispatcherTest.InnerActionMapper; +import org.apache.struts2.dispatcher.FilterDispatcherTest.InnerDestroyableObjectFactory; +import org.apache.struts2.dispatcher.FilterDispatcherTest.InnerDispatcher; +import org.springframework.mock.web.MockFilterConfig; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockServletContext; +import com.mockobjects.dynamic.C; +import com.mockobjects.dynamic.Mock; +import com.mockobjects.servlet.MockFilterChain; +import com.opensymphony.xwork2.ObjectFactory; +import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.ConfigurationManager; +import com.opensymphony.xwork2.inject.Container; +import com.opensymphony.xwork2.inject.ContainerBuilder; +import com.opensymphony.xwork2.inject.Context; +import com.opensymphony.xwork2.inject.Factory; import com.opensymphony.xwork2.util.LocalizedTextUtil; /** @@ -131,6 +146,27 @@ public class DispatcherTest extends StrutsTestCase { } } + public void testObjectFactoryDestroy() throws Exception { + + final InnerDestroyableObjectFactory destroyedObjectFactory = new InnerDestroyableObjectFactory(); + Dispatcher du = new Dispatcher(new MockServletContext(), new HashMap()); + ConfigurationManager cm = new ConfigurationManager(); + Mock mockConfiguration = new Mock(Configuration.class); + cm.setConfiguration((Configuration)mockConfiguration.proxy()); + + Mock mockContainer = new Mock(Container.class); + mockConfiguration.expectAndReturn("getContainer", mockContainer.proxy()); + mockContainer.expectAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), destroyedObjectFactory); + mockConfiguration.expect("destroy"); + + du.setConfigurationManager(cm); + assertFalse(destroyedObjectFactory.destroyed); + du.cleanup(); + assertTrue(destroyedObjectFactory.destroyed); + mockConfiguration.verify(); + mockContainer.verify(); + } + class InternalConfigurationManager extends ConfigurationManager { public boolean destroyConfiguration = false; diff --git a/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java b/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java index a17a16493..948483ebc 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java @@ -83,32 +83,7 @@ public class FilterDispatcherTest extends StrutsTestCase { assertEquals(result4[3], "foo/bar/package4/"); } - public void testObjectFactoryDestroy() throws Exception { - - final InnerDestroyableObjectFactory destroyedObjectFactory = new InnerDestroyableObjectFactory(); - FilterDispatcher filterDispatcher = new FilterDispatcher() { - @Override - protected Dispatcher createDispatcher(FilterConfig cfg) { - return new Dispatcher(cfg.getServletContext(), new HashMap()) { - Container cont = new ContainerBuilder() - .factory(ObjectFactory.class, new Factory() { - public Object create(Context context) throws Exception { return destroyedObjectFactory; } - }) - .create(false); - - @Override - public Container getContainer() { - return cont; - } - }; - } - }; - filterDispatcher.init(new MockFilterConfig((ServletContext) null)); - - assertFalse(destroyedObjectFactory.destroyed); - filterDispatcher.destroy(); - assertTrue(destroyedObjectFactory.destroyed); - } + public void testIfActionMapperIsNullDontServiceAction() throws Exception { MockServletContext servletContext = new MockServletContext(); @@ -125,8 +100,6 @@ public class FilterDispatcherTest extends StrutsTestCase { - ObjectFactory.setObjectFactory(new InnerObjectFactory()); - FilterDispatcher filter = new FilterDispatcher() { protected Dispatcher createDispatcher() { return _dispatcher; @@ -138,7 +111,7 @@ public class FilterDispatcherTest extends StrutsTestCase { assertFalse(_dispatcher.serviceRequest); } - + public void testCharacterEncodingSetBeforeRequestWrappingAndActionService() throws Exception { MockServletContext servletContext = new MockServletContext(); MockFilterConfig filterConfig = new MockFilterConfig(servletContext); @@ -148,20 +121,6 @@ public class FilterDispatcherTest extends StrutsTestCase { final InnerDispatcher _dispatcher = new InnerDispatcher(servletContext); Dispatcher.setInstance(null); - DefaultConfiguration conf = new DefaultConfiguration() { - @Override - public Container getContainer() { - return new ContainerBuilder().create(false); - } - }; - - ConfigurationManager confManager = new ConfigurationManager(); - confManager.setConfiguration(conf); - _dispatcher.setConfigurationManager(confManager); - - - ObjectFactory.setObjectFactory(new InnerObjectFactory()); - _dispatcher.setDefaultEncoding("UTF-16_DUMMY"); FilterDispatcher filter = new FilterDispatcher() { @@ -171,13 +130,13 @@ public class FilterDispatcherTest extends StrutsTestCase { }; filter.setActionMapper(new InnerActionMapper()); filter.init(filterConfig); + _dispatcher.setDefaultEncoding("UTF-16_DUMMY"); filter.doFilter(req, res, chain); assertTrue(_dispatcher.wrappedRequest); assertTrue(_dispatcher.serviceRequest); } - // === inner class ======== public static class InnerObjectFactory extends ObjectFactory { @@ -217,7 +176,7 @@ public class FilterDispatcherTest extends StrutsTestCase { // if we set the chracter encoding AFTER we do wrap request, we will get // a failing test assertNotNull(request.getCharacterEncoding()); - assertEquals(request.getCharacterEncoding(), "UTF-16_DUMMY"); + assertEquals("UTF-16_DUMMY", request.getCharacterEncoding()); return request; } @@ -227,7 +186,7 @@ public class FilterDispatcherTest extends StrutsTestCase { // if we set the chracter encoding AFTER we do wrap request, we will get // a failing test assertNotNull(request.getCharacterEncoding()); - assertEquals(request.getCharacterEncoding(), "UTF-16_DUMMY"); + assertEquals("UTF-16_DUMMY", request.getCharacterEncoding()); } } diff --git a/core/src/test/java/org/apache/struts2/dispatcher/FilterTest.java b/core/src/test/java/org/apache/struts2/dispatcher/FilterTest.java index 41f040201..7eff708c1 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/FilterTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/FilterTest.java @@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletResponse; import junit.framework.TestCase; +import org.apache.struts2.StrutsTestCase; import org.apache.struts2.dispatcher.mapper.ActionMapper; import org.apache.struts2.dispatcher.mapper.ActionMapping; import org.springframework.mock.web.MockFilterConfig; @@ -50,7 +51,7 @@ import com.opensymphony.xwork2.inject.Container; * * @version $Date$ $Id$ */ -public class FilterTest extends TestCase { +public class FilterTest extends StrutsTestCase { protected MockFilterConfig filterConfig; protected MockHttpServletRequest request; @@ -70,6 +71,7 @@ public class FilterTest extends TestCase { @Override protected void tearDown() throws Exception { + super.tearDown(); filterConfig = null; request = null; response = null; @@ -84,6 +86,7 @@ public class FilterTest extends TestCase { @Override protected void setUp() throws Exception { + super.setUp(); Dispatcher.setInstance(null); filterConfig = new MockFilterConfig(); @@ -145,7 +148,7 @@ public class FilterTest extends TestCase { assertFalse(_dispatcher2.service); filterDispatcher.init(filterConfig); - FilterDispatcher.setActionMapper(new FilterTest.InnerMapper()); + filterDispatcher.setActionMapper(new FilterTest.InnerMapper()); filterDispatcher.doFilter(request, response, filterChain2); filterDispatcher.destroy(); @@ -180,7 +183,7 @@ public class FilterTest extends TestCase { assertFalse(_dispatcher2.cleanUp); filterDispatcher.init(filterConfig); - FilterDispatcher.setActionMapper(new FilterTest.InnerMapper()); + filterDispatcher.setActionMapper(new FilterTest.InnerMapper()); filterDispatcher.doFilter(request, response, filterChain2); filterDispatcher.doFilter(request, response, filterChain2); filterDispatcher.destroy(); @@ -296,7 +299,7 @@ public class FilterTest extends TestCase { @Override public Container getContainer() { - return null; + return container; } @Override diff --git a/core/src/test/java/org/apache/struts2/dispatcher/HttpHeaderResultTest.java b/core/src/test/java/org/apache/struts2/dispatcher/HttpHeaderResultTest.java index f5b9d690f..f5ddac97d 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/HttpHeaderResultTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/HttpHeaderResultTest.java @@ -32,7 +32,8 @@ import com.mockobjects.dynamic.C; import com.mockobjects.dynamic.Mock; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; -import com.opensymphony.xwork2.util.OgnlUtil; +import com.opensymphony.xwork2.ognl.OgnlUtil; +import com.opensymphony.xwork2.util.reflection.ReflectionProvider; /** @@ -45,6 +46,7 @@ public class HttpHeaderResultTest extends StrutsTestCase { HttpHeaderResult result; HttpServletResponse response; Mock responseMock; + ReflectionProvider reflectionProvider; public void testHeaderValuesAreNotParsedWhenParseIsFalse() throws Exception { @@ -56,7 +58,7 @@ public class HttpHeaderResultTest extends StrutsTestCase { values.put("bar", "abc"); ActionContext.getContext().getValueStack().push(values); - OgnlUtil.setProperties(params, result); + reflectionProvider.setProperties(params, result); responseMock.expect("addHeader", C.args(C.eq("foo"), C.eq("${bar}"))); responseMock.expect("addHeader", C.args(C.eq("baz"), C.eq("baz"))); @@ -74,7 +76,7 @@ public class HttpHeaderResultTest extends StrutsTestCase { values.put("bar", "abc"); ActionContext.getContext().getValueStack().push(values); - OgnlUtil.setProperties(params, result); + reflectionProvider.setProperties(params, result); responseMock.expect("addHeader", C.args(C.eq("foo"), C.eq("abc"))); responseMock.expect("addHeader", C.args(C.eq("baz"), C.eq("baz"))); @@ -123,12 +125,12 @@ public class HttpHeaderResultTest extends StrutsTestCase { responseMock = new Mock(HttpServletResponse.class); response = (HttpServletResponse) responseMock.proxy(); invocation = (ActionInvocation) new Mock(ActionInvocation.class).proxy(); + reflectionProvider = container.getInstance(ReflectionProvider.class); ServletActionContext.setResponse(response); } protected void tearDown() throws Exception { super.tearDown(); - ServletActionContext.setResponse(null); ActionContext.setContext(null); } } diff --git a/core/src/test/java/org/apache/struts2/dispatcher/PlainTextResultTest.java b/core/src/test/java/org/apache/struts2/dispatcher/PlainTextResultTest.java index a7435b348..24239515c 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/PlainTextResultTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/PlainTextResultTest.java @@ -27,6 +27,7 @@ import java.io.StringWriter; import junit.framework.TestCase; import org.apache.struts2.StrutsStatics; +import org.apache.struts2.StrutsTestCase; import org.apache.struts2.views.jsp.AbstractUITagTest; import org.apache.struts2.views.jsp.StrutsMockHttpServletResponse; import org.apache.struts2.views.jsp.StrutsMockServletContext; @@ -41,7 +42,7 @@ import com.opensymphony.xwork2.util.ValueStack; * Test case for PlainTextResult. * */ -public class PlainTextResultTest extends TestCase { +public class PlainTextResultTest extends StrutsTestCase { ValueStack stack; MockActionInvocation invocation; @@ -133,7 +134,7 @@ public class PlainTextResultTest extends TestCase { response = new StrutsMockHttpServletResponse(); response.setWriter(writer); servletContext = new StrutsMockServletContext(); - stack = ValueStackFactory.getFactory().createValueStack(); + stack = ActionContext.getContext().getValueStack(); context = new ActionContext(stack.getContext()); context.put(StrutsStatics.HTTP_RESPONSE, response); context.put(StrutsStatics.SERVLET_CONTEXT, servletContext); @@ -144,6 +145,7 @@ public class PlainTextResultTest extends TestCase { protected void tearDown() throws Exception { + super.tearDown(); stack = null; invocation = null; context = null; diff --git a/core/src/test/java/org/apache/struts2/dispatcher/ServletRedirectResultTest.java b/core/src/test/java/org/apache/struts2/dispatcher/ServletRedirectResultTest.java index 63cfdf053..48d8b4724 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/ServletRedirectResultTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/ServletRedirectResultTest.java @@ -132,6 +132,6 @@ public class ServletRedirectResultTest extends StrutsTestCase implements StrutsS MockActionInvocation ai = new MockActionInvocation(); ai.setInvocationContext(ac); this.ai = ai; - ai.setStack(ValueStackFactory.getFactory().createValueStack()); + ai.setStack(ActionContext.getContext().getValueStack()); } } diff --git a/core/src/test/java/org/apache/struts2/dispatcher/StreamResultTest.java b/core/src/test/java/org/apache/struts2/dispatcher/StreamResultTest.java index 87c9f6f65..aff9174b5 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/StreamResultTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/StreamResultTest.java @@ -29,6 +29,7 @@ import java.net.URL; import junit.framework.TestCase; import org.apache.struts2.ServletActionContext; +import org.apache.struts2.StrutsTestCase; import org.springframework.mock.web.MockHttpServletResponse; import com.opensymphony.xwork2.util.ClassLoaderUtil; @@ -42,7 +43,7 @@ import com.opensymphony.xwork2.util.ValueStack; * Unit test for {@link StreamResult}. * */ -public class StreamResultTest extends TestCase { +public class StreamResultTest extends StrutsTestCase { private StreamResult result; private MockHttpServletResponse response; @@ -166,11 +167,11 @@ public class StreamResultTest extends TestCase { } protected void setUp() throws Exception { + super.setUp(); response = new MockHttpServletResponse(); result = new StreamResult(); - stack = ValueStackFactory.getFactory().createValueStack(); - ActionContext.getContext().setValueStack(stack); + stack = ActionContext.getContext().getValueStack(); MyImageAction action = new MyImageAction(); contentLength = (int) action.getContentLength(); @@ -186,7 +187,8 @@ public class StreamResultTest extends TestCase { - protected void tearDown() { + protected void tearDown() throws Exception { + super.tearDown(); response = null; result = null; stack = null; diff --git a/core/src/test/java/org/apache/struts2/dispatcher/StrutsResultSupportTest.java b/core/src/test/java/org/apache/struts2/dispatcher/StrutsResultSupportTest.java index af6d9d6c5..dcae06d05 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/StrutsResultSupportTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/StrutsResultSupportTest.java @@ -23,6 +23,7 @@ package org.apache.struts2.dispatcher; import org.apache.struts2.StrutsTestCase; import org.easymock.EasyMock; +import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.util.ValueStack; @@ -35,7 +36,7 @@ public class StrutsResultSupportTest extends StrutsTestCase { public void testParse() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); stack.push(new ActionSupport() { public String getMyLocation() { return "ThisIsMyLocation"; @@ -60,7 +61,7 @@ public class StrutsResultSupportTest extends StrutsTestCase { } public void testParseAndEncode() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); stack.push(new ActionSupport() { public String getMyLocation() { return "/myPage?param=value¶m1=value1"; @@ -86,7 +87,7 @@ public class StrutsResultSupportTest extends StrutsTestCase { public void testNoParseAndEncode() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); stack.push(new ActionSupport() { public String getMyLocation() { return "myLocation.jsp"; diff --git a/core/src/test/java/org/apache/struts2/dispatcher/VelocityResultTest.java b/core/src/test/java/org/apache/struts2/dispatcher/VelocityResultTest.java index e1f736c9c..0d642a979 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/VelocityResultTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/VelocityResultTest.java @@ -22,6 +22,7 @@ package org.apache.struts2.dispatcher; import junit.framework.TestCase; +import org.apache.struts2.StrutsTestCase; import org.apache.velocity.Template; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.exception.ParseErrorException; @@ -38,7 +39,7 @@ import com.opensymphony.xwork2.util.ValueStackFactory; /** * */ -public class VelocityResultTest extends TestCase { +public class VelocityResultTest extends StrutsTestCase { ActionInvocation actionInvocation; Mock mockActionProxy; @@ -91,9 +92,10 @@ public class VelocityResultTest extends TestCase { } protected void setUp() throws Exception { + super.setUp(); namespace = "/html"; result = new VelocityResult(); - stack = ValueStackFactory.getFactory().createValueStack(); + stack = ActionContext.getContext().getValueStack(); ActionContext.getContext().setValueStack(stack); velocity = new TestVelocityEngine(); mockActionProxy = new Mock(ActionProxy.class); diff --git a/core/src/test/java/org/apache/struts2/interceptor/StrutsConversionErrorInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/StrutsConversionErrorInterceptorTest.java index efd07b23f..a77a0f8f6 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/StrutsConversionErrorInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/StrutsConversionErrorInterceptorTest.java @@ -86,7 +86,7 @@ public class StrutsConversionErrorInterceptorTest extends StrutsTestCase { interceptor = new StrutsConversionErrorInterceptor(); mockInvocation = new Mock(ActionInvocation.class); invocation = (ActionInvocation) mockInvocation.proxy(); - stack = ValueStackFactory.getFactory().createValueStack(); + stack = ActionContext.getContext().getValueStack(); context = new ActionContext(stack.getContext()); conversionErrors = new HashMap(); context.setConversionErrors(conversionErrors); diff --git a/core/src/test/java/org/apache/struts2/interceptor/TokenInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/TokenInterceptorTest.java index 2ff3c5d36..367fe6c67 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/TokenInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/TokenInterceptorTest.java @@ -121,7 +121,7 @@ public class TokenInterceptorTest extends StrutsTestCase { request.setParameterMap(params); extraContext.put(ServletActionContext.HTTP_REQUEST, request); - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); stack.getContext().putAll(extraContext); oldContext = new ActionContext(stack.getContext()); ActionContext.setContext(oldContext); @@ -132,7 +132,6 @@ public class TokenInterceptorTest extends StrutsTestCase { } protected void tearDown() throws Exception { - configurationManager.destroyConfiguration(); - ActionContext.setContext(null); + super.tearDown(); } } diff --git a/core/src/test/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptorTest.java index 54718be4f..bd16704d2 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptorTest.java @@ -38,6 +38,7 @@ public class AnnotationValidationInterceptorTest extends StrutsTestCase { super.setUp(); test = new TestAction(); interceptor = new AnnotationValidationInterceptor(); + container.inject(interceptor); mockActionInvocation = new Mock(ActionInvocation.class); mockActionProxy = new Mock(ActionProxy.class); mockActionInvocation.matchAndReturn("getProxy", (ActionProxy) mockActionProxy.proxy()); diff --git a/core/src/test/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptorTest.java index ad04c797e..7ad19f06d 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptorTest.java @@ -126,16 +126,15 @@ public class JSONValidationInterceptorTest extends StrutsTestCase { this.action = new TestAction(); this.interceptor = new JSONValidationInterceptor(); this.validationInterceptor = new AnnotationValidationInterceptor(); + container.inject(validationInterceptor); this.request = new StrutsMockHttpServletRequest(); stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter); this.response = new StrutsMockHttpServletResponse(); response.setWriter(writer); - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); - ActionContext context = new ActionContext(stack.getContext()); + ActionContext context = ActionContext.getContext(); - ActionContext.setContext(context); context.put(StrutsStatics.HTTP_REQUEST, request); context.put(StrutsStatics.HTTP_RESPONSE, response); diff --git a/core/src/test/java/org/apache/struts2/util/InvocationSessionStoreTest.java b/core/src/test/java/org/apache/struts2/util/InvocationSessionStoreTest.java index 35f32408f..3a37dba33 100644 --- a/core/src/test/java/org/apache/struts2/util/InvocationSessionStoreTest.java +++ b/core/src/test/java/org/apache/struts2/util/InvocationSessionStoreTest.java @@ -67,7 +67,8 @@ public class InvocationSessionStoreTest extends StrutsTestCase { } protected void setUp() throws Exception { - stack = ValueStackFactory.getFactory().createValueStack(); + super.setUp(); + stack = ActionContext.getContext().getValueStack(); ActionContext actionContext = new ActionContext(stack.getContext()); ActionContext.setContext(actionContext); diff --git a/core/src/test/java/org/apache/struts2/util/StrutsUtilTest.java b/core/src/test/java/org/apache/struts2/util/StrutsUtilTest.java index 4a42f79f9..23af8dc49 100644 --- a/core/src/test/java/org/apache/struts2/util/StrutsUtilTest.java +++ b/core/src/test/java/org/apache/struts2/util/StrutsUtilTest.java @@ -35,6 +35,7 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockRequestDispatcher; +import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.ValueStackFactory; @@ -195,7 +196,7 @@ public class StrutsUtilTest extends StrutsTestCase { protected void setUp() throws Exception { super.setUp(); - stack = ValueStackFactory.getFactory().createValueStack(); + stack = ActionContext.getContext().getValueStack(); request = new InternalMockHttpServletRequest(); response = new MockHttpServletResponse(); strutsUtil = new StrutsUtil(stack, request, response); diff --git a/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java b/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java index 4e068f620..83664b272 100644 --- a/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java +++ b/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java @@ -27,6 +27,7 @@ import junit.framework.TestCase; import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsStatics; +import org.apache.struts2.StrutsTestCase; import org.apache.struts2.views.jsp.StrutsMockHttpServletResponse; import org.apache.struts2.views.jsp.StrutsMockServletContext; import org.springframework.mock.web.MockHttpServletRequest; @@ -40,7 +41,7 @@ import com.opensymphony.xwork2.util.ValueStackFactory; * Test case for FreeMarkerResult. * */ -public class FreeMarkerResultTest extends TestCase { +public class FreeMarkerResultTest extends StrutsTestCase { ValueStack stack; MockActionInvocation invocation; @@ -89,7 +90,7 @@ public class FreeMarkerResultTest extends TestCase { response.setWriter(writer); request = new MockHttpServletRequest(); servletContext = new StrutsMockServletContext(); - stack = ValueStackFactory.getFactory().createValueStack(); + stack = ActionContext.getContext().getValueStack(); context = new ActionContext(stack.getContext()); context.put(StrutsStatics.HTTP_RESPONSE, response); context.put(StrutsStatics.HTTP_REQUEST, request); diff --git a/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerTest.java b/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerTest.java index ec146abcc..1901f798d 100644 --- a/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerTest.java +++ b/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerTest.java @@ -24,6 +24,7 @@ import java.util.List; import junit.framework.TestCase; +import org.apache.struts2.StrutsTestCase; import org.apache.struts2.util.ListEntry; import org.apache.struts2.util.StrutsUtil; @@ -37,22 +38,13 @@ import freemarker.template.ObjectWrapper; /** */ -public class FreemarkerTest extends TestCase { +public class FreemarkerTest extends StrutsTestCase { TestAction testAction = null; - /** - * - */ - public FreemarkerTest(String name) { - super(name); - } - - public void testSelectHelper() { StrutsUtil wwUtil = new StrutsUtil(ActionContext.getContext().getValueStack(), null, null); - List selectList = null; selectList = wwUtil.makeSelectList("ignored", "stringList", null, null); @@ -79,9 +71,6 @@ public class FreemarkerTest extends TestCase { protected void setUp() throws Exception { super.setUp(); - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); - ActionContext.setContext(new ActionContext(stack.getContext())); - testAction = new TestAction(); ActionContext.getContext().getValueStack().push(testAction); } diff --git a/core/src/test/java/org/apache/struts2/views/freemarker/tags/TagModelTest.java b/core/src/test/java/org/apache/struts2/views/freemarker/tags/TagModelTest.java index a623cdee6..64233f18b 100644 --- a/core/src/test/java/org/apache/struts2/views/freemarker/tags/TagModelTest.java +++ b/core/src/test/java/org/apache/struts2/views/freemarker/tags/TagModelTest.java @@ -33,7 +33,8 @@ import org.apache.struts2.views.freemarker.tags.TagModel; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; -import com.opensymphony.xwork2.util.OgnlValueStack; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ognl.OgnlValueStack; import freemarker.ext.util.WrapperTemplateModel; import freemarker.template.AdapterTemplateModel; @@ -56,7 +57,7 @@ public class TagModelTest extends StrutsTestCase { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); - OgnlValueStack stack = new OgnlValueStack(); + OgnlValueStack stack = (OgnlValueStack)ActionContext.getContext().getValueStack(); Map params = new LinkedHashMap(); @@ -184,8 +185,8 @@ public class TagModelTest extends StrutsTestCase { public void testGetWriter() throws Exception { - OgnlValueStack stack = new OgnlValueStack(); - + OgnlValueStack stack = (OgnlValueStack)ActionContext.getContext().getValueStack(); + final InternalBean bean = new InternalBean(stack); MockHttpServletRequest request = new MockHttpServletRequest(); diff --git a/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java index ca0510325..47cc87717 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java @@ -82,7 +82,7 @@ public abstract class AbstractTagTest extends StrutsTestCase { * create our standard mock objects */ action = this.getAction(); - stack = ValueStackFactory.getFactory().createValueStack(); + stack = ActionContext.getContext().getValueStack(); context = stack.getContext(); stack.push(action); diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ActionTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ActionTagTest.java index e80416362..eda98420d 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ActionTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ActionTagTest.java @@ -251,10 +251,7 @@ public class ActionTagTest extends AbstractTagTest { } protected void tearDown() throws Exception { - configurationManager.destroyConfiguration(); - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); - ActionContext.setContext(new ActionContext(stack.getContext())); super.tearDown(); } } diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ElseIfTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ElseIfTagTest.java index cfd3a0087..2e354ba1a 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ElseIfTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ElseIfTagTest.java @@ -30,6 +30,8 @@ import org.apache.struts2.components.If; import com.mockobjects.servlet.MockJspWriter; import com.mockobjects.servlet.MockPageContext; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ognl.OgnlValueStack; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.ValueStackFactory; @@ -98,7 +100,7 @@ public class ElseIfTagTest extends StrutsTestCase { protected void setUp() throws Exception { super.setUp(); - stack = ValueStackFactory.getFactory().createValueStack(); + stack = ActionContext.getContext().getValueStack(); jspWriter = new MockJspWriter(); diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ElseTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ElseTagTest.java index 78477e18c..6f6ad019b 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ElseTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ElseTagTest.java @@ -29,6 +29,7 @@ import org.apache.struts2.components.If; import com.mockobjects.servlet.MockJspWriter; import com.mockobjects.servlet.MockPageContext; +import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.ValueStackFactory; @@ -93,7 +94,7 @@ public class ElseTagTest extends StrutsTestCase { super.setUp(); // create the needed objects elseTag = new ElseTag(); - stack = ValueStackFactory.getFactory().createValueStack(); + stack = ActionContext.getContext().getValueStack(); // create the mock http servlet request StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest(); diff --git a/core/src/test/java/org/apache/struts2/views/jsp/IfTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/IfTagTest.java index 4562e47cd..fbb2e1373 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/IfTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/IfTagTest.java @@ -324,7 +324,7 @@ public class IfTagTest extends StrutsTestCase { super.setUp(); // create the needed objects tag = new IfTag(); - stack = ValueStackFactory.getFactory().createValueStack(); + stack = ActionContext.getContext().getValueStack(); // create the mock http servlet request StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest(); diff --git a/core/src/test/java/org/apache/struts2/views/jsp/PropertyTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/PropertyTagTest.java index 5d177c035..e0269b227 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/PropertyTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/PropertyTagTest.java @@ -42,7 +42,7 @@ import com.opensymphony.xwork2.util.ValueStackFactory; public class PropertyTagTest extends StrutsTestCase { StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest(); - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack; public void testDefaultValue() { @@ -279,7 +279,7 @@ public class PropertyTagTest extends StrutsTestCase { protected void setUp() throws Exception { super.setUp(); - ActionContext.getContext().setValueStack(stack); + stack = ActionContext.getContext().getValueStack(); request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack); } diff --git a/core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java index 240c62379..923dc3736 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java @@ -172,8 +172,9 @@ public class TextTagTest extends AbstractTagTest { assertEquals(value1, writer.toString()); final StringBuffer buffer = writer.getBuffer(); buffer.delete(0, buffer.length()); - ValueStack newStack = ValueStackFactory.getFactory().createValueStack(); + ValueStack newStack = container.getInstance(ValueStackFactory.class).createValueStack(); newStack.getContext().put(ActionContext.LOCALE, foreignLocale); + newStack.getContext().put(ActionContext.CONTAINER, container); newStack.push(new TestAction1()); request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, newStack); assertNotSame(ActionContext.getContext().getValueStack().peek(), newStack.peek()); @@ -203,8 +204,9 @@ public class TextTagTest extends AbstractTagTest { buffer.delete(0, buffer.length()); String value_int = getLocalizedMessage(foreignLocale); assertFalse(value_default.equals(value_int)); - ValueStack newStack = ValueStackFactory.getFactory().createValueStack(stack); + ValueStack newStack = container.getInstance(ValueStackFactory.class).createValueStack(stack); newStack.getContext().put(ActionContext.LOCALE, foreignLocale); + newStack.getContext().put(ActionContext.CONTAINER, container); assertNotSame(newStack.getContext().get(ActionContext.LOCALE), ActionContext.getContext().getLocale()); request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, newStack); assertEquals(ActionContext.getContext().getValueStack().peek(), newStack.peek()); @@ -275,7 +277,6 @@ public class TextTagTest extends AbstractTagTest { } protected void tearDown() throws Exception { - ValueStack valueStack = ValueStackFactory.getFactory().createValueStack(); - ActionContext.setContext(new ActionContext(valueStack.getContext())); + super.tearDown(); } } diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/FormTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/FormTagTest.java index 6402c1fbf..07f351b50 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ui/FormTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/FormTagTest.java @@ -184,17 +184,6 @@ public class FormTagTest extends AbstractUITagTest { } }); - // used by form tag to get "actionClass" parameter - ObjectFactory.setObjectFactory(new ObjectFactory() { - public Class getClassInstance(String className) throws ClassNotFoundException { - if (DefaultActionMapper.class.getName().equals(className)) { - return DefaultActionMapper.class; - } - return ActionSupport.class; - } - }); - - FormTag tag = new FormTag(); tag.setPageContext(pageContext); tag.setName("myForm"); @@ -221,7 +210,6 @@ public class FormTagTest extends AbstractUITagTest { } finally { configurationManager.setConfiguration(originalConfiguration); - ObjectFactory.setObjectFactory(originalObjectFactory); } } @@ -289,17 +277,6 @@ public class FormTagTest extends AbstractUITagTest { } }); - // used by form tag to get "actionClass" parameter - ObjectFactory.setObjectFactory(new ObjectFactory() { - public Class getClassInstance(String className) throws ClassNotFoundException { - if (DefaultActionMapper.class.getName().equals(className)) { - return DefaultActionMapper.class; - } - return ActionSupport.class; - } - }); - - FormTag tag = new FormTag(); tag.setPageContext(pageContext); tag.setName("myForm"); @@ -326,7 +303,6 @@ public class FormTagTest extends AbstractUITagTest { } finally { configurationManager.setConfiguration(originalConfiguration); - ObjectFactory.setObjectFactory(originalObjectFactory); } } diff --git a/core/src/test/java/org/apache/struts2/views/util/ContextUtilTest.java b/core/src/test/java/org/apache/struts2/views/util/ContextUtilTest.java index dd7b05c3b..3b9e304cd 100755 --- a/core/src/test/java/org/apache/struts2/views/util/ContextUtilTest.java +++ b/core/src/test/java/org/apache/struts2/views/util/ContextUtilTest.java @@ -23,7 +23,12 @@ package org.apache.struts2.views.util; import junit.framework.TestCase; import org.apache.struts2.StrutsConstants; +import org.apache.struts2.StrutsTestCase; +import com.mockobjects.dynamic.C; +import com.mockobjects.dynamic.Mock; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.ValueStackFactory; @@ -31,77 +36,83 @@ import com.opensymphony.xwork2.util.ValueStackFactory; * Test case for ContextUtil * */ -public class ContextUtilTest extends TestCase { +public class ContextUtilTest extends StrutsTestCase { + private void setAltSyntax(ValueStack stack, String val) { + Mock container = new Mock(Container.class); + container.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(StrutsConstants.STRUTS_TAG_ALTSYNTAX)), val); + stack.getContext().put(ActionContext.CONTAINER, container.proxy()); + } + public void testAltSyntaxMethod1() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); stack.getContext().put("useAltSyntax", "true"); - ContextUtil.setAltSyntax("true"); + setAltSyntax(stack, "true"); assertTrue(ContextUtil.isUseAltSyntax(stack.getContext())); } public void testAltSyntaxMethod2() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); stack.getContext().put("useAltSyntax", "false"); - ContextUtil.setAltSyntax("true"); + setAltSyntax(stack, "true"); assertTrue(ContextUtil.isUseAltSyntax(stack.getContext())); } public void testAltSyntaxMethod3() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); stack.getContext().put("useAltSyntax", "true"); - ContextUtil.setAltSyntax("false"); + setAltSyntax(stack, "false"); assertTrue(ContextUtil.isUseAltSyntax(stack.getContext())); } public void testAltSyntaxMethod4() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); stack.getContext().put("useAltSyntax", "false"); - ContextUtil.setAltSyntax("false"); + setAltSyntax(stack, "false"); assertFalse(ContextUtil.isUseAltSyntax(stack.getContext())); } //======================================================== public void testAltSyntaxMethod5() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); stack.getContext().put("useAltSyntax", Boolean.TRUE); - ContextUtil.setAltSyntax("true"); + setAltSyntax(stack, "true"); assertTrue(ContextUtil.isUseAltSyntax(stack.getContext())); } public void testAltSyntaxMethod6() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); stack.getContext().put("useAltSyntax", Boolean.FALSE); - ContextUtil.setAltSyntax("true"); + setAltSyntax(stack, "true"); assertTrue(ContextUtil.isUseAltSyntax(stack.getContext())); } public void testAltSyntaxMethod7() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); stack.getContext().put("useAltSyntax", Boolean.TRUE); - ContextUtil.setAltSyntax("false"); + setAltSyntax(stack, "false"); assertTrue(ContextUtil.isUseAltSyntax(stack.getContext())); } public void testAltSyntaxMethod8() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); stack.getContext().put("useAltSyntax", Boolean.FALSE); - ContextUtil.setAltSyntax("false"); + setAltSyntax(stack, "false"); assertFalse(ContextUtil.isUseAltSyntax(stack.getContext())); } // ========================================== public void testAltSyntaxMethod9() throws Exception { - ValueStack stack = ValueStackFactory.getFactory().createValueStack(); + ValueStack stack = ActionContext.getContext().getValueStack(); stack.getContext().put("useAltSyntax", null); - ContextUtil.setAltSyntax("true"); + setAltSyntax(stack, "true"); assertTrue(ContextUtil.isUseAltSyntax(stack.getContext())); } } diff --git a/core/src/test/java/org/apache/struts2/views/util/UrlHelperTest.java b/core/src/test/java/org/apache/struts2/views/util/UrlHelperTest.java index c502dee21..13fdc7f81 100644 --- a/core/src/test/java/org/apache/struts2/views/util/UrlHelperTest.java +++ b/core/src/test/java/org/apache/struts2/views/util/UrlHelperTest.java @@ -20,16 +20,24 @@ */ package org.apache.struts2.views.util; +import com.mockobjects.dynamic.C; import com.mockobjects.dynamic.Mock; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.conversion.impl.XWorkConverter; +import com.opensymphony.xwork2.inject.Container; +import com.opensymphony.xwork2.inject.Scope.Strategy; +import com.opensymphony.xwork2.util.ValueStack; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; import java.util.TreeMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.struts2.StrutsConstants; import org.apache.struts2.StrutsTestCase; @@ -38,6 +46,8 @@ import org.apache.struts2.StrutsTestCase; * */ public class UrlHelperTest extends StrutsTestCase { + + private StubContainer stubContainer; public void testForceAddSchemeHostAndPort() throws Exception { String expectedUrl = "http://localhost/contextPath/path1/path2/myAction.action"; @@ -252,8 +262,8 @@ public class UrlHelperTest extends StrutsTestCase { String expectedString = "https://www.mydomain.com:7002/mywebapp/MyAction.action?foo=bar&hello=earth&hello=mars"; - UrlHelper.setHttpPort("7001"); - UrlHelper.setHttpsPort("7002"); + setProp(StrutsConstants.STRUTS_URL_HTTP_PORT, "7001"); + setProp(StrutsConstants.STRUTS_URL_HTTPS_PORT, "7002"); Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); mockHttpServletRequest.expectAndReturn("getServerName", "www.mydomain.com"); @@ -281,8 +291,8 @@ public class UrlHelperTest extends StrutsTestCase { String expectedString = "http://www.mydomain.com:7001/mywebapp/MyAction.action?foo=bar&hello=earth&hello=mars"; - UrlHelper.setHttpPort("7001"); - UrlHelper.setHttpsPort("7002"); + setProp(StrutsConstants.STRUTS_URL_HTTP_PORT, "7001"); + setProp(StrutsConstants.STRUTS_URL_HTTPS_PORT, "7002"); Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); mockHttpServletRequest.expectAndReturn("getServerName", "www.mydomain.com"); @@ -354,7 +364,7 @@ public class UrlHelperTest extends StrutsTestCase { public void testTranslateAndEncode() throws Exception { - UrlHelper.setCustomEncoding("UTF-8"); + setProp(StrutsConstants.STRUTS_I18N_ENCODING, "UTF-8"); String result = UrlHelper.translateAndEncode("\u65b0\u805e"); String expectedResult = "%E6%96%B0%E8%81%9E"; @@ -362,10 +372,64 @@ public class UrlHelperTest extends StrutsTestCase { } public void testTranslateAndDecode() throws Exception { - UrlHelper.setCustomEncoding("UTF-8"); + setProp(StrutsConstants.STRUTS_I18N_ENCODING, "UTF-8"); String result = UrlHelper.translateAndDecode("%E6%96%B0%E8%81%9E"); String expectedResult = "\u65b0\u805e"; assertEquals(result, expectedResult); } + + public void setUp() throws Exception { + super.setUp(); + stubContainer = new StubContainer(container); + ActionContext.getContext().put(ActionContext.CONTAINER, stubContainer); + } + + private void setProp(String key, String val) { + stubContainer.overrides.put(key, val); + } + + class StubContainer implements Container { + + Container parent; + + public StubContainer(Container parent) { + super(); + this.parent = parent; + } + + public Map overrides = new HashMap(); + public T getInstance(Class type, String name) { + if (String.class.isAssignableFrom(type) && overrides.containsKey(name)) { + return (T) overrides.get(name); + } else { + return parent.getInstance(type, name); + } + } + + public T getInstance(Class type) { + return parent.getInstance(type); + } + + public Set getInstanceNames(Class type) { + return parent.getInstanceNames(type); + } + + public void inject(Object o) { + parent.inject(o); + } + + public T inject(Class implementation) { + return parent.inject(implementation); + } + + public void removeScopeStrategy() { + parent.removeScopeStrategy(); + + } + + public void setScopeStrategy(Strategy scopeStrategy) { + parent.setScopeStrategy(scopeStrategy); + } + } } diff --git a/core/src/test/java/org/apache/struts2/views/xslt/XSLTResultTest.java b/core/src/test/java/org/apache/struts2/views/xslt/XSLTResultTest.java index 59ecb9c17..08436dcf7 100644 --- a/core/src/test/java/org/apache/struts2/views/xslt/XSLTResultTest.java +++ b/core/src/test/java/org/apache/struts2/views/xslt/XSLTResultTest.java @@ -142,13 +142,13 @@ public class XSLTResultTest extends StrutsTestCase { } protected void setUp() throws Exception { + super.setUp(); request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); servletContext = new MockServletContext(); result = new XSLTResult(); - stack = ValueStackFactory.getFactory().createValueStack(); - ActionContext.getContext().setValueStack(stack); + stack = ActionContext.getContext().getValueStack(); MyAction action = new MyAction(); @@ -163,7 +163,8 @@ public class XSLTResultTest extends StrutsTestCase { ActionContext.getContext().put(ServletActionContext.SERVLET_CONTEXT, servletContext); } - protected void tearDown() { + protected void tearDown() throws Exception { + super.tearDown(); request = null; response = null; servletContext = null; diff --git a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ListValidatorsAction.java b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ListValidatorsAction.java index a99b6749a..4efafc67a 100644 --- a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ListValidatorsAction.java +++ b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ListValidatorsAction.java @@ -27,7 +27,8 @@ import org.apache.struts2.util.ClassLoaderUtils; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; -import com.opensymphony.xwork2.validator.ActionValidatorManagerFactory; +import com.opensymphony.xwork2.inject.Inject; +import com.opensymphony.xwork2.validator.ActionValidatorManager; /** * ListValidatorsAction loads the validations for a given class and context @@ -40,7 +41,14 @@ public class ListValidatorsAction extends ActionSupport { private String clazz; private String context; List validators = Collections.EMPTY_LIST; + private ActionValidatorManager actionValidatorManager; + + @Inject + public void setActionValidatorManager(ActionValidatorManager mgr) { + this.actionValidatorManager = mgr; + } + public String getClazz() { return clazz; } @@ -77,7 +85,7 @@ public class ListValidatorsAction extends ActionSupport { protected void loadValidators() { Class value = getClassInstance(); if ( value != null ) { - validators = ActionValidatorManagerFactory.getInstance().getValidators(value, context); + validators = actionValidatorManager.getValidators(value, context); } } diff --git a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConfigAction.java b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConfigAction.java index 9b59b4293..7cc3539fc 100644 --- a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConfigAction.java +++ b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConfigAction.java @@ -24,8 +24,6 @@ import java.beans.PropertyDescriptor; import java.util.Set; import java.util.TreeSet; -import ognl.OgnlRuntime; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -33,6 +31,7 @@ import com.opensymphony.xwork2.ObjectFactory; import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.entities.ActionConfig; import com.opensymphony.xwork2.inject.Inject; +import com.opensymphony.xwork2.util.reflection.ReflectionProvider; /** * ShowConfigAction @@ -53,6 +52,7 @@ public class ShowConfigAction extends ActionNamesAction { private ConfigurationHelper configHelper; private ObjectFactory objectFactory; + private ReflectionProvider reflectionProvider; public String getDetailView() { return detailView; @@ -79,6 +79,11 @@ public class ShowConfigAction extends ActionNamesAction { public void setObjectFactory(ObjectFactory fac) { this.objectFactory = fac; } + + @Inject + public void setReflectionProvider(ReflectionProvider prov) { + this.reflectionProvider = prov; + } public String stripPackage(Class clazz) { return clazz.getName().substring(clazz.getName().lastIndexOf('.') + 1); @@ -111,8 +116,7 @@ public class ShowConfigAction extends ActionNamesAction { new TreeSet(configHelper.getActionNames(namespace)); try { Class clazz = objectFactory.getClassInstance(getConfig().getClassName()); - java.util.Collection pds = OgnlRuntime.getPropertyDescriptors(clazz).values(); - properties = (PropertyDescriptor[]) pds.toArray(PDSAT); + properties = reflectionProvider.getPropertyDescriptors(clazz); } catch (Exception e) { log.error("Unable to get properties for action " + actionName, e); addActionError("Unable to retrieve action properties: " + e.toString()); diff --git a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowValidatorAction.java b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowValidatorAction.java index 94252e508..4c4db8d9c 100644 --- a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowValidatorAction.java +++ b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowValidatorAction.java @@ -29,13 +29,13 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; -import ognl.Ognl; -import ognl.OgnlException; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import com.opensymphony.xwork2.util.OgnlUtil; +import com.opensymphony.xwork2.inject.Inject; +import com.opensymphony.xwork2.util.reflection.ReflectionContextFactory; +import com.opensymphony.xwork2.util.reflection.ReflectionException; +import com.opensymphony.xwork2.util.reflection.ReflectionProvider; import com.opensymphony.xwork2.validator.Validator; /** @@ -49,7 +49,20 @@ public class ShowValidatorAction extends ListValidatorsAction { Set properties = Collections.EMPTY_SET; int selected = 0; + + ReflectionProvider reflectionProvider; + ReflectionContextFactory reflectionContextFactory; + @Inject + public void setReflectionProvider(ReflectionProvider prov) { + this.reflectionProvider = prov; + } + + @Inject + public void setReflectionContextFactory(ReflectionContextFactory fac) { + this.reflectionContextFactory = fac; + } + public int getSelected() { return selected; } @@ -71,7 +84,7 @@ public class ShowValidatorAction extends ListValidatorsAction { Validator validator = getSelectedValidator(); properties = new TreeSet(); try { - Map context = Ognl.createDefaultContext(validator); + Map context = reflectionContextFactory.createDefaultContext(validator); BeanInfo beanInfoFrom = null; try { beanInfoFrom = Introspector.getBeanInfo(validator.getClass(), Object.class); @@ -91,10 +104,9 @@ public class ShowValidatorAction extends ListValidatorsAction { value = "No read method for property"; } else { try { - Object expr = OgnlUtil.compile(name); - value = Ognl.getValue(expr, context, validator); - } catch (OgnlException e) { - addActionError("Caught OGNL exception while getting property value for '" + name + "' on validator of type " + validator.getClass().getName()); + value = reflectionProvider.getValue(name, context, validator); + } catch (ReflectionException e) { + addActionError("Caught exception while getting property value for '" + name + "' on validator of type " + validator.getClass().getName()); } } properties.add(new PropertyInfo(name, pd.getPropertyType(), value)); diff --git a/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/AbstractTagTest.java b/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/AbstractTagTest.java index 72ba0a684..fabbf82e5 100644 --- a/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/AbstractTagTest.java +++ b/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/AbstractTagTest.java @@ -83,7 +83,7 @@ public abstract class AbstractTagTest extends StrutsTestCase { * create our standard mock objects */ action = this.getAction(); - stack = ValueStackFactory.getFactory().createValueStack(); + stack = ActionContext.getContext().getValueStack(); context = stack.getContext(); stack.push(action); context.put(Head.PARSE_CONTENT, false); diff --git a/plugins/jsf/src/main/java/org/apache/struts2/jsf/StrutsVariableResolver.java b/plugins/jsf/src/main/java/org/apache/struts2/jsf/StrutsVariableResolver.java index 425acc57f..04e488865 100644 --- a/plugins/jsf/src/main/java/org/apache/struts2/jsf/StrutsVariableResolver.java +++ b/plugins/jsf/src/main/java/org/apache/struts2/jsf/StrutsVariableResolver.java @@ -24,7 +24,7 @@ import javax.faces.context.FacesContext; import javax.faces.el.EvaluationException; import javax.faces.el.VariableResolver; -import com.opensymphony.xwork2.util.OgnlValueStack; +import com.opensymphony.xwork2.ognl.OgnlValueStack; import com.opensymphony.xwork2.ActionContext; /** diff --git a/plugins/plexus/src/main/java/org/apache/struts2/plexus/PlexusObjectFactory.java b/plugins/plexus/src/main/java/org/apache/struts2/plexus/PlexusObjectFactory.java index 78f0d105f..adaf10faf 100644 --- a/plugins/plexus/src/main/java/org/apache/struts2/plexus/PlexusObjectFactory.java +++ b/plugins/plexus/src/main/java/org/apache/struts2/plexus/PlexusObjectFactory.java @@ -38,7 +38,6 @@ import com.opensymphony.xwork2.config.entities.InterceptorConfig; import com.opensymphony.xwork2.config.entities.ResultConfig; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.interceptor.Interceptor; -import com.opensymphony.xwork2.util.OgnlUtil; import com.opensymphony.xwork2.validator.Validator; /** @@ -144,7 +143,7 @@ public class PlexusObjectFactory extends ObjectFactory { Map extraContext = new HashMap(); extraContext.put(PLEXUS_COMPONENT_TYPE, Interceptor.class.getName()); Interceptor interceptor = (Interceptor) buildBean(interceptorClassName, extraContext); - OgnlUtil.setProperties(params, interceptor); + reflectionProvider.setProperties(params, interceptor); interceptor.init(); return interceptor; @@ -195,7 +194,7 @@ public class PlexusObjectFactory extends ObjectFactory { Map context = new HashMap(); context.put(PLEXUS_COMPONENT_TYPE, Validator.class.getName()); Validator validator = (Validator) buildBean(className, context); - OgnlUtil.setProperties(params, validator); + reflectionProvider.setProperties(params, validator); return validator; } diff --git a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/TemplatePageFilter.java b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/TemplatePageFilter.java index e6cc9fc80..5133e8e6c 100644 --- a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/TemplatePageFilter.java +++ b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/TemplatePageFilter.java @@ -43,7 +43,9 @@ import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.Result; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.interceptor.PreResultListener; -import com.opensymphony.xwork2.util.OgnlValueStack; +import com.opensymphony.xwork2.ognl.OgnlValueStack; +import com.opensymphony.xwork2.util.ValueStack; +import com.opensymphony.xwork2.util.ValueStackFactory; /** * An abstract template page filter that sets up the proper contexts for @@ -97,8 +99,8 @@ public abstract class TemplatePageFilter extends PageFilter { ServletContext servletContext = filterConfig.getServletContext(); ActionContext ctx = ServletActionContext.getActionContext(req); if (ctx == null) { - // ok, one isn't associated with the request, so let's get a ThreadLocal one (which will create one if needed) - OgnlValueStack vs = new OgnlValueStack(); + // ok, one isn't associated with the request, so let's create one using the current Dispatcher + ValueStack vs = Dispatcher.getInstance().getContainer().getInstance(ValueStackFactory.class).createValueStack(); vs.getContext().putAll(Dispatcher.getInstance().createContextMap(req, res, null, servletContext)); ctx = new ActionContext(vs.getContext()); if (ctx.getActionInvocation() == null) { @@ -165,7 +167,7 @@ public abstract class TemplatePageFilter extends PageFilter { public void setResultCode(String resultCode) { } - public OgnlValueStack getStack() { + public ValueStack getStack() { return null; } @@ -182,5 +184,8 @@ public abstract class TemplatePageFilter extends PageFilter { public void setActionEventListener(ActionEventListener listener) { } + + public void init(ActionProxy proxy) throws Exception { + } } } diff --git a/plugins/struts1/src/main/java/org/apache/struts2/s1/Struts1Action.java b/plugins/struts1/src/main/java/org/apache/struts2/s1/Struts1Action.java index 99d817e37..25c18e88a 100644 --- a/plugins/struts1/src/main/java/org/apache/struts2/s1/Struts1Action.java +++ b/plugins/struts1/src/main/java/org/apache/struts2/s1/Struts1Action.java @@ -38,6 +38,7 @@ import org.apache.struts2.dispatcher.Dispatcher; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ObjectFactory; import com.opensymphony.xwork2.config.entities.ActionConfig; +import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.interceptor.ScopedModelDriven; /** @@ -61,13 +62,19 @@ public class Struts1Action extends DefaultActionSupport implements ScopedModelDr private String className; private boolean validate; private String scopeKey; + private ObjectFactory objectFactory; + + @Inject + public void setObjectFactory(ObjectFactory fac) { + this.objectFactory = fac; + } public String execute() throws Exception { ActionContext ctx = ActionContext.getContext(); ActionConfig actionConfig = ctx.getActionInvocation().getProxy().getConfig(); Action action = null; try { - action = (Action) ObjectFactory.getObjectFactory().buildBean(className, null); + action = (Action) objectFactory.buildBean(className, null); } catch (Exception e) { throw new StrutsException("Unable to create the legacy Struts Action", e, actionConfig); }