You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2010/04/11 09:33:36 UTC

svn commit: r932843 - in /openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common: component/BaseEjbBean.java interceptor/OpenWebBeansEjbInterceptor.java proxy/EjbBeanProxyHandler.java util/EjbDefinitionUtility.java

Author: gerdogdu
Date: Sun Apr 11 07:33:36 2010
New Revision: 932843

URL: http://svn.apache.org/viewvc?rev=932843&view=rev
Log:
[OWB-348] Adding Interceptor and Decorator Support for EJB Beans

Modified:
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java

Modified: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java?rev=932843&r1=932842&r2=932843&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java (original)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java Sun Apr 11 07:33:36 2010
@@ -36,9 +36,6 @@ public abstract class BaseEjbBean<T> ext
     /**Session bean type*/
     protected SessionBeanType ejbType;
     
-    /**Current bean instance*/
-    protected T instance = null;
-    
     /**Injected reference local interface type*/
     protected Class<?> iface = null;
     
@@ -124,13 +121,7 @@ public abstract class BaseEjbBean<T> ext
     @Override
     protected T createComponentInstance(CreationalContext<T> creationalContext)
     {
-        if(this.instance == null)
-        {
-            //Create instance
-            this.instance = getInstance(creationalContext);
-        }
-
-        return instance;
+        return getInstance(creationalContext);
     }
     
     /**
@@ -149,9 +140,7 @@ public abstract class BaseEjbBean<T> ext
         if(removeStatefulInstance && getEjbType().equals(SessionBeanType.STATEFUL))
         {
             //Call remove method
-        }
-        
-        this.instance = null;
+        }        
     }
     
     /**

Modified: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java?rev=932843&r1=932842&r2=932843&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java (original)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java Sun Apr 11 07:33:36 2010
@@ -16,38 +16,404 @@
  */
 package org.apache.webbeans.ejb.common.interceptor;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.ProxyObject;
+
 import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.spi.Context;
 import javax.enterprise.context.spi.CreationalContext;
+import javax.interceptor.AroundInvoke;
 import javax.interceptor.InvocationContext;
 
+import org.apache.webbeans.component.InjectionTargetBean;
+import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.context.ContextFactory;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.decorator.DelegateHandler;
+import org.apache.webbeans.decorator.WebBeansDecoratorConfig;
+import org.apache.webbeans.decorator.WebBeansDecoratorInterceptor;
 import org.apache.webbeans.ejb.common.component.BaseEjbBean;
+import org.apache.webbeans.ejb.common.util.EjbUtility;
+import org.apache.webbeans.inject.OWBInjector;
+import org.apache.webbeans.intercept.InterceptorData;
+import org.apache.webbeans.intercept.InterceptorDataImpl;
+import org.apache.webbeans.intercept.InterceptorType;
+import org.apache.webbeans.intercept.InterceptorUtil;
+import org.apache.webbeans.intercept.InvocationContextImpl;
+import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.proxy.JavassistProxyFactory;
+import org.apache.webbeans.spi.ContextsService;
+import org.apache.webbeans.spi.ServiceLoader;
+import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.WebBeansUtil;
 
