Skip to content

Commit

Permalink
WW-4789 WW-3788 Avoids unneeded binds to ThreadLocal
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Apr 13, 2020
1 parent c253b7f commit 6279e6d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 46 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/com/opensymphony/xwork2/ActionContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public Map<String, Object> getApplication() {
* @return the context map.
*/
public Map<String, Object> getContextMap() {
return getContext().context;
return context;
}

/**
Expand Down Expand Up @@ -524,7 +524,7 @@ public ActionContext usePageContextOrClear(ActionContext actionContext) {

public ActionContext withExtraContext(Map<String, Object> extraContext) {
if (extraContext != null) {
getContext().context.putAll(extraContext);
context.putAll(extraContext);
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ protected void createAction(Map<String, Object> contextMap) {
}

protected Map<String, Object> createContextMap() {
ActionContext oldContext = ActionContext.getContext();
ActionContext actionContext;

if (extraContext != null && extraContext.containsKey(ActionContext.VALUE_STACK)) {
Expand All @@ -345,20 +344,11 @@ protected Map<String, Object> createContextMap() {
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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,40 +64,20 @@ public ValueStack createValueStack() {
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
Expand Down

0 comments on commit 6279e6d

Please sign in to comment.