WW-4789 WW-3788 Avoids unneeded binds to ThreadLocal

This commit is contained in:
Lukasz Lenart
2020-04-13 09:47:19 +02:00
parent c253b7f480
commit 6279e6dd16
3 changed files with 15 additions and 46 deletions
@@ -242,7 +242,7 @@ public class ActionContext implements Serializable {
* @return the context map.
*/
public Map<String, Object> getContextMap() {
return getContext().context;
return context;
}
/**
@@ -524,7 +524,7 @@ public class ActionContext implements Serializable {
public ActionContext withExtraContext(Map<String, Object> extraContext) {
if (extraContext != null) {
getContext().context.putAll(extraContext);
context.putAll(extraContext);
}
return this;
}
@@ -324,7 +324,6 @@ public class DefaultActionInvocation implements ActionInvocation {
}
protected Map<String, Object> createContextMap() {
ActionContext oldContext = ActionContext.getContext();
ActionContext actionContext;
if (extraContext != null && extraContext.containsKey(ActionContext.VALUE_STACK)) {
@@ -345,20 +344,11 @@ public class DefaultActionInvocation implements ActionInvocation {
actionContext = stack.getActionContext();
}
try {
return actionContext
.bind()
.withExtraContext(extraContext)
.withActionInvocation(this)
.withContainer(container)
.getContextMap();
} finally {
ActionContext.clear();
if (oldContext != null) {
LOG.debug("Re-binding the old context");
oldContext.bind();
}
}
return actionContext
.withExtraContext(extraContext)
.withActionInvocation(this)
.withContainer(container)
.getContextMap();
}
/**
@@ -18,7 +18,6 @@
*/
package com.opensymphony.xwork2.ognl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.TextProvider;
import com.opensymphony.xwork2.conversion.NullHandler;
import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
@@ -65,40 +64,20 @@ public class OgnlValueStackFactory implements ValueStackFactory {
ValueStack stack = new OgnlValueStack(xworkConverter, compoundRootAccessor, textProvider,
containerAllowsStaticMethodAccess(), containerAllowsStaticFieldAccess());
container.inject(stack);
ActionContext oldContext = ActionContext.getContext();
try {
return stack.getActionContext()
.bind()
.withContainer(container)
.withValueStack(stack)
.getValueStack();
} finally {
ActionContext.clear();
if (oldContext != null) {
LOG.debug("Re-binding the old context");
oldContext.bind();
}
}
return stack.getActionContext()
.withContainer(container)
.withValueStack(stack)
.getValueStack();
}
public ValueStack createValueStack(ValueStack stack) {
ValueStack result = new OgnlValueStack(stack, xworkConverter, compoundRootAccessor,
containerAllowsStaticMethodAccess(), containerAllowsStaticFieldAccess());
container.inject(result);
ActionContext oldContext = ActionContext.getContext();
try {
return result.getActionContext()
.bind()
.withContainer(container)
.withValueStack(result)
.getValueStack();
} finally {
ActionContext.clear();
if (oldContext != null) {
LOG.debug("Re-binding the old context");
oldContext.bind();
}
}
return result.getActionContext()
.withContainer(container)
.withValueStack(result)
.getValueStack();
}
@Inject