Author: dblevins
Date: Fri Dec 28 14:00:51 2007
New Revision: 607343
URL: http://svn.apache.org/viewvc?rev=607343&view=rev
Log:
Fixed OPENEJB-583: Method-level @ExcludeClassInterceptors disables class-level
@ExcludeDefaultInterceptors
Added tests to prove OPENEJB-584 invalid: Method-level interceptors declared
via annotations executed before method-level annotations declared via xml
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInterceptorTest.java
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java?rev=607343&r1=607342&r2=607343&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java
Fri Dec 28 14:00:51 2007
@@ -247,13 +247,11 @@
for (InterceptorBindingInfo info : bindings) {
Level level = level(info);
- if (excludes.contains(level)) continue;
-
if (!implies(method, ejbName, level, info)) continue;
Type type = type(level, info);
- if (type == Type.EXPLICIT_ORDERING){
+ if (type == Type.EXPLICIT_ORDERING && !excludes.contains(level)){
methodBindings.add(info);
// An explicit ordering trumps all other bindings of the same
level or below
// (even other explicit order bindings). Any bindings that
were higher than
@@ -272,12 +270,10 @@
if (type == Type.SAME_LEVEL_EXCLUSION){
excludes.add(level);
- continue;
- }
- boolean excludeInterceptorsOnly = info.interceptors.size() == 0 &&
info.interceptorOrder.size() == 0;
- if (!excludeInterceptorsOnly) {
- methodBindings.add(info);
}
+
+ if (!excludes.contains(level)) methodBindings.add(info);
+
if (info.excludeClassInterceptors) excludes.add(Level.CLASS);
if (info.excludeDefaultInterceptors) excludes.add(Level.PACKAGE);
}
@@ -295,7 +291,7 @@
// do we have parameters?
List<String> params = methodInfo.methodParams;
- if (params == null || params.size() == 0) return true;
+ if (params == null) return true;
// do we have the same number of parameters?
if (params.size() != method.getParameterTypes().length) return false;
@@ -335,9 +331,18 @@
}
private static Level level(InterceptorBindingInfo info) {
- if (info.ejbName.equals("*")) return Level.PACKAGE;
- if (info.method == null) return Level.CLASS;
- if (info.method.methodParams == null) return Level.OVERLOADED_METHOD;
+ if (info.ejbName.equals("*")) {
+ return Level.PACKAGE;
+ }
+
+ if (info.method == null) {
+ return Level.CLASS;
+ }
+
+ if (info.method.methodParams == null) {
+ return Level.OVERLOADED_METHOD;
+ }
+
return Level.EXACT_METHOD;
}
@@ -345,12 +350,15 @@
if (info.interceptorOrder.size() > 0) {
return Type.EXPLICIT_ORDERING;
}
+
if (level == Level.CLASS && info.excludeClassInterceptors &&
info.excludeDefaultInterceptors) {
return Type.SAME_AND_LOWER_EXCLUSION;
}
+
if (level == Level.CLASS && info.excludeClassInterceptors) {
return Type.SAME_LEVEL_EXCLUSION;
}
+
return Type.ADDITION_OR_LOWER_EXCLUSION;
}
Modified:
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInterceptorTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInterceptorTest.java?rev=607343&r1=607342&r2=607343&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInterceptorTest.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInterceptorTest.java
Fri Dec 28 14:00:51 2007
@@ -38,6 +38,7 @@
import javax.interceptor.InvocationContext;
import javax.interceptor.ExcludeClassInterceptors;
import javax.interceptor.ExcludeDefaultInterceptors;
+import javax.interceptor.Interceptors;
import javax.naming.InitialContext;
import javax.ejb.EJBException;
import java.util.List;
@@ -66,15 +67,6 @@
EjbJarInfo ejbJar = config.configureApplication(buildTestApp());
assertNotNull(ejbJar);
- assertEquals(1, ejbJar.enterpriseBeans.size());
- assertEquals(1, ejbJar.enterpriseBeans.get(0).aroundInvoke.size());
- assertEquals(1, ejbJar.enterpriseBeans.get(0).postConstruct.size());
-
- assertEquals(3, ejbJar.interceptors.size());
-// assertEquals(1, ejbJar.interceptors.get(0).aroundInvoke.size());
-// assertEquals(1, ejbJar.interceptors.get(0).postConstruct.size());
-
-// assertEquals(3, ejbJar.interceptorBindings.size());
assembler.createApplication(ejbJar);
@@ -91,11 +83,13 @@
assertCalls(
Call.Default_Invoke_BEFORE,
- Call.Method_Invoke_BEFORE,
+ Call.Method_ann_Invoke_BEFORE,
+ Call.Method_dd_Invoke_BEFORE,
Call.Bean_Invoke_BEFORE,
Call.Bean_Invoke,
Call.Bean_Invoke_AFTER,
- Call.Method_Invoke_AFTER,
+ Call.Method_dd_Invoke_AFTER,
+ Call.Method_ann_Invoke_AFTER,
Call.Default_Invoke_AFTER);
calls.clear();
@@ -103,11 +97,13 @@
assertEquals(true, b);
assertCalls(
- Call.Method_Invoke_BEFORE,
+ Call.Method_ann_Invoke_BEFORE,
+ Call.Method_dd_Invoke_BEFORE,
Call.Bean_Invoke_BEFORE,
Call.Bean_Invoke,
Call.Bean_Invoke_AFTER,
- Call.Method_Invoke_AFTER);
+ Call.Method_dd_Invoke_AFTER,
+ Call.Method_ann_Invoke_AFTER);
calls.clear();
try {
@@ -127,6 +123,36 @@
fail("Inner Exception should be a SysException");
}
}
+
+ calls.clear();
+
+ //--------------------------------------------
+ //--------------------------------------------
+ Target target2 = (Target) ctx.lookup("Target2BeanLocal");
+ i = target2.echo(123);
+ calls.clear();
+
+ i = target2.echo(123);
+ assertEquals(123, i);
+
+ assertCalls(
+ Call.Method_ann_Invoke_BEFORE,
+ Call.Bean_Invoke_BEFORE,
+ Call.Bean_Invoke,
+ Call.Bean_Invoke_AFTER,
+ Call.Method_ann_Invoke_AFTER);
+ calls.clear();
+
+ b = target2.echo(true);
+ assertEquals(true, b);
+
+ assertCalls(
+ Call.Method_ann_Invoke_BEFORE,
+ Call.Bean_Invoke_BEFORE,
+ Call.Bean_Invoke,
+ Call.Bean_Invoke_AFTER,
+ Call.Method_ann_Invoke_AFTER);
+ calls.clear();
}
private void assertCalls(Call... expectedCalls) {
@@ -146,40 +172,56 @@
Default_Invoke_BEFORE,
SuperClass_Invoke_BEFORE,
Class_Invoke_BEFORE,
- Method_Invoke_BEFORE,
+ Method_ann_Invoke_BEFORE,
+ Method_dd_Invoke_BEFORE,
Bean_Invoke_BEFORE,
Bean_Invoke,
Bean_Invoke_AFTER,
- Method_Invoke_AFTER,
+ Method_dd_Invoke_AFTER,
+ Method_ann_Invoke_AFTER,
Class_Invoke_AFTER,
SuperClass_Invoke_AFTER,
Default_Invoke_AFTER,
}
- public EjbModule buildTestApp() {
+ public EjbModule buildTestApp() throws Exception {
EjbJar ejbJar = new EjbJar();
AssemblyDescriptor ad = ejbJar.getAssemblyDescriptor();
+ ejbJar.addEnterpriseBean(new StatelessBean(Target2Bean.class));
+
EnterpriseBean bean = ejbJar.addEnterpriseBean(new
StatelessBean(TargetBean.class));
Interceptor interceptor;
- interceptor = ejbJar.addInterceptor(new
Interceptor(ClassInterceptor.class));
- ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
-
interceptor = ejbJar.addInterceptor(new
Interceptor(DefaultInterceptor.class));
ad.addInterceptorBinding(new InterceptorBinding("*", interceptor));
- interceptor = ejbJar.addInterceptor(new
Interceptor(EchoMethodInterceptor.class));
+ {
+ interceptor = ejbJar.addInterceptor(new
Interceptor(EchoMethodInterceptorViaDD.class));
+ InterceptorBinding binding = ad.addInterceptorBinding(new
InterceptorBinding(bean, interceptor));
+ binding.setMethod(new NamedMethod(TargetBean.class.getMethod("echo",
List.class)));
+ }
+
+ {
+ interceptor = ejbJar.addInterceptor(new
Interceptor(EchoMethodInterceptorViaDD.class));
+ InterceptorBinding binding = ad.addInterceptorBinding(new
InterceptorBinding(bean, interceptor));
+ binding.setMethod(new NamedMethod(TargetBean.class.getMethod("echo",
int.class)));
+ }
+
+ {
+ interceptor = ejbJar.addInterceptor(new
Interceptor(EchoMethodInterceptorViaDD.class));
InterceptorBinding binding = ad.addInterceptorBinding(new
InterceptorBinding(bean, interceptor));
- binding.setMethod(new NamedMethod("echo"));
+ binding.setMethod(new NamedMethod(TargetBean.class.getMethod("echo",
boolean.class)));
+ }
return new EjbModule(this.getClass().getClassLoader(),
this.getClass().getSimpleName(), "test", ejbJar, null);
}
public static List<Call> calls = new ArrayList<Call>();
+ @Interceptors({ClassInterceptor.class})
public static class TargetBean implements Target {
@PostConstruct
@@ -195,6 +237,49 @@
return o;
}
+ @Interceptors({EchoMethodInterceptorViaAnn.class})
+ public List echo(List data){
+ calls.add(Call.Bean_Invoke);
+ return data;
+ }
+
+ public void throwAppException() throws AppException {
+ throw new AppException();
+ }
+
+ public void throwSysException() {
+ throw new SysException();
+ }
+
+ @Interceptors({EchoMethodInterceptorViaAnn.class})
+ @ExcludeClassInterceptors
+ public int echo(int i) {
+ calls.add(Call.Bean_Invoke);
+ return i;
+ }
+
+ @Interceptors({EchoMethodInterceptorViaAnn.class})
+ @ExcludeClassInterceptors
+ @ExcludeDefaultInterceptors
+ public boolean echo(boolean i) {
+ calls.add(Call.Bean_Invoke);
+ return i;
+ }
+ }
+
+ @ExcludeDefaultInterceptors
+ @Interceptors({ClassInterceptor.class})
+ public static class Target2Bean implements Target {
+
+ @AroundInvoke
+ public Object invoke(InvocationContext context) throws Exception {
+ calls.add(Call.Bean_Invoke_BEFORE);
+ Object o = context.proceed();
+ calls.add(Call.Bean_Invoke_AFTER);
+ return o;
+ }
+
+ @Interceptors({EchoMethodInterceptorViaAnn.class})
public List echo(List data){
calls.add(Call.Bean_Invoke);
return data;
@@ -208,12 +293,14 @@
throw new SysException();
}
+ @Interceptors({EchoMethodInterceptorViaAnn.class})
@ExcludeClassInterceptors
public int echo(int i) {
calls.add(Call.Bean_Invoke);
return i;
}
+ @Interceptors({EchoMethodInterceptorViaAnn.class})
@ExcludeClassInterceptors
@ExcludeDefaultInterceptors
public boolean echo(boolean i) {
@@ -240,13 +327,24 @@
}
}
- public static class EchoMethodInterceptor {
+ public static class EchoMethodInterceptorViaAnn {
+
+ @AroundInvoke
+ public Object invoke(InvocationContext context) throws Exception {
+ calls.add(Call.Method_ann_Invoke_BEFORE);
+ Object o = context.proceed();
+ calls.add(Call.Method_ann_Invoke_AFTER);
+ return o;
+ }
+ }
+
+ public static class EchoMethodInterceptorViaDD {
@AroundInvoke
public Object invoke(InvocationContext context) throws Exception {
- calls.add(Call.Method_Invoke_BEFORE);
+ calls.add(Call.Method_dd_Invoke_BEFORE);
Object o = context.proceed();
- calls.add(Call.Method_Invoke_AFTER);
+ calls.add(Call.Method_dd_Invoke_AFTER);
return o;
}
}