splitting ejb interceptor and self callback interceptor lists since otherwise it is not possible to order them with cdi interceptors correctly
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/aa4cfc35 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/aa4cfc35 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/aa4cfc35 Branch: refs/heads/master Commit: aa4cfc3559c070dfd8dde9fcb5ab50535d9fdc28 Parents: 788b74f Author: Romain Manni-Bucau <[email protected]> Authored: Wed Mar 4 23:45:45 2015 +0100 Committer: Romain Manni-Bucau <[email protected]> Committed: Wed Mar 4 23:45:45 2015 +0100 ---------------------------------------------------------------------- .../java/org/apache/openejb/BeanContext.java | 30 +++++++++++++++++--- tck/cdi-embedded/pom.xml | 3 +- tck/cdi-embedded/src/test/resources/failing.xml | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/aa4cfc35/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java b/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java index c2f70ff..1270cd7 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java @@ -75,6 +75,7 @@ import javax.enterprise.inject.spi.InterceptionType; import javax.enterprise.inject.spi.Interceptor; import javax.naming.Context; import javax.persistence.EntityManagerFactory; +import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; @@ -127,11 +128,18 @@ public class BeanContext extends DeploymentContext { final Collection<Interceptor<?>> postConstructInterceptors = Collection.class.cast(Reflections.get(injectionTarget, "postConstructInterceptors")); final Collection<Interceptor<?>> preDestroyInterceptors = Collection.class.cast(Reflections.get(injectionTarget, "preDestroyInterceptors")); for (final Interceptor<?> pc : postConstructInterceptors) { + if (isEjbInterceptor(pc)) { + continue; + } + final InterceptorData interceptorData = createInterceptorData(pc); instanceScopedInterceptors.add(interceptorData); cdiInterceptors.add(interceptorData); } for (final Interceptor<?> pd : preDestroyInterceptors) { + if (isEjbInterceptor(pd)) { + continue; + } if (postConstructInterceptors.contains(pd)) { continue; } @@ -177,6 +185,11 @@ public class BeanContext extends DeploymentContext { clear(Collection.class.cast(Reflections.get(info, "cdiInterceptors"))); } + private boolean isEjbInterceptor(final Interceptor<?> pc) { + final Set<Annotation> interceptorBindings = pc.getInterceptorBindings(); + return interceptorBindings == null || interceptorBindings.isEmpty(); + } + private InterceptorData createInterceptorData(final Interceptor<?> i) { final InterceptorData data; if (CdiInterceptorBean.class.isInstance(i)) { @@ -282,6 +295,7 @@ public class BeanContext extends DeploymentContext { private TransactionPolicyFactory transactionPolicyFactory; private final List<InterceptorData> callbackInterceptors = new ArrayList<InterceptorData>(); + private final List<InterceptorData> beanCallbackInterceptors = new ArrayList<InterceptorData>(); private final Set<InterceptorData> instanceScopedInterceptors = new HashSet<InterceptorData>(); private final List<InterceptorInstance> systemInterceptors = new ArrayList<InterceptorInstance>(); private final List<InterceptorInstance> userInterceptors = new ArrayList<InterceptorInstance>(); @@ -1103,15 +1117,23 @@ public class BeanContext extends DeploymentContext { public List<InterceptorData> getCallbackInterceptors() { final List<InterceptorData> datas = getInterceptorData(); - datas.addAll(cdiInterceptors); datas.addAll(callbackInterceptors); + datas.addAll(cdiInterceptors); + datas.addAll(beanCallbackInterceptors); return datas; } public void setCallbackInterceptors(final List<InterceptorData> callbackInterceptors) { //TODO shouldn't we remove the old callbackInterceptors from instanceScopedInterceptors before adding the new ones? + this.beanCallbackInterceptors.clear(); this.callbackInterceptors.clear(); - this.callbackInterceptors.addAll(callbackInterceptors); + for (final InterceptorData data : callbackInterceptors) { + if (data.getInterceptorClass().isAssignableFrom(getManagedClass())) { + this.beanCallbackInterceptors.add(data); + } else { + this.callbackInterceptors.add(data); + } + } this.instanceScopedInterceptors.addAll(callbackInterceptors); } @@ -1130,7 +1152,7 @@ public class BeanContext extends DeploymentContext { } public List<InterceptorData> getInterceptorData() { - final List<InterceptorData> datas = new ArrayList<InterceptorData>(); + final List<InterceptorData> datas = new ArrayList<InterceptorData>(getUserAndSystemInterceptors().size()); for (final InterceptorInstance instance : getUserAndSystemInterceptors()) { datas.add(instance.getData()); } @@ -1634,7 +1656,7 @@ public class BeanContext extends DeploymentContext { if (callbacks.isEmpty()) { transactionType = TransactionType.RequiresNew; } else { - transactionType = getTransactionType(callbacks.iterator().next()); + transactionType = getTransactionType(callbacks.iterator().next()); // TODO: we should take the last one I think if (transactionType == TransactionType.Required) { transactionType = TransactionType.RequiresNew; } http://git-wip-us.apache.org/repos/asf/tomee/blob/aa4cfc35/tck/cdi-embedded/pom.xml ---------------------------------------------------------------------- diff --git a/tck/cdi-embedded/pom.xml b/tck/cdi-embedded/pom.xml index dc0361b..4133bfb 100644 --- a/tck/cdi-embedded/pom.xml +++ b/tck/cdi-embedded/pom.xml @@ -203,9 +203,10 @@ <openejb.cdi.producer.interception>false</openejb.cdi.producer.interception> <openejb.cdi.filter.classloader>false</openejb.cdi.filter.classloader> + <openejb.jul.forceReload>true</openejb.jul.forceReload> <openejb.strict.interface.declaration>true</openejb.strict.interface.declaration> <openejb.http.mock-request>true</openejb.http.mock-request> - <openejb.http.default-content-type>text/plain</openejb.http.default-content-type> + <openejb.http.default-content-type>text/plain</openejb.http.default-content-type> <!-- TODO: remove it --> <openejb.embedded.try-jsp>true</openejb.embedded.try-jsp> <openejb.deploymentId.format>{appId}/{ejbJarId}/{ejbName}</openejb.deploymentId.format> <org.apache.openejb.assembler.classic.WebAppBuilder>org.apache.openejb.web.LightweightWebAppBuilder</org.apache.openejb.assembler.classic.WebAppBuilder> http://git-wip-us.apache.org/repos/asf/tomee/blob/aa4cfc35/tck/cdi-embedded/src/test/resources/failing.xml ---------------------------------------------------------------------- diff --git a/tck/cdi-embedded/src/test/resources/failing.xml b/tck/cdi-embedded/src/test/resources/failing.xml index 01cc8b3..da64e41 100644 --- a/tck/cdi-embedded/src/test/resources/failing.xml +++ b/tck/cdi-embedded/src/test/resources/failing.xml @@ -31,7 +31,7 @@ -Dopenejb.embedded.try-jsp=true --> <classes> - <class name="org.jboss.cdi.tck.interceptors.tests.contract.lifecycleCallback.bindings.ejb.SessionBeanLifecycleInterceptorDefinitionTest" /> + <class name="org.jboss.cdi.tck.tests.lookup.injectionpoint.non.contextual.NonContextualInjectionPointTest" /> </classes> </test> </suite>
