You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2014/02/01 17:02:46 UTC
svn commit: r1563435 - in /tomee/tomee/trunk/container/openejb-core/src:
main/java/org/apache/openejb/config/rules/
main/resources/org/apache/openejb/config/rules/
test/java/org/apache/openejb/config/rules/
Author: dblevins
Date: Sat Feb 1 16:02:46 2014
New Revision: 1563435
URL: http://svn.apache.org/r1563435
Log:
Patch from Ivan St. Ivanov, OPENEJB-678: Validation: Explicit check for InvocationContext incorrectly used in bean callbacks
Thanks, Ivan!
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java
tomee/tomee/trunk/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidCallbacksTest.java
Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java?rev=1563435&r1=1563434&r2=1563435&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java Sat Feb 1 16:02:46 2014
@@ -341,7 +341,13 @@ public class CheckCallbacks extends Vali
if (possibleMethods.size() == 0) {
fail(bean, "callback.missing", type, callback.getMethodName(), callback.getClassName());
} else if (possibleMethods.size() == 1) {
- fail(bean, "callback.invalidArguments", type, callback.getMethodName(), getParameters(possibleMethods.get(0)), callback.getClassName(), getParameters(parameterTypes));
+ Class<?>[] parameters = possibleMethods.get(0).getParameterTypes();
+ if (parameters.length == 1 && parameters[0].equals(InvocationContext.class)) {
+ fail(bean.getEjbName(), "callback.invocationcontext.notallowed", type,
+ callback.getMethodName());
+ } else {
+ fail(bean, "callback.invalidArguments", type, callback.getMethodName(), getParameters(possibleMethods.get(0)), callback.getClassName(), getParameters(parameterTypes));
+ }
} else {
fail(bean, "callback.missing.possibleTypo", type, callback.getMethodName(), possibleMethods.size(), callback.getClassName(), getParameters(parameterTypes));
}
Modified: tomee/tomee/trunk/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties?rev=1563435&r1=1563434&r2=1563435&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties Sat Feb 1 16:02:46 2014
@@ -199,6 +199,11 @@
2.callback.missing = {0} method missing: "{1}" in class {2}
3.callback.missing = {0} method "{1}" not found in class {2}. The required method signature is "void {1}()"
+# fail(bean, "callback.invocationcontext.notallowed", type, callback.getMethodName())
+1.callback.invocationcontext.notallowed = Invalid usage of javax.interceptor.InvocationContext as parameter type of callback method
+2.callback.invocationcontext.notallowed = Invalid usage of javax.interceptor.InvocationContext as parameter type of callback method in bean class {0}
+3.callback.invocationcontext.notallowed = Invalid usage of javax.interceptor.InvocationContext as parameter type of callback method {1} in bean class {0}. Parameters of type InvocationContext are only allowed for interceptors
+
# fail(bean, "callback.invalidArguments", type, callback.getMethodName(), getParameters(possibleMethods.get(0)), callback.getClassName());
1.callback.invalidArguments = Invalid {0} arguments
2.callback.invalidArguments = Invalid {0} arguments. Found: {1}({2}). Required: {1}({4})
Modified: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidCallbacksTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidCallbacksTest.java?rev=1563435&r1=1563434&r2=1563435&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidCallbacksTest.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidCallbacksTest.java Sat Feb 1 16:02:46 2014
@@ -17,6 +17,7 @@
package org.apache.openejb.config.rules;
import junit.framework.TestCase;
+
import org.apache.openejb.jee.EjbJar;
import org.apache.openejb.jee.NamedMethod;
import org.apache.openejb.jee.SingletonBean;
@@ -38,6 +39,8 @@ import javax.ejb.PrePassivate;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.SessionSynchronization;
+import javax.interceptor.InvocationContext;
+
import java.rmi.RemoteException;
import java.util.concurrent.Callable;
@@ -85,6 +88,13 @@ public class CheckInvalidCallbacksTest e
return ejbJar;
}
+ @Keys(@Key(value = "callback.invocationcontext.notallowed", count = 4))
+ public EjbJar test3() {
+ EjbJar ejbJar = new EjbJar();
+ ejbJar.addEnterpriseBean(new StatefulBean(CallbackViolatorBean.class));
+ return ejbJar;
+ }
+
public static class TestBean implements Callable {
public Object call() throws Exception {
return null;
@@ -252,4 +262,22 @@ public class CheckInvalidCallbacksTest e
@AfterCompletion
public void afterCompletion(boolean committed) {}
}
+
+ public class CallbackViolatorBean {
+ @PostConstruct
+ public void postConstruct(InvocationContext ic) {
+ }
+
+ @PreDestroy
+ public void preDestroy(InvocationContext ic) {
+ }
+
+ @PrePassivate
+ public void prePassivate(InvocationContext ic) {
+ }
+
+ @PostActivate
+ public void postActivate(InvocationContext ic) {
+ }
+ }
}
\ No newline at end of file
Fwd: svn commit: r1563435 - in /tomee/tomee/trunk/container/openejb-core/src:
main/java/org/apache/openejb/config/rules/ main/resources/org/apache/openejb/config/rules/
test/java/org/apache/openejb/config/rules/
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Don't we make more generic saying "this parameter type xxx is not
allowed for this callback"?
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
---------- Forwarded message ----------
From: <db...@apache.org>
Date: 2014-02-01
Subject: svn commit: r1563435 - in
/tomee/tomee/trunk/container/openejb-core/src:
main/java/org/apache/openejb/config/rules/
main/resources/org/apache/openejb/config/rules/
test/java/org/apache/openejb/config/rules/
To: commits@tomee.apache.org
Author: dblevins
Date: Sat Feb 1 16:02:46 2014
New Revision: 1563435
URL: http://svn.apache.org/r1563435
Log:
Patch from Ivan St. Ivanov, OPENEJB-678: Validation: Explicit check
for InvocationContext incorrectly used in bean callbacks
Thanks, Ivan!
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java
tomee/tomee/trunk/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidCallbacksTest.java
Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java?rev=1563435&r1=1563434&r2=1563435&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java
Sat Feb 1 16:02:46 2014
@@ -341,7 +341,13 @@ public class CheckCallbacks extends Vali
if (possibleMethods.size() == 0) {
fail(bean, "callback.missing", type,
callback.getMethodName(), callback.getClassName());
} else if (possibleMethods.size() == 1) {
- fail(bean, "callback.invalidArguments", type,
callback.getMethodName(), getParameters(possibleMethods.get(0)),
callback.getClassName(), getParameters(parameterTypes));
+ Class<?>[] parameters =
possibleMethods.get(0).getParameterTypes();
+ if (parameters.length == 1 &&
parameters[0].equals(InvocationContext.class)) {
+ fail(bean.getEjbName(),
"callback.invocationcontext.notallowed", type,
+ callback.getMethodName());
+ } else {
+ fail(bean, "callback.invalidArguments", type,
callback.getMethodName(), getParameters(possibleMethods.get(0)),
callback.getClassName(), getParameters(parameterTypes));
+ }
} else {
fail(bean, "callback.missing.possibleTypo", type,
callback.getMethodName(), possibleMethods.size(),
callback.getClassName(), getParameters(parameterTypes));
}
Modified: tomee/tomee/trunk/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties?rev=1563435&r1=1563434&r2=1563435&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
Sat Feb 1 16:02:46 2014
@@ -199,6 +199,11 @@
2.callback.missing = {0} method missing: "{1}" in class {2}
3.callback.missing = {0} method "{1}" not found in class {2}. The
required method signature is "void {1}()"
+# fail(bean, "callback.invocationcontext.notallowed", type,
callback.getMethodName())
+1.callback.invocationcontext.notallowed = Invalid usage of
javax.interceptor.InvocationContext as parameter type of callback
method
+2.callback.invocationcontext.notallowed = Invalid usage of
javax.interceptor.InvocationContext as parameter type of callback
method in bean class {0}
+3.callback.invocationcontext.notallowed = Invalid usage of
javax.interceptor.InvocationContext as parameter type of callback
method {1} in bean class {0}. Parameters of type InvocationContext are
only allowed for interceptors
+
# fail(bean, "callback.invalidArguments", type,
callback.getMethodName(), getParameters(possibleMethods.get(0)),
callback.getClassName());
1.callback.invalidArguments = Invalid {0} arguments
2.callback.invalidArguments = Invalid {0} arguments. Found: {1}({2}).
Required: {1}({4})
Modified: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidCallbacksTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidCallbacksTest.java?rev=1563435&r1=1563434&r2=1563435&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidCallbacksTest.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidCallbacksTest.java
Sat Feb 1 16:02:46 2014
@@ -17,6 +17,7 @@
package org.apache.openejb.config.rules;
import junit.framework.TestCase;
+
import org.apache.openejb.jee.EjbJar;
import org.apache.openejb.jee.NamedMethod;
import org.apache.openejb.jee.SingletonBean;
@@ -38,6 +39,8 @@ import javax.ejb.PrePassivate;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.SessionSynchronization;
+import javax.interceptor.InvocationContext;
+
import java.rmi.RemoteException;
import java.util.concurrent.Callable;
@@ -85,6 +88,13 @@ public class CheckInvalidCallbacksTest e
return ejbJar;
}
+ @Keys(@Key(value = "callback.invocationcontext.notallowed", count = 4))
+ public EjbJar test3() {
+ EjbJar ejbJar = new EjbJar();
+ ejbJar.addEnterpriseBean(new StatefulBean(CallbackViolatorBean.class));
+ return ejbJar;
+ }
+
public static class TestBean implements Callable {
public Object call() throws Exception {
return null;
@@ -252,4 +262,22 @@ public class CheckInvalidCallbacksTest e
@AfterCompletion
public void afterCompletion(boolean committed) {}
}
+
+ public class CallbackViolatorBean {
+ @PostConstruct
+ public void postConstruct(InvocationContext ic) {
+ }
+
+ @PreDestroy
+ public void preDestroy(InvocationContext ic) {
+ }
+
+ @PrePassivate
+ public void prePassivate(InvocationContext ic) {
+ }
+
+ @PostActivate
+ public void postActivate(InvocationContext ic) {
+ }
+ }
}
\ No newline at end of file