+/**
+ * EJB interceptor that is responsible
+ * for injection dependent instances, and call
+ * OWB based interceptors and decorators.
+ * 
+ * @version $Rev$ $Date$
+ *
+ */
 public class OpenWebBeansEjbInterceptor
 {
-    private static ThreadLocal<BaseEjbBean<?>> threadLocal = new ThreadLocal<BaseEjbBean<?>>();
+    //Logger instance
+    private static final WebBeansLogger logger = WebBeansLogger.getLogger(OpenWebBeansEjbInterceptor.class);
+    
+    /**Thread local for calling bean*/
+    private static transient ThreadLocal<BaseEjbBean<?>> threadLocal = new ThreadLocal<BaseEjbBean<?>>();
+    
+    /**Thread local for calling creational context*/
+    private static transient ThreadLocal<CreationalContext<?>> threadLocalCreationalContext = new ThreadLocal<CreationalContext<?>>();
+    
+    /**Intercepted methods*/
+    protected transient Map<Method, List<InterceptorData>> interceptedMethodMap = new WeakHashMap<Method, List<InterceptorData>>();
     
-    private static ThreadLocal<CreationalContext<?>> threadLocalCreationalContext = new ThreadLocal<CreationalContext<?>>();
+    /**Bean decorator objects*/
+    protected transient List<Object> decorators = null;
+    
+    /**Delegate handler*/
+    protected transient DelegateHandler delegateHandler;
+    
+    /**Injector*/
+    private transient OWBInjector injector;
+    
+    /**
+     * Creates a new instance.
+     */
+    public OpenWebBeansEjbInterceptor()
+    {
+        
+    }
     
+    /**
+     * Sets thread local.
+     * @param ejbBean bean
+     * @param creationalContext context
+     */
     public static void setThreadLocal(BaseEjbBean<?> ejbBean, CreationalContext<?> creationalContext)
     {
         threadLocal.set(ejbBean);
         threadLocalCreationalContext.set(creationalContext);
     }
     
+    /**
+     * Remove locals.
+     */
     public static void unsetThreadLocal()
     {
         threadLocal.remove();
         threadLocalCreationalContext.remove();
     }
     
+    /**
+     * Called for every business methods.
+     * @param context invocation context
+     * @return instance
+     * @throws Exception
+     */
+    @AroundInvoke
+    public Object callToOwbInterceptors(InvocationContext context) throws Exception
+    {
+        boolean requestCreated = false;
+        boolean applicationCreated = false;
+        boolean requestAlreadyActive = false;
+        boolean applicationAlreadyActive = false;
+        try
+        {
+            int result = 1000;
+            //Context activities
+            if( (result = activateContexts(RequestScoped.class)) == 1)
+            {
+                requestCreated = true;
+            }
+            else if(result == -1)
+            {
+                requestAlreadyActive = true;
+            }
+            
+            if((result = activateContexts(ApplicationScoped.class)) == 1)
+            {
+                applicationCreated = true;
+            }
+            else if(result == -1)
+            {
+                applicationAlreadyActive = true;
+            }
+
+            //Calls OWB interceptors and decorators
+            callInterceptorsAndDecorators(context.getMethod(), context.getTarget(), context.getParameters());
+
+        }finally
+        {
+            if(!requestAlreadyActive)
+            {
+                deActivateContexts(requestCreated, RequestScoped.class);   
+            }
+            if(!applicationAlreadyActive)
+            {
+                deActivateContexts(applicationCreated, ApplicationScoped.class);   
+            }
+        }
+        
+        return context.proceed();
+    }
+    
+    /**
+     * Post construct.
+     * @param context invocation ctx
+     */
     @PostConstruct
     public void afterConstruct(InvocationContext context)
     {
+        InjectionTargetBean<?> injectionTarget = (InjectionTargetBean<?>) threadLocal.get();
+        
+        if (WebBeansUtil.isContainsInterceptorMethod(injectionTarget.getInterceptorStack(), InterceptorType.POST_CONSTRUCT))
+        {                
+            InvocationContextImpl impl = new InvocationContextImpl(null, context.getTarget(), null, null, 
+                    InterceptorUtil.getInterceptorMethods(injectionTarget.getInterceptorStack(), InterceptorType.POST_CONSTRUCT), InterceptorType.POST_CONSTRUCT);
+            impl.setCreationalContext(threadLocalCreationalContext.get());
+            try
+            {
+                impl.proceed();
+            }
+            catch (Exception e)
+            {
+                logger.error(OWBLogConst.ERROR_0008, new Object[]{"@PostConstruct."}, e);                
+            }
+        }            
+        
         Object instance = context.getTarget();
+        this.injector = new OWBInjector();
+        try
+        {
+            this.injector.inject(instance, threadLocalCreationalContext.get());
+        }
+        catch (Exception e)
+        {
+            logger.error("Error is occured while injecting dependencies of bean : " + threadLocal.get(),e);
+        }
+        
+    }
+    
+    /**
+     * Pre destroy.
+     * @param context invocation context
+     */
+    @PreDestroy
+    public void preDestroy(InvocationContext context)
+    {
+        InjectionTargetBean<?> injectionTarget = (InjectionTargetBean<?>) threadLocal.get();
+        
+        if (WebBeansUtil.isContainsInterceptorMethod(injectionTarget.getInterceptorStack(), InterceptorType.PRE_DESTROY))
+        {                
+            InvocationContextImpl impl = new InvocationContextImpl(null, context.getTarget(), null, null, 
+                    InterceptorUtil.getInterceptorMethods(injectionTarget.getInterceptorStack(), InterceptorType.PRE_DESTROY), InterceptorType.PRE_DESTROY);
+            impl.setCreationalContext(threadLocalCreationalContext.get());
+            try
+            {
+                impl.proceed();
+            }
+            catch (Exception e)
+            {
+                logger.error(OWBLogConst.ERROR_0008, new Object[]{"@PreDestroy."}, e);
+            }
+        }            
+        
+        if(this.injector != null)
+        {
+            this.injector.destroy();
+            this.interceptedMethodMap.clear();
+            if(decorators != null)
+            {
+                decorators.clear();
+            }
+        }
+    }
+    
+    /**
+     * Activate given context.
+     * @param scopeType scope type
+     * @return true if also creates context.
+     */
+    private int activateContexts(Class<? extends Annotation> scopeType)
+    {
+        ContextsService service = ServiceLoader.getService(ContextsService.class);
+        Context ctx = service.getCurrentContext(scopeType);
+        
+        if(scopeType == RequestScoped.class)
+        {
+            if(ctx != null && !ctx.isActive())
+            {
+                ContextFactory.activateContext(scopeType);
+                return 0;
+            }
+            else if(ctx == null)
+            {
+                ContextFactory.initRequestContext(null);
+                return 1;
+            }
+            
+        }
+        
+        ctx = service.getCurrentContext(scopeType);
+        if(ctx != null && !ctx.isActive())
+        {
+            ContextFactory.activateContext(scopeType);
+            return 0;
+        }
+        else if(ctx == null)
+        {
+            ContextFactory.initApplicationContext(null);
+            return 1;
 
-        threadLocal.get().injectFieldInInterceptor(instance, threadLocalCreationalContext.get());
+        }     
         
+        return -1;
+    }
+    
+    /**
+     * Deacitvate context.
+     * @param destroy if destroy context
+     * @param scopeType scope type
+     */
+    private void deActivateContexts(boolean destroy, Class<? extends Annotation> scopeType)
+    {
+        if(scopeType == ApplicationScoped.class)
+        {
+            if(destroy)
+            {
+                ContextFactory.destroyApplicationContext(null);
+            }
+            else
+            {
+                ContextFactory.deActivateContext(ApplicationScoped.class);
+            }            
+        }
+        else
+        {
+            if(destroy)
+            {
+                ContextFactory.destroyRequestContext(null);
+            }
+            else
+            {
+                ContextFactory.deActivateContext(RequestScoped.class);
+            }            
+        }                
+    }
+    
+    /**
+     * Calls OWB related interceptors and decorators.
+     * @param method business method
+     * @param instance bean instance
+     * @param arguments method arguments
+     * @return result of operation
+     * @throws Exception for any exception
+     */
+    private Object callInterceptorsAndDecorators(Method method, Object instance, Object[] arguments) throws Exception
+    {
+        InjectionTargetBean<?> injectionTarget = (InjectionTargetBean<?>) threadLocal.get();
         
+        String methodName = method.getName();
+        if(ClassUtil.isObjectMethod(methodName) && !methodName.equals("toString"))
+        {
+            logger.warn("Calling method on proxy is restricted except Object.toString(), but current method is Object." + methodName);
+        }
+                
+        if (InterceptorUtil.isWebBeansBusinessMethod(method) && 
+                EjbUtility.isBusinessMethod(method, threadLocal.get()))
+        {
+
+            List<Object> decorators = null;
+
+            if (injectionTarget.getDecoratorStack().size() > 0 && this.decorators == null)
+            {
+                Class<?> proxyClass = JavassistProxyFactory.getInterceptorProxyClasses().get(injectionTarget);
+                if (proxyClass == null)
+                {
+                    ProxyFactory delegateFactory = JavassistProxyFactory.createProxyFactory(injectionTarget);
+                    proxyClass = JavassistProxyFactory.getProxyClass(delegateFactory);
+                    JavassistProxyFactory.getInterceptorProxyClasses().put(injectionTarget, proxyClass);
+                }
+                Object delegate = proxyClass.newInstance();
+                this.delegateHandler = new DelegateHandler(threadLocal.get());
+                ((ProxyObject)delegate).setHandler(this.delegateHandler);
+
+                // Gets component decorator stack
+                decorators = WebBeansDecoratorConfig.getDecoratorStack(injectionTarget, instance, delegate, (CreationalContextImpl<?>)threadLocalCreationalContext.get());                        
+                //Sets decorator stack of delegate
+                this.delegateHandler.setDecorators(decorators);
+                
+                this.decorators = decorators;
+            }
+
+            // Run around invoke chain
+            List<InterceptorData> interceptorStack = injectionTarget.getInterceptorStack();
+            if (interceptorStack.size() > 0)
+            {
+                if(this.interceptedMethodMap.get(method) == null)
+                {
+                    //Holds filtered interceptor stack
+                    List<InterceptorData> filteredInterceptorStack = new ArrayList<InterceptorData>(interceptorStack);
+
+                    // Filter both EJB and WebBeans interceptors
+                    InterceptorUtil.filterCommonInterceptorStackList(filteredInterceptorStack, method, (CreationalContextImpl<?>)threadLocalCreationalContext.get());
+
+                    // If there are both interceptors and decorators, add hook
+                    // point to the end of the interceptor stack.
+                    if (decorators != null && filteredInterceptorStack.size() > 0)
+                    {
+                        WebBeansDecoratorInterceptor lastInterceptor = new WebBeansDecoratorInterceptor(delegateHandler, instance);
+                        InterceptorDataImpl data = new InterceptorDataImpl(true,lastInterceptor);
+                        data.setDefinedInInterceptorClass(true);
+                        data.setAroundInvoke(lastInterceptor.getClass().getDeclaredMethods()[0]);
+                        //Add to last
+                        filteredInterceptorStack.add(data);
+                    }
+                    
+                    this.interceptedMethodMap.put(method, filteredInterceptorStack);
+                }
+                
+                // Call Around Invokes
+                if (WebBeansUtil.isContainsInterceptorMethod(this.interceptedMethodMap.get(method), InterceptorType.AROUND_INVOKE))
+                {
+                     return InterceptorUtil.callAroundInvokes(threadLocal.get(), instance, (CreationalContextImpl<?>)threadLocalCreationalContext.get(), method, 
+                            arguments, InterceptorUtil.getInterceptorMethods(this.interceptedMethodMap.get(method), InterceptorType.AROUND_INVOKE));
+                }
+                
+            }
+            
+            // If there are Decorators, allow the delegate handler to
+            // manage the stack
+            if (this.decorators != null)
+            {
+                return delegateHandler.invoke(instance, method, null, arguments);
+            }
+        }    
+        
+        return null;
+    }
+    
+    //Read object
+    private  void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
+    {
+        threadLocal = new ThreadLocal<BaseEjbBean<?>>();
+        threadLocalCreationalContext = new ThreadLocal<CreationalContext<?>>();
+        interceptedMethodMap = new WeakHashMap<Method, List<InterceptorData>>();
     }
+ 
     
 }

