You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2014/04/26 07:03:54 UTC
[1/3] git commit: Includes check for braces in expression
Repository: struts
Updated Branches:
refs/heads/feature/exclude-object-class aff3a3a62 -> 5d8aa8a80
Includes check for braces in expression
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/58a58615
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/58a58615
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/58a58615
Branch: refs/heads/feature/exclude-object-class
Commit: 58a58615cf45c669800deafd462f7c427b677caf
Parents: aff3a3a
Author: Lukasz Lenart <lu...@apache.org>
Authored: Sat Apr 26 06:57:42 2014 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Sat Apr 26 06:57:42 2014 +0200
----------------------------------------------------------------------
.../src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts/blob/58a58615/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java
index a0231bc..81f9700 100644
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java
@@ -309,7 +309,8 @@ public class OgnlUtil {
if (tree instanceof SimpleNode) {
SimpleNode node = (SimpleNode) tree;
for (String excludedPattern : excludedProperties) {
- if (excludedPattern.equalsIgnoreCase(node.toString())) {
+ // TODO lukaszlenart: need a better way to check 'toString' and 'toString()' call
+ if (excludedPattern.equalsIgnoreCase(node.toString()) || (excludedPattern + "()").equalsIgnoreCase(node.toString())) {
throw new OgnlException("Tree [" + (parent != null ? parent : tree) + "] trying access excluded pattern [" + excludedPattern + "]");
}
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
[2/3] git commit: Uses OgnlUtil to execute action/method instead of
Reflection
Posted by lu...@apache.org.
Uses OgnlUtil to execute action/method instead of Reflection
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/bcc0327e
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/bcc0327e
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/bcc0327e
Branch: refs/heads/feature/exclude-object-class
Commit: bcc0327ee49c60b10d158354c0d1be06eb8a9f52
Parents: 58a5861
Author: Lukasz Lenart <lu...@apache.org>
Authored: Sat Apr 26 06:58:50 2014 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Sat Apr 26 06:58:50 2014 +0200
----------------------------------------------------------------------
.../xwork2/DefaultActionInvocation.java | 54 +++++++-------------
1 file changed, 18 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts/blob/bcc0327e/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java b/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
index 531a725..4539e56 100644
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
@@ -22,14 +22,14 @@ import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.interceptor.PreResultListener;
+import com.opensymphony.xwork2.ognl.OgnlUtil;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import com.opensymphony.xwork2.util.profiling.UtilTimerStack;
+import ognl.OgnlException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -46,18 +46,8 @@ import java.util.Map;
*/
public class DefaultActionInvocation implements ActionInvocation {
- private static final long serialVersionUID = -585293628862447329L;
-
- //static {
- // if (ObjectFactory.getContinuationPackage() != null) {
- // continuationHandler = new ContinuationHandler();
- // }
- //}
private static final Logger LOG = LoggerFactory.getLogger(DefaultActionInvocation.class);
- private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
- private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
-
protected Object action;
protected ActionProxy proxy;
protected List<PreResultListener> preResultListeners;
@@ -75,6 +65,7 @@ public class DefaultActionInvocation implements ActionInvocation {
protected ValueStackFactory valueStackFactory;
protected Container container;
protected UnknownHandlerManager unknownHandlerManager;
+ protected OgnlUtil ognlUtil;
public DefaultActionInvocation(final Map<String, Object> extraContext, final boolean pushAction) {
this.extraContext = extraContext;
@@ -106,6 +97,11 @@ public class DefaultActionInvocation implements ActionInvocation {
this.actionEventListener = listener;
}
+ @Inject
+ public void setOgnlUtil(OgnlUtil ognlUtil) {
+ this.ognlUtil = ognlUtil;
+ }
+
public Object getAction() {
return action;
}
@@ -420,22 +416,19 @@ public class DefaultActionInvocation implements ActionInvocation {
try {
UtilTimerStack.push(timerKey);
- boolean methodCalled = false;
- Object methodResult = null;
- Method method = null;
+ Object methodResult;
try {
- method = getAction().getClass().getMethod(methodName, EMPTY_CLASS_ARRAY);
- } catch (NoSuchMethodException e) {
+ methodResult = ognlUtil.getValue(methodName + "()", getStack().getContext(), action);
+ } catch (OgnlException e) {
// hmm -- OK, try doXxx instead
try {
- String altMethodName = "do" + methodName.substring(0, 1).toUpperCase() + methodName.substring(1);
- method = getAction().getClass().getMethod(altMethodName, EMPTY_CLASS_ARRAY);
- } catch (NoSuchMethodException e1) {
+ String altMethodName = "do" + methodName.substring(0, 1).toUpperCase() + methodName.substring(1) + "()";
+ methodResult = ognlUtil.getValue(altMethodName, ActionContext.getContext().getContextMap(), action);
+ } catch (OgnlException e1) {
// well, give the unknown handler a shot
if (unknownHandlerManager.hasUnknownHandlers()) {
try {
methodResult = unknownHandlerManager.handleUnknownMethod(action, methodName);
- methodCalled = true;
} catch (NoSuchMethodException e2) {
// throw the original one
throw e;
@@ -445,29 +438,18 @@ public class DefaultActionInvocation implements ActionInvocation {
}
}
}
-
- if (!methodCalled) {
- methodResult = method.invoke(action, EMPTY_OBJECT_ARRAY);
- }
-
return saveResult(actionConfig, methodResult);
- } catch (NoSuchMethodException e) {
- throw new IllegalArgumentException("The " + methodName + "() is not defined in action " + getAction().getClass() + "");
- } catch (InvocationTargetException e) {
+ } catch (OgnlException e) {
// We try to return the source exception.
- Throwable t = e.getTargetException();
+ //Throwable t = e.getTargetException();
if (actionEventListener != null) {
- String result = actionEventListener.handleException(t, getStack());
+ String result = actionEventListener.handleException(e, getStack());
if (result != null) {
return result;
}
}
- if (t instanceof Exception) {
- throw (Exception) t;
- } else {
- throw e;
- }
+ throw e;
} finally {
UtilTimerStack.pop(timerKey);
}
[3/3] git commit: Updates tests as using Object's methods is
prohibited
Posted by lu...@apache.org.
Updates tests as using Object's methods is prohibited
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/5d8aa8a8
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/5d8aa8a8
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/5d8aa8a8
Branch: refs/heads/feature/exclude-object-class
Commit: 5d8aa8a80be131dbcf412c28aec0435d3bdc23e3
Parents: bcc0327
Author: Lukasz Lenart <lu...@apache.org>
Authored: Sat Apr 26 06:59:18 2014 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Sat Apr 26 06:59:18 2014 +0200
----------------------------------------------------------------------
.../ExecuteAndWaitInterceptorTest.java | 2 ++
.../struts2/views/jsp/PropertyTagTest.java | 30 ++++++++++++--------
.../apache/struts2/views/jsp/ui/SelectTest.java | 2 +-
.../struts2/rest/RestActionInvocationTest.java | 2 ++
.../xwork2/DefaultActionInvocationTest.java | 8 ++++++
5 files changed, 31 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts/blob/5d8aa8a8/core/src/test/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptorTest.java
index 01d1a6e..5a01015 100644
--- a/core/src/test/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptorTest.java
+++ b/core/src/test/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptorTest.java
@@ -32,6 +32,7 @@ import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.inject.ContainerBuilder;
import com.opensymphony.xwork2.interceptor.ParametersInterceptor;
import com.opensymphony.xwork2.mock.MockResult;
+import com.opensymphony.xwork2.ognl.OgnlUtil;
import com.opensymphony.xwork2.util.location.LocatableProperties;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsInternalTestCase;
@@ -222,6 +223,7 @@ public class ExecuteAndWaitInterceptorTest extends StrutsInternalTestCase {
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
builder.factory(ObjectFactory.class);
builder.factory(ActionProxyFactory.class, DefaultActionProxyFactory.class);
+ builder.factory(OgnlUtil.class, OgnlUtil.class);
}
}
http://git-wip-us.apache.org/repos/asf/struts/blob/5d8aa8a8/core/src/test/java/org/apache/struts2/views/jsp/PropertyTagTest.java
----------------------------------------------------------------------
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 cce9a0c..a2b77ba 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
@@ -180,11 +180,13 @@ public class PropertyTagTest extends StrutsInternalTestCase {
pageContext.setRequest(request);
// test
- {PropertyTag tag = new PropertyTag();
- tag.setPageContext(pageContext);
- tag.setValue("%{toString()}");
- tag.doStartTag();
- tag.doEndTag();}
+ {
+ PropertyTag tag = new PropertyTag();
+ tag.setPageContext(pageContext);
+ tag.setValue("%{formatTitle()}");
+ tag.doStartTag();
+ tag.doEndTag();
+ }
// verify test
request.verify();
@@ -212,7 +214,7 @@ public class PropertyTagTest extends StrutsInternalTestCase {
tag.setEscape(false);
tag.setEscapeJavaScript(true);
tag.setPageContext(pageContext);
- tag.setValue("%{toString()}");
+ tag.setValue("%{formatTitle()}");
tag.doStartTag();
tag.doEndTag();}
@@ -242,7 +244,7 @@ public class PropertyTagTest extends StrutsInternalTestCase {
tag.setEscape(false);
tag.setEscapeXml(true);
tag.setPageContext(pageContext);
- tag.setValue("%{toString()}");
+ tag.setValue("%{formatTitle()}");
tag.doStartTag();
tag.doEndTag();}
@@ -272,7 +274,7 @@ public class PropertyTagTest extends StrutsInternalTestCase {
tag.setEscape(false);
tag.setEscapeCsv(true);
tag.setPageContext(pageContext);
- tag.setValue("%{toString()}");
+ tag.setValue("%{formatTitle()}");
tag.doStartTag();
tag.doEndTag();}
@@ -300,7 +302,7 @@ public class PropertyTagTest extends StrutsInternalTestCase {
// test
{PropertyTag tag = new PropertyTag();
tag.setPageContext(pageContext);
- tag.setValue("toString()");
+ tag.setValue("formatTitle()");
tag.doStartTag();
tag.doEndTag();}
@@ -328,7 +330,7 @@ public class PropertyTagTest extends StrutsInternalTestCase {
// test
{PropertyTag tag = new PropertyTag();
tag.setPageContext(pageContext);
- tag.setValue("toString()");
+ tag.setValue("formatTitle()");
tag.doStartTag();
tag.doEndTag();}
@@ -356,7 +358,7 @@ public class PropertyTagTest extends StrutsInternalTestCase {
// test
{PropertyTag tag = new PropertyTag();
tag.setPageContext(pageContext);
- tag.setValue("%{toString()}");
+ tag.setValue("%{formatTitle()}");
tag.doStartTag();
tag.doEndTag();}
@@ -385,8 +387,12 @@ public class PropertyTagTest extends StrutsInternalTestCase {
return title;
}
- public String toString() {
+ public String formatTitle() {
return "Foo is: " + title;
}
+
+ public String toString() {
+ return formatTitle();
+ }
}
}
http://git-wip-us.apache.org/repos/asf/struts/blob/5d8aa8a8/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java
index 094cfc9..06b7e80 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java
@@ -494,7 +494,7 @@ public class SelectTest extends AbstractUITagTest {
tag.setList("list2");
tag.setListKey("id");
tag.setListValue("name");
- tag.setValue("fooInt.toString()");
+ tag.setValue("fooInt");
// header stuff
tag.setHeaderKey("headerKey");
http://git-wip-us.apache.org/repos/asf/struts/blob/5d8aa8a8/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java
----------------------------------------------------------------------
diff --git a/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java b/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java
index af2a7fd..6db05f1 100644
--- a/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java
+++ b/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java
@@ -10,6 +10,7 @@ import com.opensymphony.xwork2.config.entities.InterceptorMapping;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.mock.MockActionProxy;
import com.opensymphony.xwork2.mock.MockInterceptor;
+import com.opensymphony.xwork2.ognl.OgnlUtil;
import com.opensymphony.xwork2.util.XWorkTestCaseHelper;
import junit.framework.TestCase;
import org.apache.struts2.ServletActionContext;
@@ -228,6 +229,7 @@ public class RestActionInvocationTest extends TestCase {
request.setMethod("GET");
+ restActionInvocation.setOgnlUtil(new OgnlUtil());
restActionInvocation.invoke();
assertEquals(123, response.getStatus());
http://git-wip-us.apache.org/repos/asf/struts/blob/5d8aa8a8/xwork-core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java b/xwork-core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java
index 1b93a5c..e0aa8ba 100644
--- a/xwork-core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java
+++ b/xwork-core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java
@@ -1,9 +1,14 @@
package com.opensymphony.xwork2;
+import com.mockobjects.dynamic.Mock;
import com.opensymphony.xwork2.config.entities.InterceptorMapping;
import com.opensymphony.xwork2.mock.MockActionProxy;
import com.opensymphony.xwork2.mock.MockContainer;
import com.opensymphony.xwork2.mock.MockInterceptor;
+import com.opensymphony.xwork2.ognl.OgnlUtil;
+import com.opensymphony.xwork2.util.ValueStackFactory;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
import java.util.ArrayList;
import java.util.HashMap;
@@ -39,6 +44,9 @@ public class DefaultActionInvocationTest extends XWorkTestCase {
mockInterceptor3.setExpectedFoo("test3");
DefaultActionInvocation defaultActionInvocation = new DefaultActionInvocationTester(interceptorMappings);
+ container.inject(defaultActionInvocation);
+ defaultActionInvocation.stack = container.getInstance(ValueStackFactory.class).createValueStack();
+
defaultActionInvocation.invoke();
assertTrue(mockInterceptor1.isExecuted());
assertTrue(mockInterceptor2.isExecuted());