tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-2055 ejb style interceptors
Date Thu, 08 Jun 2017 14:47:03 GMT
Repository: tomee
Updated Branches:
  refs/heads/master 4a09afb5b -> 2e2423cb2


TOMEE-2055 ejb style interceptors


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/2e2423cb
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/2e2423cb
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/2e2423cb

Branch: refs/heads/master
Commit: 2e2423cb2968fbac142bf4d8cf6fc49a7a28eee8
Parents: 4a09afb
Author: rmannibucau <rmannibucau@apache.org>
Authored: Thu Jun 8 16:46:56 2017 +0200
Committer: rmannibucau <rmannibucau@apache.org>
Committed: Thu Jun 8 16:46:56 2017 +0200

----------------------------------------------------------------------
 .../java/org/apache/openejb/cdi/CdiEjbBean.java | 17 +++++++++++++-
 .../openejb/cdi/AroundConstructCdiTest.java     | 24 ++++++++++++++++++--
 2 files changed, 38 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/2e2423cb/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
index feeb984..9f46e60 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
@@ -36,6 +36,7 @@ import org.apache.webbeans.intercept.InterceptorResolutionService;
 import org.apache.webbeans.portable.InjectionTargetImpl;
 import org.apache.webbeans.util.GenericsUtil;
 
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
@@ -522,7 +523,21 @@ public class CdiEjbBean<T> extends BaseEjbBean<T> implements
InterceptedMarker,
         public T createNewPojo(final CreationalContext<T> creationalContext) {
             final CreationalContextImpl<T> ccImpl = CreationalContextImpl.class.cast(creationalContext);
             // super.produce(cc) will not work since we need the unproxied instance - decorator
case
-            final T produce = super.produce(super.createInterceptorInstances(ccImpl), ccImpl);
+            final Map<javax.enterprise.inject.spi.Interceptor<?>, Object> interceptorInstances
= super.createInterceptorInstances(ccImpl);
+            final InterceptorResolutionService.BeanInterceptorInfo interceptorInfo = super.getInterceptorInfo();
+            if (interceptorInfo != null) {
+                final Map<Constructor<?>, InterceptorResolutionService.BusinessMethodInterceptorInfo>
constructorInterceptorInfos =
+                        interceptorInfo.getConstructorInterceptorInfos();
+                if (!constructorInterceptorInfos.isEmpty()) { // were missed by OWB
+                    for (final javax.enterprise.inject.spi.Interceptor interceptorBean :
constructorInterceptorInfos.values().iterator().next().getEjbInterceptors()) {
+                        if (!interceptorInstances.containsKey(interceptorBean)) {
+                            ccImpl.putContextual(interceptorBean);
+                            interceptorInstances.put(interceptorBean, interceptorBean.create(ccImpl));
+                        }
+                    }
+                }
+            }
+            final T produce = super.produce(interceptorInstances, ccImpl);
             if (produce == null) { // user didnt call ic.proceed() in @AroundConstruct
                 return super.newInstance(ccImpl);
             }

http://git-wip-us.apache.org/repos/asf/tomee/blob/2e2423cb/container/openejb-core/src/test/java/org/apache/openejb/cdi/AroundConstructCdiTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/cdi/AroundConstructCdiTest.java
b/container/openejb-core/src/test/java/org/apache/openejb/cdi/AroundConstructCdiTest.java
index b7d5fed..26e677d 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/cdi/AroundConstructCdiTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/cdi/AroundConstructCdiTest.java
@@ -27,6 +27,7 @@ import javax.interceptor.AroundConstruct;
 import javax.interceptor.AroundInvoke;
 import javax.interceptor.Interceptor;
 import javax.interceptor.InterceptorBinding;
+import javax.interceptor.Interceptors;
 import javax.interceptor.InvocationContext;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
@@ -37,24 +38,43 @@ import static org.junit.Assert.assertEquals;
 
 // ensure @AroundConstruct doesnt fail and prevent to use EJB in its both flavors/signatures
 @RunWith(ApplicationComposer.class)
-@Classes(cdi = true, innerClassesAsBean = true, cdiInterceptors = {AroundConstructCdiTest.AC1.class,
AroundConstructCdiTest.AC2.class})
+@Classes(cdi = true, innerClassesAsBean = true, cdiInterceptors = {
+        AroundConstructCdiTest.AC1.class, AroundConstructCdiTest.AC2.class
+})
 public class AroundConstructCdiTest {
     @Inject
     private Bean bean;
 
     @Test
     public void run() {
-        assertEquals("truetrueget", bean.get());
+        assertEquals("truetruetrueget", bean.get());
     }
 
     @B1 @B2
     @Singleton
+    @Interceptors(AC3.class)
     public static class Bean {
         public String get() {
             return "get";
         }
     }
 
+    @Interceptor
+    public static class AC3 {
+        private boolean constructured = false;
+
+        @AroundConstruct
+        public Object ac(InvocationContext ic) throws Exception {
+            constructured = true;
+            return ic.proceed();
+        }
+
+        @AroundInvoke
+        public Object ai(final InvocationContext ic) throws Exception {
+            return constructured + ic.proceed().toString();
+        }
+    }
+
     @B1
     @Interceptor
     public static class AC1 {


Mime
View raw message