Modified: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java?rev=932843&r1=932842&r2=932843&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java (original)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java Sun Apr 11 07:33:36 2010
@@ -16,6 +16,9 @@
  */
 package org.apache.webbeans.ejb.common.proxy;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.lang.reflect.Method;
 import java.util.List;
 
@@ -26,8 +29,11 @@ import javax.enterprise.context.spi.Crea
 import javax.enterprise.inject.spi.SessionBeanType;
 
 import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.context.AbstractContext;
+import org.apache.webbeans.context.creational.CreationalContextFactory;
 import org.apache.webbeans.ejb.common.component.BaseEjbBean;
 import org.apache.webbeans.ejb.common.interceptor.OpenWebBeansEjbInterceptor;
+import org.apache.webbeans.logger.WebBeansLogger;
 
 import javassist.util.proxy.MethodHandler;
 
@@ -39,10 +45,14 @@ import javassist.util.proxy.MethodHandle
 @SuppressWarnings("unchecked")
 public class EjbBeanProxyHandler implements MethodHandler
 {
+    //Logger instance
+    private static final WebBeansLogger logger = WebBeansLogger.getLogger(EjbBeanProxyHandler.class);
+    
     /**Proxy ejb bean instance*/
     private BaseEjbBean<?> ejbBean;
     
-    private CreationalContext<?> creationalContext;
+    /**Creational Context*/
+    private transient CreationalContext<?> creationalContext;
     
     /**
      * Creates a new instance.
@@ -73,13 +83,40 @@ public class EjbBeanProxyHandler impleme
         
         try
         {
+            //Set Ejb bean on thread local
             OpenWebBeansEjbInterceptor.setThreadLocal(this.ejbBean, this.creationalContext);
+
+            Object webbeansInstance = null;
             
             //Context of the bean
-            Context webbeansContext = BeanManagerImpl.getManager().getContext(ejbBean.getScope());
+            Context webbeansContext = BeanManagerImpl.getManager().getContext(this.ejbBean.getScope());
+            
+            //Already saved in context?
+            webbeansInstance=webbeansContext.get(this.ejbBean);
+            if (webbeansInstance != null)
+            {
+                // voila, we are finished if we found an existing contextual instance
+                return webbeansInstance;
+            }
             
-            //Get bean instance from context
-            Object webbeansInstance = webbeansContext.get((Contextual<Object>)this.ejbBean, (CreationalContext<Object>)this.creationalContext);            
+            if (webbeansContext instanceof AbstractContext)
+            {
+                CreationalContext<?> cc = ((AbstractContext)webbeansContext).getCreationalContext(this.ejbBean);
+                if (cc != null)
+                {
+                    creationalContext = cc;
+                }
+            }
+            if (creationalContext == null)
+            {
+                // if there was no CreationalContext set from external, we create a new one
+                creationalContext = CreationalContextFactory.getInstance().getCreationalContext(this.ejbBean);
+            }
+            
+            // finally, we create a new contextual instance
+            webbeansInstance = webbeansContext.get((Contextual<Object>)this.ejbBean, (CreationalContext<Object>) creationalContext);
+            
+            //Call actual method
             result = method.invoke(webbeansInstance, arguments);            
             
         }finally
@@ -88,7 +125,7 @@ public class EjbBeanProxyHandler impleme
         }                
         
         return result;
-    }
+    }    
     
     /**
      * Check stateful bean remove method control.
@@ -112,4 +149,41 @@ public class EjbBeanProxyHandler impleme
         
         return false;
     }
+    
+    /**
+     * Write to stream.
+     * @param s stream
+     * @throws IOException
+     */
+    private  void writeObject(ObjectOutputStream s) throws IOException
+    {
+        // we have to write the ids for all beans, not only PassivationCapable
+        // since this gets serialized along with the Bean proxy.
+        String passivationId = this.ejbBean.getId();
+        if (passivationId!= null)
+        {
+            s.writeObject(passivationId);
+        }
+        else
+        {
+            s.writeObject(null);
+            logger.warn("Trying to serialize not passivated capable bean proxy : " + this.ejbBean);
+        }
+    }
+    
+    /**
+     * Read from stream.
+     * @param s stream
+     * @throws IOException
+     * @throws ClassNotFoundException
+     */
+    private  void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
+    {
+        String passivationId = (String) s.readObject();
+        if (passivationId != null)
+        {
+            this.ejbBean = (BaseEjbBean<?>)BeanManagerImpl.getManager().getPassivationCapableBean(passivationId);
+        }
+    }
+    
 }

