Author: mrdon Date: Mon Sep 24 17:07:19 2007 New Revision: 579021 URL: http://svn.apache.org/viewvc?rev=579021&view=rev Log: Better handling of action context creation WW-2203
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StrutsRequestWrapper.java Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java?rev=579021&r1=579020&r2=579021&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java Mon Sep 24 17:07:19 2007 @@ -162,7 +162,11 @@ @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; + } } Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java?rev=579021&r1=579020&r2=579021&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java Mon Sep 24 17:07:19 2007 @@ -52,6 +52,8 @@ 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 @@ 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; Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StrutsRequestWrapper.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StrutsRequestWrapper.java?rev=579021&r1=579020&r2=579021&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StrutsRequestWrapper.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StrutsRequestWrapper.java Mon Sep 24 17:07:19 2007 @@ -62,26 +62,27 @@ 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); } } }