diff --git a/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java b/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java index 47bfb5a79..4e6042cba 100644 --- a/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java +++ b/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java @@ -162,7 +162,11 @@ public class StrutsXmlConfigurationProvider extends XmlConfigurationProvider { @Override public boolean needsReload() { ActionContext ctx = ActionContext.getContext(); - return ctx.get(reloadKey) == null && super.needsReload(); + if (ctx != null) { + return ctx.get(reloadKey) == null && super.needsReload(); + } else { + return true; + } } 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 41d7ca0ee..e5781d78f 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java @@ -52,6 +52,8 @@ import org.apache.struts2.dispatcher.mapper.ActionMapping; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.ClassLoaderUtil; +import com.opensymphony.xwork2.util.ValueStack; +import com.opensymphony.xwork2.util.ValueStackFactory; import com.opensymphony.xwork2.util.profiling.UtilTimerStack; import com.opensymphony.xwork2.ActionContext; @@ -386,6 +388,12 @@ public class FilterDispatcher implements StrutsStatics, Filter { String timerKey = "FilterDispatcher_doFilter: "; try { + + // FIXME: this should be refactored better to not duplicate work with the action invocation + ValueStack stack = dispatcher.getContainer().getInstance(ValueStackFactory.class).createValueStack(); + ActionContext ctx = new ActionContext(stack.getContext()); + ActionContext.setContext(ctx); + UtilTimerStack.push(timerKey); request = prepareDispatcherAndWrapRequest(request, response); ActionMapping mapping; diff --git a/core/src/main/java/org/apache/struts2/dispatcher/StrutsRequestWrapper.java b/core/src/main/java/org/apache/struts2/dispatcher/StrutsRequestWrapper.java index 75eb4a0c2..3292c75b7 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/StrutsRequestWrapper.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/StrutsRequestWrapper.java @@ -62,26 +62,27 @@ public class StrutsRequestWrapper extends HttpServletRequestWrapper { ActionContext ctx = ActionContext.getContext(); Object attribute = super.getAttribute(s); - - if (attribute == null) { - boolean alreadyIn = false; - Boolean b = (Boolean) ctx.get("__requestWrapper.getAttribute"); - if (b != null) { - alreadyIn = b.booleanValue(); - } - - // note: we don't let # come through or else a request for - // #attr.foo or #request.foo could cause an endless loop - if (!alreadyIn && s.indexOf("#") == -1) { - try { - // If not found, then try the ValueStack - ctx.put("__requestWrapper.getAttribute", Boolean.TRUE); - ValueStack stack = ctx.getValueStack(); - if (stack != null) { - attribute = stack.findValue(s); + if (ctx != null) { + if (attribute == null) { + boolean alreadyIn = false; + Boolean b = (Boolean) ctx.get("__requestWrapper.getAttribute"); + if (b != null) { + alreadyIn = b.booleanValue(); + } + + // note: we don't let # come through or else a request for + // #attr.foo or #request.foo could cause an endless loop + if (!alreadyIn && s.indexOf("#") == -1) { + try { + // If not found, then try the ValueStack + ctx.put("__requestWrapper.getAttribute", Boolean.TRUE); + ValueStack stack = ctx.getValueStack(); + if (stack != null) { + attribute = stack.findValue(s); + } + } finally { + ctx.put("__requestWrapper.getAttribute", Boolean.FALSE); } - } finally { - ctx.put("__requestWrapper.getAttribute", Boolean.FALSE); } } }