You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by xu...@apache.org on 2010/08/27 08:53:25 UTC
svn commit: r990049 - in /openejb/trunk/openejb3/container/openejb-core/src:
main/java/org/apache/openejb/config/rules/CheckCallbacks.java
test/java/org/apache/openejb/config/rules/CheckInvalidInterceptorTest.java
Author: xuhaihong
Date: Fri Aug 27 06:53:24 2010
New Revision: 990049
URL: http://svn.apache.org/viewvc?rev=990049&view=rev
Log:
OpenEJB-1338 Validate the callback methods with correct declaring classes
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidInterceptorTest.java
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java?rev=990049&r1=990048&r2=990049&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCallbacks.java Fri Aug 27 06:53:24 2010
@@ -251,7 +251,14 @@ public class CheckCallbacks extends Vali
private void checkAroundTypeInvoke(String aroundType, Class ejbClass, String declaringClassName, String declaringMethodName, String componentName) {
try {
- Method method = getMethod(ejbClass, declaringMethodName, InvocationContext.class);
+ Class<?> delcaringClass = null;
+ try {
+ delcaringClass = declaringClassName == null ? ejbClass : loadClass(declaringClassName);
+ } catch (OpenEJBException e) {
+ fail(componentName, "missing.class", declaringClassName, aroundType, ejbClass.getName());
+ return;
+ }
+ Method method = getMethod(delcaringClass, declaringMethodName, InvocationContext.class);
Class<?> returnType = method.getReturnType();
@@ -301,7 +308,14 @@ public class CheckCallbacks extends Vali
private void checkCallback(Class<?> ejbClass, String type, CallbackMethod callback, EnterpriseBean bean, Class... parameterTypes) {
try {
- Method method = getMethod(ejbClass, callback.getMethodName(), parameterTypes);
+ Class<?> delcaringClass = null;
+ try {
+ delcaringClass = callback.getClassName() == null ? ejbClass : loadClass(callback.getClassName());
+ } catch (OpenEJBException e) {
+ fail(type, "missing.class", callback.getClassName(), type, bean.getEjbName());
+ return;
+ }
+ Method method = getMethod(delcaringClass, callback.getMethodName(), parameterTypes);
if (implementsSessionBean(ejbClass)) {
SessionBean sb = (SessionBean) bean;
if ("PreDestroy".equals(type)) {
@@ -358,7 +372,14 @@ public class CheckCallbacks extends Vali
private void checkCallback(Class interceptorClass, String type, CallbackMethod callback, Interceptor interceptor) {
try {
- Method method = getMethod(interceptorClass, callback.getMethodName(), InvocationContext.class);
+ Class<?> delcaringClass = null;
+ try {
+ delcaringClass = callback.getClassName() == null ? interceptorClass : loadClass(callback.getClassName());
+ } catch (OpenEJBException e) {
+ fail(type, "missing.class", callback.getClassName(), type, interceptor.getInterceptorClass());
+ return;
+ }
+ Method method = getMethod(delcaringClass, callback.getMethodName(), InvocationContext.class);
Class<?> returnType = method.getReturnType();
Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidInterceptorTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidInterceptorTest.java?rev=990049&r1=990048&r2=990049&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidInterceptorTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInvalidInterceptorTest.java Fri Aug 27 06:53:24 2010
@@ -23,12 +23,14 @@ import javax.annotation.PreDestroy;
import javax.interceptor.AroundInvoke;
import javax.interceptor.AroundTimeout;
import javax.interceptor.Interceptors;
+import javax.interceptor.InvocationContext;
import junit.framework.TestCase;
import org.apache.openejb.jee.EjbJar;
import org.apache.openejb.jee.Interceptor;
import org.apache.openejb.jee.InterceptorBinding;
+import org.apache.openejb.jee.LifecycleCallback;
import org.apache.openejb.jee.NamedMethod;
import org.apache.openejb.jee.StatelessBean;
import org.junit.runner.RunWith;
@@ -68,10 +70,27 @@ public class CheckInvalidInterceptorTest
return ejbJar;
}
+ /**
+ * Should not get any failure message, as we explicitly configure the methods in the base class
+ * @return
+ */
+ @Keys
+ public EjbJar testDeclaringInterceptorClass() {
+ EjbJar ejbJar = new EjbJar();
+ Interceptor subInterceptor = ejbJar.addInterceptor(new org.apache.openejb.jee.Interceptor(SubInterceptor.class));
+ subInterceptor.getPostConstruct().add(new LifecycleCallback(BaseInterceptor.class.getName(), "interceptPostConstruct"));
+ subInterceptor.getPreDestroy().add(new LifecycleCallback(BaseInterceptor.class.getName(), "interceptPreDestroy"));
+ subInterceptor.getAroundInvoke().add(new org.apache.openejb.jee.AroundInvoke(BaseInterceptor.class.getName(), "interceptAroundInvoke"));
+ subInterceptor.getAroundTimeout().add(new org.apache.openejb.jee.AroundTimeout(BaseInterceptor.class.getName(), "interceptAroundTimeout"));
+ return ejbJar;
+ }
+
@Interceptors(Interzeptor.class)
- public static class FooBean {}
+ public static class FooBean {
+ }
public static class Interzeptor {
+
@PostConstruct
public Object interceptPostConstruct() {
return null;
@@ -83,10 +102,46 @@ public class CheckInvalidInterceptorTest
}
@AroundInvoke
- public void interceptAroundInvoke() {}
+ public void interceptAroundInvoke() {
+ }
@AroundTimeout
- public void interceptAroundTimeout() {}
+ public void interceptAroundTimeout() {
+ }
+ }
+
+ public static class BaseInterceptor {
+
+ public void interceptPostConstruct(InvocationContext context) throws Exception {
+ }
+
+ public void interceptPreDestroy(InvocationContext context) throws Exception {
+ }
+
+ public Object interceptAroundInvoke(InvocationContext context) throws Exception {
+ return null;
+ }
+
+ public Object interceptAroundTimeout(InvocationContext context) throws Exception {
+ return null;
+ }
+ }
+
+ public static class SubInterceptor extends BaseInterceptor {
+
+ private final Object interceptPostConstruct() {
+ return null;
+ }
+
+ private final Object interceptPreDestroy() {
+ return null;
+ }
+
+ private final void interceptAroundInvoke() {
+ }
+
+ private final void interceptAroundTimeout() {
+ }
}
public static class CallbackMissingInterceptor {