Modified: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java?rev=932843&r1=932842&r2=932843&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java (original)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java Sun Apr 11 07:33:36 2010
@@ -49,14 +49,21 @@ public final class EjbDefinitionUtility
         try
         {
             bean.setIface(iface);
-            ProxyFactory factory = new ProxyFactory();
             
-            EjbBeanProxyHandler handler = new EjbBeanProxyHandler(bean,creationalContext);
+            Class<?> clazz = JavassistProxyFactory.getEjbBeanProxyClass(bean);
+            if(clazz != null)
+            {
+                return (T)clazz.newInstance();
+            }
             
+            //Proxy factory instance
+            ProxyFactory factory = new ProxyFactory();            
+            
+            EjbBeanProxyHandler handler = new EjbBeanProxyHandler(bean,creationalContext);            
             factory.setHandler(handler);
             factory.setInterfaces(new Class[]{iface});
          
-            return (T)(JavassistProxyFactory.getProxyClass(factory).newInstance());
+            return (T)(JavassistProxyFactory.defineEjbBeanProxyClass(bean, factory).newInstance());
             
         }catch(Exception e)
         {



Re: svn commit: r932843 - in /openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common: component/BaseEjbBean.java interceptor/OpenWebBeansEjbInterceptor.java proxy/EjbBeanProxyHandler.java util/EjbDefinitionUtility.java

Posted by Eric Covener <co...@gmail.com>.
>>>>Finally, does this work whether or not the EJB itself was contextual?
> This is written to work with contextual EJB beans. If the EJB bean is not contextual, then it does not support decorators but supports JSR299 style
> interceptors. We could create a new EJB interceptor/utility for returning interceptors for non-contextual ejbs.

Gurkan,

Revisiting this old thread -- are you sure the non-contextual case
should not be deocratable? I think this became part of my conventional
wisdom but I can't find any basis for it.

It seems decoration sould be easy  to add to our interceptor for
non-contextual -- in fact I think all the contextual vs non-contextual
distinction can go away if we do a little more work in @PostConstruct.

(hope to look at it this week)

-- 
Eric Covener
covener@gmail.com

Re: svn commit: r932843 - in /openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common: component/BaseEjbBean.java interceptor/OpenWebBeansEjbInterceptor.java proxy/EjbBeanProxyHandler.java util/EjbDefinitionUtility.java

Posted by Eric Covener <co...@gmail.com>.
>>>>Finally, does this work whether or not the EJB itself was contextual?
> This is written to work with contextual EJB beans. If the EJB bean is not contextual, then it does not support decorators but supports JSR299 style
> interceptors. We could create a new EJB interceptor/utility for returning interceptors for non-contextual ejbs.

Have you discussed at all with David Blevins how we might get hooked
in for this non-contextual case?  Seems like we'd need openEJB to
pretend something like OWBEjbIntercptor was always specified as an
@Interceptor.

-- 
Eric Covener
covener@gmail.com

Re: svn commit: r932843 - in /openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common: component/BaseEjbBean.java interceptor/OpenWebBeansEjbInterceptor.java proxy/EjbBeanProxyHandler.java util/EjbDefinitionUtility.java

Posted by Gurkan Erdogdu <gu...@yahoo.com>.
>>>Do you think it's possible to re-use an InterceptorHandler instead of
>>>having the ejb-common code know so much detail of
>>>interceptors/decorators?
Hımm, the first reason is that in EJB scenario, target bean method is called by the EJB container. Second is that InterceptorHandler is a Javassist method handler, the other is interceptor. But it is reasonable to define common methods that are used by both of them.

>>>I wasn't able to rebase my workspace yet, but who is calling the
>>>BaseEJBBean.setThreadLocal() ?
It is called by the EjbBeanProxyHandler#invoke

>>>Finally, does this work whether or not the EJB itself was contextual?
This is written to work with contextual EJB beans. If the EJB bean is not contextual, then it does not support decorators but supports JSR299 style
interceptors. We could create a new EJB interceptor/utility for returning interceptors for non-contextual ejbs.

Thanks;

--Gurkan



________________________________
From: Eric Covener <co...@gmail.com>
To: dev@openwebbeans.apache.org
Sent: Sun, April 11, 2010 2:35:11 PM
Subject: Re: svn commit: r932843 - in /openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common:  component/BaseEjbBean.java interceptor/OpenWebBeansEjbInterceptor.java  proxy/EjbBeanProxyHandler.java util/EjbDefinitionUtility.java

> +    private Object callInterceptorsAndDecorators(Method method, Object instance, Object[] arguments) throws Exception

Do you think it's possible to re-use an InterceptorHandler instead of
having the ejb-common code know so much detail of
interceptors/decorators?

I wasn't able to rebase my workspace yet, but who is calling the
BaseEJBBean.setThreadLocal() ?

Finally, does this work whether or not the EJB itself was contextual?

-- 
Eric Covener
covener@gmail.com



      ___________________________________________________________________
Yahoo! Türkiye açıldı!  http://yahoo.com.tr
İnternet üzerindeki en iyi içeriği Yahoo! Türkiye sizlere sunuyor!

Re: svn commit: r932843 - in /openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common: component/BaseEjbBean.java interceptor/OpenWebBeansEjbInterceptor.java proxy/EjbBeanProxyHandler.java util/EjbDefinitionUtility.java

Posted by Eric Covener <co...@gmail.com>.
> +    private Object callInterceptorsAndDecorators(Method method, Object instance, Object[] arguments) throws Exception

Do you think it's possible to re-use an InterceptorHandler instead of
having the ejb-common code know so much detail of
interceptors/decorators?

I wasn't able to rebase my workspace yet, but who is calling the
BaseEJBBean.setThreadLocal() ?

Finally, does this work whether or not the EJB itself was contextual?

-- 
Eric Covener
covener@gmail.com