openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rsandt...@apache.org
Subject svn commit: r1697484 [2/2] - in /openwebbeans/branches/cdi-2.0: ./ distribution/ distribution/src/assembly/ distribution/src/main/ readme/ samples/ webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/ w...
Date Mon, 24 Aug 2015 19:16:41 GMT
Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java Mon Aug 24 19:16:40 2015
@@ -25,6 +25,7 @@ import java.lang.reflect.ParameterizedTy
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -78,7 +79,6 @@ import org.apache.webbeans.util.ClassUti
 import org.apache.webbeans.util.GenericsUtil;
 import org.apache.webbeans.util.WebBeansUtil;
 
-@SuppressWarnings("unchecked")
 public final class NotificationManager
 {
     private final Map<Type, Set<ObserverMethod<?>>> observers = new ConcurrentHashMap<Type, Set<ObserverMethod<?>>>();
@@ -87,30 +87,37 @@ public final class NotificationManager
     /**
      * Contains information whether certain Initialized and Destroyed events have observer methods.
      */
-    private final ConcurrentMap<Annotation, Boolean> hasLifecycleEventObservers = new ConcurrentHashMap<Annotation, Boolean>();
+    private final ConcurrentMap<Annotation, Boolean> hasContextLifecycleEventObservers
+        = new ConcurrentHashMap<Annotation, Boolean>();
 
+    /**
+     * List of ObserverMethods cached by their raw types.
+     */
+    private final ConcurrentHashMap<Class<?>, Set<ObserverMethod<?>>> observersByRawType
+        = new ConcurrentHashMap<Class<?>, Set<ObserverMethod<?>>>();
 
 
-    public static final Set<Class> CONTAINER_EVENT_CLASSES = new HashSet<Class>();
-    static {
-        CONTAINER_EVENT_CLASSES.add(AfterBeanDiscovery.class);
-        CONTAINER_EVENT_CLASSES.add(AfterDeploymentValidation.class);
-        CONTAINER_EVENT_CLASSES.add(AfterTypeDiscovery.class);
-        CONTAINER_EVENT_CLASSES.add(BeforeBeanDiscovery.class);
-        CONTAINER_EVENT_CLASSES.add(BeforeShutdown.class);
-        CONTAINER_EVENT_CLASSES.add(ProcessAnnotatedType.class);
-        CONTAINER_EVENT_CLASSES.add(ProcessBean.class);
-        CONTAINER_EVENT_CLASSES.add(ProcessBeanAttributes.class);
-        CONTAINER_EVENT_CLASSES.add(ProcessInjectionPoint.class);
-        CONTAINER_EVENT_CLASSES.add(ProcessInjectionTarget.class);
-        CONTAINER_EVENT_CLASSES.add(ProcessManagedBean.class);
-        CONTAINER_EVENT_CLASSES.add(ProcessObserverMethod.class);
-        CONTAINER_EVENT_CLASSES.add(ProcessProducer.class);
-        CONTAINER_EVENT_CLASSES.add(ProcessProducerField.class);
-        CONTAINER_EVENT_CLASSES.add(ProcessProducerMethod.class);
-        CONTAINER_EVENT_CLASSES.add(ProcessSessionBeanImpl.class);
-        CONTAINER_EVENT_CLASSES.add(ProcessSyntheticAnnotatedType.class);
-    }
+
+    public static final Set<Class> CONTAINER_EVENT_CLASSES = new HashSet<Class>(
+        Arrays.asList(new Class[]{
+            AfterBeanDiscovery.class,
+            AfterDeploymentValidation.class,
+            AfterTypeDiscovery.class,
+            BeforeBeanDiscovery.class,
+            BeforeShutdown.class,
+            ProcessAnnotatedType.class,
+            ProcessBean.class,
+            ProcessBeanAttributes.class,
+            ProcessInjectionPoint.class,
+            ProcessInjectionTarget.class,
+            ProcessManagedBean.class,
+            ProcessObserverMethod.class,
+            ProcessProducer.class,
+            ProcessProducerField.class,
+            ProcessProducerMethod.class,
+            ProcessSessionBeanImpl.class,
+            ProcessSyntheticAnnotatedType.class,
+        }));
 
     public NotificationManager(WebBeansContext webBeansContext)
     {
@@ -118,13 +125,24 @@ public final class NotificationManager
     }
 
     /**
+     * This methods needs to get called after the container got started.
+     * This is to avoid that events which already got fired during bootstrap in Extensions
+     * will get cached and events from beans thus get ignored.
+     */
+    public void clearCaches()
+    {
+        observersByRawType.clear();
+        hasContextLifecycleEventObservers.clear();
+    }
+
+    /**
      *
      * @param lifecycleEvent e.g. {@link org.apache.webbeans.annotation.DestroyedLiteral#INSTANCE_REQUEST_SCOPED}
      * @return whether the given Initialized or Destroyed event has observer methods.
      */
-    public boolean hasLifecycleObserver(Annotation lifecycleEvent)
+    public boolean hasContextLifecycleObserver(Annotation lifecycleEvent)
     {
-        Boolean hasObserver = hasLifecycleEventObservers.get(lifecycleEvent);
+        Boolean hasObserver = hasContextLifecycleEventObservers.get(lifecycleEvent);
         if (hasObserver == null)
         {
             hasObserver = Boolean.FALSE;
@@ -136,7 +154,7 @@ public final class NotificationManager
                     break;
                 }
             }
-            hasLifecycleEventObservers.putIfAbsent(lifecycleEvent, hasObserver);
+            hasContextLifecycleEventObservers.putIfAbsent(lifecycleEvent, hasObserver);
         }
 
         return hasObserver;
@@ -177,8 +195,6 @@ public final class NotificationManager
 
     public <T> Set<ObserverMethod<? super T>> resolveObservers(T event, EventMetadataImpl metadata, boolean isLifecycleEvent)
     {
-        EventUtil.checkEventBindings(webBeansContext, metadata.getQualifiers());
-
         Type eventType = metadata.validatedType();
         Set<ObserverMethod<? super T>> observersMethods = filterByType(event, eventType, isLifecycleEvent);
 
@@ -189,9 +205,10 @@ public final class NotificationManager
             observersMethods = filterByWithAnnotations(observersMethods, ((ProcessAnnotatedType) event).getAnnotatedType());
         }
 
-        //this check for the TCK is only needed if no observer was found
-        if (observersMethods.isEmpty())
+        if (!isLifecycleEvent && observersMethods.isEmpty())
         {
+            //this check for the TCK is only needed if no observer was found
+            EventUtil.checkEventBindings(webBeansContext, metadata.getQualifiers());
             EventUtil.checkQualifierImplementations(metadata.getQualifiers());
         }
 
@@ -305,7 +322,18 @@ public final class NotificationManager
             return filterByExtensionEventType(event, declaredEventType);
         }
         Class<?> eventClass = event.getClass();
-        
+
+        // whether the fired event is a raw java class or a generic type
+        boolean isRawEvent = declaredEventType instanceof Class;
+        if (isRawEvent)
+        {
+            Set rawTypeObservers = observersByRawType.get(eventClass);
+            if (rawTypeObservers != null)
+            {
+                return rawTypeObservers;
+            }
+        }
+
         Set<ObserverMethod<? super T>> matching = new HashSet<ObserverMethod<? super T>>();
 
         Set<Type> eventTypes = GenericsUtil.getTypeClosure(declaredEventType, eventClass);
@@ -314,17 +342,16 @@ public final class NotificationManager
             throw new IllegalArgumentException("event type may not contain unbound type variable: " + eventTypes);
         }
 
-        Set<Type> observedTypes = observers.keySet();
-
-        for (Type observedType : observedTypes)
+        for (Map.Entry<Type, Set<ObserverMethod<?>>> observerEntry : observers.entrySet())
         {
+            Type observedType = observerEntry.getKey();
             for (Type eventType : eventTypes)
             {
                 if ((ParameterizedType.class.isInstance(eventType) && Class.class.isInstance(observedType)
                         && GenericsUtil.isAssignableFrom(true, false, observedType, ParameterizedType.class.cast(eventType).getRawType()))
                     || GenericsUtil.isAssignableFrom(true, false, observedType, eventType))
                 {
-                    Set<ObserverMethod<?>> observerMethods = observers.get(observedType);
+                    Set<ObserverMethod<?>> observerMethods = observerEntry.getValue();
 
                     for (ObserverMethod<?> observerMethod : observerMethods)
                     {
@@ -334,6 +361,12 @@ public final class NotificationManager
                 }
             }
         }
+
+        if (isRawEvent)
+        {
+            // cache the result
+            observersByRawType.putIfAbsent(eventClass, (Set) matching);
+        }
         return matching;
     }
     

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java Mon Aug 24 19:16:40 2015
@@ -253,6 +253,10 @@ public class ObserverMethodImpl<T> imple
                 }
                 catch (ContextNotActiveException cnae)
                 {
+                    if (ifExist)
+                    {
+                        return;
+                    }
                     // this may happen if we try to e.g. send an event to a @ConversationScoped bean from a ServletListener
                     logger.log(Level.INFO, OWBLogConst.INFO_0010, bean);
                     return;

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java Mon Aug 24 19:16:40 2015
@@ -195,14 +195,6 @@ public class DecoratorHandler implements
             {
                 interceptorInfo = ((AbstractProducer<?>)producer).getInterceptorInfo();
             }
-            else
-            {
-                // TODO
-            }
-        }
-        else
-        {
-            // TODO
         }
     }
 

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/AbstractLifeCycle.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/AbstractLifeCycle.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/AbstractLifeCycle.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/AbstractLifeCycle.java Mon Aug 24 19:16:40 2015
@@ -30,6 +30,7 @@ import org.apache.webbeans.config.OWBLog
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.config.WebBeansFinder;
 import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.container.InjectableBeanManager;
 import org.apache.webbeans.container.InjectionResolver;
 import org.apache.webbeans.portable.events.discovery.BeforeShutdownImpl;
 import org.apache.webbeans.spi.ContainerLifecycle;
@@ -94,7 +95,7 @@ public abstract class AbstractLifeCycle
     @Override
     public BeanManager getBeanManager()
     {        
-        return beanManager;
+        return new InjectableBeanManager(beanManager);
     }
     
     @Override

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java Mon Aug 24 19:16:40 2015
@@ -58,8 +58,10 @@ public class StandaloneLifeCycle extends
     @Override
     protected void afterStartApplication(Object startupObject)
     {
-        // the ApplicationContext is already started, but we fire the event again as the userland beans are only available now
-        webBeansContext.getBeanManagerImpl().fireEvent(new Object(), InitializedLiteral.INSTANCE_APPLICATION_SCOPED);
+        // the ApplicationContext is already started, but we fire
+        // the event again as the userland beans are only available now
+        webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+            new Object(), InitializedLiteral.INSTANCE_APPLICATION_SCOPED);
 
         webBeansContext.getContextsService().startContext(RequestScoped.class, null);
         webBeansContext.getContextsService().startContext(SessionScoped.class, null);

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLoggerFacade.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLoggerFacade.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLoggerFacade.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLoggerFacade.java Mon Aug 24 19:16:40 2015
@@ -127,7 +127,7 @@ public final class WebBeansLoggerFacade
 
         if (WB_BUNDLE == null)
         {
-            throw new NullPointerException("ResourceBundle can not be null");
+            throw new IllegalStateException("ResourceBundle can not be null");
         }
         try
         {

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java Mon Aug 24 19:16:40 2015
@@ -34,7 +34,6 @@ import org.apache.webbeans.logger.WebBea
 import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
 import org.apache.webbeans.spi.plugins.OpenWebBeansJavaEEPlugin;
 import org.apache.webbeans.spi.plugins.OpenWebBeansPlugin;
-import org.apache.webbeans.spi.plugins.OpenWebBeansWebPlugin;
 
 /**
  * <p>OpenWebBeans plugins are used to extend 'core' functionality of the injection
@@ -260,24 +259,6 @@ public class PluginLoader
         return null;        
     }
     
-    public OpenWebBeansWebPlugin getWebPlugin()
-    {
-        if(!pluginsExist())
-        {
-            return null;
-        }
-        
-        for(OpenWebBeansPlugin plugin : plugins)
-        {
-            if(plugin instanceof OpenWebBeansWebPlugin)
-            {
-                return (OpenWebBeansWebPlugin)plugin;
-            }
-        }
-        
-        return null;        
-    }    
-    
     private boolean pluginsExist()
     {
         return plugins != null && plugins.size() > 0;

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java Mon Aug 24 19:16:40 2015
@@ -28,6 +28,7 @@ import java.util.Set;
 import javax.enterprise.inject.spi.Annotated;
 
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.GenericsUtil;
 
 /**
@@ -56,14 +57,9 @@ abstract class AbstractAnnotated impleme
      */
     protected AbstractAnnotated(WebBeansContext webBeansContext, Type baseType)
     {
-        if (webBeansContext == null)
-        {
-            throw new NullPointerException("no WebBeansContext");
-        }
-        if (baseType == null)
-        {
-            throw new NullPointerException("no base type");
-        }
+        Asserts.assertNotNull(webBeansContext, Asserts.PARAM_NAME_WEBBEANSCONTEXT);
+        Asserts.assertNotNull(baseType, "base type");
+        
         this.baseType = baseType;
         this.webBeansContext = webBeansContext;
     }

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/BaseProducerProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/BaseProducerProducer.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/BaseProducerProducer.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/BaseProducerProducer.java Mon Aug 24 19:16:40 2015
@@ -53,7 +53,7 @@ public abstract class BaseProducerProduc
                                 WebBeansContext webBeansContext)
     {
         super(points);
-        Asserts.assertNotNull(webBeansContext, "WebBeansContext");
+        Asserts.assertNotNull(webBeansContext, Asserts.PARAM_NAME_WEBBEANSCONTEXT);
         this.owner = owner;
         this.webBeansContext = webBeansContext;
         this.disposalIPs = disposalIPs;
@@ -127,7 +127,10 @@ public abstract class BaseProducerProduc
             }
             finally
             {
-                parentCreationalContext.release();
+                if (parentCreationalContext != null)
+                {
+                    parentCreationalContext.release();
+                }
             }
         }
     }

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanMetadataProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanMetadataProducer.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanMetadataProducer.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanMetadataProducer.java Mon Aug 24 19:16:40 2015
@@ -31,11 +31,6 @@ public class BeanMetadataProducer<T> ext
     @Override
     protected Contextual<T> produce(Map<Interceptor<?>, ?> interceptors, CreationalContextImpl<Contextual<T>> creationalContext)
     {
-        if (!(creationalContext instanceof CreationalContextImpl))
-        {
-            // TODO What to do here?
-            throw new IllegalStateException("MetadataProducer does work only with CreationalContextImpl");
-        }
         CreationalContextImpl<T> contextImpl = (CreationalContextImpl<T>)creationalContext;
         return contextImpl.getBean();
     }

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java Mon Aug 24 19:16:40 2015
@@ -79,15 +79,9 @@ public class EventProducer<T> extends Ab
     protected Event<T> produce(Map<Interceptor<?>, ?> interceptors, CreationalContextImpl<Event<T>> creationalContext)
     {
         Event<T> instance = null;
-        InjectionPoint injectionPoint = null;
-        //TODO What should we do here if creationalContext is not instanceof CreationalContextImpl?
-        if (creationalContext instanceof CreationalContextImpl)
-        {
-            injectionPoint = ((CreationalContextImpl<Event<T>>)creationalContext).getInjectionPoint();
-        }
-
         Type eventType;
-        
+
+        InjectionPoint injectionPoint = creationalContext.getInjectionPoint();
         if(injectionPoint != null)
         {
             Type[] eventActualTypeArgs;
@@ -114,12 +108,8 @@ public class EventProducer<T> extends Ab
             }           
             finally
             {
-                if (creationalContext instanceof CreationalContextImpl)
-                {
-                    ((CreationalContextImpl<Event<T>>)creationalContext).removeInjectionPoint();
-                }
+                creationalContext.removeInjectionPoint();
             }
-            
         }
                         
         return instance;

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessInjectionPoint.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessInjectionPoint.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessInjectionPoint.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessInjectionPoint.java Mon Aug 24 19:16:40 2015
@@ -42,7 +42,7 @@ public class GProcessInjectionPoint exte
             {
                 return getInjectionPoint().getBean().getBeanClass();
             }
-            else if (getInjectionPoint().getAnnotated() != null && getInjectionPoint().getAnnotated() instanceof AnnotatedMember)
+            else if (getInjectionPoint().getAnnotated() instanceof AnnotatedMember)
             {
                 return ((AnnotatedMember) getInjectionPoint().getAnnotated()).getDeclaringType().getJavaClass();
             }

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java Mon Aug 24 19:16:40 2015
@@ -55,6 +55,7 @@ public abstract class AbstractProxyFacto
 
     private static final Logger logger = WebBeansLoggerFacade.getLogger(AbstractProxyFactory.class);
 
+
     protected WebBeansContext webBeansContext;
 
     /**
@@ -65,6 +66,8 @@ public abstract class AbstractProxyFacto
     private Object unsafe = null;
     private Method unsafeAllocateInstance = null;
 
+    private final int javaVersion;
+
 
     /**
      * The name of the field which stores the passivationID of the Bean this proxy serves.
@@ -77,9 +80,35 @@ public abstract class AbstractProxyFacto
     protected AbstractProxyFactory(WebBeansContext webBeansContext)
     {
         this.webBeansContext = webBeansContext;
+        javaVersion = determineJavaVersion();
         initializeUnsafe();
     }
 
+    private int determineJavaVersion()
+    {
+        String javaVersionProp = webBeansContext.getOpenWebBeansConfiguration().getGeneratorJavaVersion();
+        if (javaVersionProp != null)
+        {
+            if (javaVersionProp.startsWith("1.7"))
+            {
+                return Opcodes.V1_7;
+            }
+            else if (javaVersionProp.startsWith("1.8"))
+            {
+                return Opcodes.V1_8;
+            }
+            else if (javaVersionProp.startsWith("1.9"))
+            {
+                // TODO upgrade to Java9 as soon as ASM really supports it!
+                return Opcodes.V1_8;
+            }
+        }
+
+        // the fallback default is V1_6
+        return Opcodes.V1_6;
+    }
+
+
     protected ClassLoader getProxyClassLoader(Class<?> beanClass)
     {
         return webBeansContext.getApplicationBoundaryService().getBoundaryClassLoader(beanClass);
@@ -249,7 +278,7 @@ public abstract class AbstractProxyFacto
                                  Method[] interceptedMethods, Method[] nonInterceptedMethods, Constructor<?> constructor)
             throws ProxyGenerationException
     {
-        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
+        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
         String classFileName = classToProxy.getName().replace('.', '/');
 
         String[] interfaceNames = new String[]{Type.getInternalName(getMarkerInterface())};
@@ -261,7 +290,7 @@ public abstract class AbstractProxyFacto
             superClassName = Type.getInternalName(Object.class);
         }
 
-        cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER + Opcodes.ACC_SYNTHETIC, proxyClassFileName, null, superClassName, interfaceNames);
+        cw.visit(javaVersion, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER + Opcodes.ACC_SYNTHETIC, proxyClassFileName, null, superClassName, interfaceNames);
         cw.visitSource(classFileName + ".java", null);
 
         createInstanceVariables(cw, classToProxy, classFileName);

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java Mon Aug 24 19:16:40 2015
@@ -247,11 +247,7 @@ public class SubclassProxyFactory extend
 
             // and finally invoke the target method on the provided Contextual Instance
             final Type declaringClass = Type.getType(delegatedMethod.getDeclaringClass());
-            if (abstractMethod)
-            {
-                // generate an empty return block
-            }
-            else
+            if (!abstractMethod)
             {
                 // invoke the method on the super class;
                 mv.visitMethodInsn(Opcodes.INVOKESPECIAL, declaringClass.getInternalName(), delegatedMethod.getName(), methodDescriptor, false);

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/Asserts.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/Asserts.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/Asserts.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/Asserts.java Mon Aug 24 19:16:40 2015
@@ -28,6 +28,8 @@ import java.lang.reflect.Method;
  */
 public final class Asserts
 {
+    public static final String PARAM_NAME_WEBBEANSCONTEXT = "WebBeansContetx";
+    public static final String PARAM_NAME_ANNOTATION = "Annotation";
 
     /*
      * Private constructor

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java Mon Aug 24 19:16:40 2015
@@ -365,11 +365,7 @@ public final class ClassUtil
             }
             else
             {
-                if (isOverridden(methods, method))
-                {
-                    // method is overridden in superclass, so do nothing
-                }
-                else
+                if (!isOverridden(methods, method))
                 {
                     // method is not overridden, so add it
                     methods.add(method);

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java Mon Aug 24 19:16:40 2015
@@ -65,6 +65,48 @@ public final class GenericsUtil
         return false;
     }
 
+    public static boolean satisfiesDependencyRaw(boolean isDelegateOrEvent, boolean isProducer, Type injectionPointType, Type beanType)
+    {
+        if (beanType instanceof TypeVariable || beanType instanceof WildcardType || beanType instanceof GenericArrayType)
+        {
+            return isAssignableFrom(isDelegateOrEvent, isProducer, injectionPointType, beanType);
+        }
+        else
+        {
+            Type injectionPointRawType = injectionPointType instanceof ParameterizedType? ((ParameterizedType)injectionPointType).getRawType(): injectionPointType;
+            Type beanRawType = beanType instanceof ParameterizedType? ((ParameterizedType)beanType).getRawType(): beanType;
+
+            if  (ClassUtil.isSame(injectionPointRawType, beanRawType))
+            {
+                return isAssignableFrom(isDelegateOrEvent, isProducer, injectionPointRawType, beanRawType);
+            }
+            else
+            {
+                Class bean = (Class) beanType;
+                if (bean.getSuperclass() != null && ClassUtil.isRawClassEquals(injectionPointType, bean.getSuperclass()))
+                {
+                    return true;
+                }
+
+                Class<?>[] interfaces = bean.getInterfaces();
+                if (interfaces == null || interfaces.length == 0)
+                {
+                    return false;
+                }
+
+                for (Class<?> clazz : interfaces)
+                {
+                    if (ClassUtil.isRawClassEquals(injectionPointType, clazz))
+                    {
+                        return true;
+                    }
+                }
+            }
+        }
+
+        return false;
+    }
+
     /**
      * 5.2.3 and 5.2.4
      */
@@ -999,6 +1041,10 @@ public final class GenericsUtil
                 {
                     subclass = iface;
                 }
+                else
+                {
+                    subclass = declaringClass.getSuperclass();
+                }
             }
             return getDirectSubclass(subclass, actualClass);
         }

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/UrlSet.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/UrlSet.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/UrlSet.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/UrlSet.java Mon Aug 24 19:16:40 2015
@@ -84,7 +84,7 @@ public class UrlSet implements Set<URL>
     @Override
     public boolean remove(Object o)
     {
-        if (o instanceof URL && o != null)
+        if (o instanceof URL)
         {
             return urlMap.remove(((URL) o).toExternalForm()) != null;
         }

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Mon Aug 24 19:16:40 2015
@@ -140,6 +140,7 @@ import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.lang.reflect.WildcardType;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.EnumSet;
@@ -1252,45 +1253,56 @@ public final class WebBeansUtil
         }
     }
 
+    private final static Set<Type> EXTENSION_BEAN_EVENT_TYPES = new HashSet<Type>(
+        Arrays.asList(new Class[]{
+            GProcessAnnotatedType.class,
+            GProcessSyntheticAnnotatedType.class,
+            GProcessInjectionPoint.class,
+            GProcessInjectionTarget.class,
+            GProcessBeanAttributes.class,
+            GProcessManagedBean.class,
+            GProcessSessionBean.class,
+            GProcessBean.class}));
     public static boolean isExtensionBeanEventType(Type type)
     {
-        return type.equals(GProcessAnnotatedType.class) ||
-               type.equals(GProcessSyntheticAnnotatedType.class) ||
-               type.equals(GProcessInjectionPoint.class) ||
-               type.equals(GProcessInjectionTarget.class) ||
-               type.equals(GProcessBeanAttributes.class) ||
-               type.equals(GProcessManagedBean.class) ||
-               type.equals(GProcessSessionBean.class) ||
-               type.equals(GProcessBean.class);
+        return EXTENSION_BEAN_EVENT_TYPES.contains(type);
     }
 
+    private final static Set<Type> DEFAULT_EXTENSION_BEAN_EVENT_TYPE = new HashSet<Type>(
+        Arrays.asList(new Class[]{
+            ProcessAnnotatedType.class,
+            ProcessSyntheticAnnotatedType.class,
+            ProcessInjectionPoint.class,
+            ProcessInjectionTarget.class,
+            ProcessBeanAttributes.class,
+            ProcessManagedBean.class,
+            ProcessBean.class,
+            ProcessSessionBean.class}));
     public static boolean isDefaultExtensionBeanEventType(Class<?> clazz)
     {
-        return clazz.equals(ProcessAnnotatedType.class) ||
-               clazz.equals(ProcessSyntheticAnnotatedType.class) ||
-               clazz.equals(ProcessInjectionPoint.class) ||
-               clazz.equals(ProcessInjectionTarget.class) ||
-               clazz.equals(ProcessBeanAttributes.class) ||
-               clazz.equals(ProcessManagedBean.class) ||
-               clazz.equals(ProcessBean.class) ||
-               clazz.equals(ProcessSessionBean.class);
+        return DEFAULT_EXTENSION_BEAN_EVENT_TYPE.contains(clazz);
     }
 
+    private final static Set<Type> EXTENSION_PRODUCER_OR_OBSERVER_EVENT_TYPE = new HashSet<Type>(
+        Arrays.asList(new Class[]{
+            GProcessProducer.class,
+            GProcessProducerField.class,
+            GProcessProducerMethod.class,
+            GProcessObservableMethod.class}));
     public static boolean isExtensionProducerOrObserverEventType(Type type)
     {
-        return type.equals(GProcessProducer.class) ||
-               type.equals(GProcessProducerField.class) ||
-               type.equals(GProcessProducerMethod.class) ||
-               type.equals(GProcessObservableMethod.class);
+        return EXTENSION_PRODUCER_OR_OBSERVER_EVENT_TYPE.contains(type);
     }
 
+    private final static Set<Type> DEFAULT_EXTENSION_PRODUCER_OR_OBSERVER_EVENT_TYPE = new HashSet<Type>(
+        Arrays.asList(new Class[]{
+            ProcessProducer.class,
+            ProcessProducerField.class,
+            ProcessProducerMethod.class,
+            ProcessObserverMethod.class}));
     public static boolean isDefaultExtensionProducerOrObserverEventType(Class<?> clazz)
     {
-        return clazz.equals(ProcessProducer.class) ||
-               clazz.equals(ProcessProducerField.class) ||
-               clazz.equals(ProcessProducerMethod.class) ||
-               clazz.equals(ProcessObserverMethod.class);
-
+        return DEFAULT_EXTENSION_PRODUCER_OR_OBSERVER_EVENT_TYPE.contains(clazz);
     }
 
     public static boolean isDependent(Bean<?> bean)

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java Mon Aug 24 19:16:40 2015
@@ -221,7 +221,10 @@ public class DefaultBeanArchiveService i
         {
             try
             {
-                xmlStream.close();
+                if (xmlStream != null)
+                {
+                    xmlStream.close();
+                }
             }
             catch (IOException ioe)
             {
@@ -454,7 +457,7 @@ public class DefaultBeanArchiveService i
                     {
                         final String value = getTrimmedAttribute(condition, "value");
                         final String systProp = System.getProperty(getTrimmedAttribute(condition, "name"));
-                        if ((value == null && systProp == null) || !value.equals(systProp))
+                        if ((value == null && systProp == null) || !(value != null && value.equals(systProp)))
                         {
                             skip = true;
                             break;

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties Mon Aug 24 19:16:40 2015
@@ -122,6 +122,10 @@ org.apache.webbeans.useBDABeansXMLScanne
 #
 # org.apache.webbeans.proxy.mapping.javax.enterprise.context.RequestScoped=org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler
 org.apache.webbeans.proxy.mapping.javax.enterprise.context.ApplicationScoped=org.apache.webbeans.intercept.ApplicationScopedBeanInterceptorHandler
+org.apache.webbeans.proxy.mapping.javax.enterprise.context.RequestScoped=org.apache.webbeans.intercept.RequestScopedBeanInterceptorHandler
+org.apache.webbeans.proxy.mapping.javax.enterprise.context.SessionScoped=org.apache.webbeans.intercept.SessionScopedBeanInterceptorHandler
+################################################################################################
+
 ################################################################################################
 
 ############################ Eager Session Initialisation ######################################
@@ -135,3 +139,13 @@ org.apache.webbeans.proxy.mapping.javax.
 #  * any other value will be interpreted as Java regular expression for request URIs which need eager Session initialization
 org.apache.webbeans.web.eagerSessionInitialisation=false
 ################################################################################################
+
+
+######################### Java version for generated proxy classes #############################
+# The Java Version to use for the generated proxy classes.
+# If "auto" then we will pick the version of the current JVM.
+# The default is set to "1.6" as some tools in jetty/tomcat/etc still
+# cannot properly handle Java8 (mostly due to older Eclipse JDT versions).
+org.apache.webbeans.generator.javaVersion=1.6
+################################################################################################
+

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/test/java/org/apache/webbeans/test/events/generics/GenericObserverTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/test/java/org/apache/webbeans/test/events/generics/GenericObserverTest.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/test/java/org/apache/webbeans/test/events/generics/GenericObserverTest.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/test/java/org/apache/webbeans/test/events/generics/GenericObserverTest.java Mon Aug 24 19:16:40 2015
@@ -53,6 +53,21 @@ public class GenericObserverTest extends
         Assert.assertTrue(instance.isExtendsNumberObserved());
     }
 
+    @Test
+    public void testOwb1066()
+    {
+        startContainer(GenericEventBean1.class);
+
+        GenericEventBean1 instance = getInstance(GenericEventBean1.class);
+        instance.fireOwb1066_Event();
+
+        Assert.assertTrue(instance.isIntegerObserved());
+        Assert.assertFalse(instance.isUnintendedListObserved());
+        Assert.assertFalse(instance.isNumberObserved());
+        Assert.assertTrue(instance.isExtendsNumberObserved());
+    }
+
+
     @RequestScoped
     public static class GenericEventBean1
     {
@@ -70,6 +85,15 @@ public class GenericObserverTest extends
             integerEvent.fire(list);
         }
 
+        /**
+         * Test for OWB-1066. Previously created an endless loop
+         */
+        public void fireOwb1066_Event()
+        {
+            List<Integer> list = Arrays.asList(1,2,3);
+            integerEvent.fire(list);
+        }
+
         public void observeTotallyDifferentList(@Observes List<Map> mapList)
         {
             unintendedListObserved = true;

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/GenericsTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/GenericsTest.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/GenericsTest.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/GenericsTest.java Mon Aug 24 19:16:40 2015
@@ -127,4 +127,11 @@ public class GenericsTest extends Abstra
         Assert.assertNotNull(bazEnum);
         Assert.assertEquals(BazEnum.YES, bazEnum);
     }
+
+    @Test
+    public void testManualLookupsOfBeansWithGenerics() {
+        startContainer(MyBean.class, MyInterface.class, MyAbstract.class, StringBean.class, StringBeanAbstract.class);
+        MyBean instance = getInstance(MyBean.class);
+        instance.checkAll();
+    }
 }

Modified: openwebbeans/branches/cdi-2.0/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/decorator/Decorator1Test.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/decorator/Decorator1Test.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/decorator/Decorator1Test.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/decorator/Decorator1Test.java Mon Aug 24 19:16:40 2015
@@ -38,6 +38,7 @@ import org.apache.webbeans.test.componen
 import org.apache.webbeans.test.component.decorator.clean.AccountComponent;
 import org.apache.webbeans.test.component.decorator.clean.LargeTransactionDecorator;
 import org.apache.webbeans.test.component.decorator.clean.ServiceDecorator;
+import org.apache.webbeans.test.component.decorator.clean.ServiceDecoratorWithCtInjectionPoint;
 import org.apache.webbeans.test.component.service.IService;
 import org.apache.webbeans.test.component.service.ServiceImpl1;
 import org.junit.Test;
@@ -101,4 +102,31 @@ public class Decorator1Test extends Abst
 
     }
 
+
+    @Test
+    public void testDecoratorWithCtDelegate()
+    {
+        addDecorator(ServiceDecoratorWithCtInjectionPoint.class);
+        addDecorator(LargeTransactionDecorator.class);
+
+        startContainer(ServiceDecoratorWithCtInjectionPoint.class, CheckWithCheckPayment.class, ServiceImpl1.class, Binding1.class);
+
+        ServiceDecoratorWithCtInjectionPoint.delegateAttr = null;
+        ServiceDecoratorWithCtInjectionPoint.ip = null;
+
+        ServiceImpl1 serviceImpl = getInstance(ServiceImpl1.class, new Annotation[]{new Binding1Literal()});
+        String s = serviceImpl.service();
+
+        Assert.assertEquals("ServiceDecoratorWithCtInjectionPoint", s);
+
+        Set<Type> apiTyeps = new HashSet<Type>();
+        apiTyeps.add(IService.class);
+
+        List<Decorator<?>> decs = getBeanManager().resolveDecorators(apiTyeps, new Annotation[]{new Binding1Literal()});
+        Assert.assertNotNull(decs);
+        Assert.assertTrue(decs.size() > 0);
+
+        Assert.assertEquals("ServiceImpl1", ServiceDecoratorWithCtInjectionPoint.delegateAttr);
+    }
+
 }

Modified: openwebbeans/branches/cdi-2.0/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/JmsProxyHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/JmsProxyHandler.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/JmsProxyHandler.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/JmsProxyHandler.java Mon Aug 24 19:16:40 2015
@@ -279,14 +279,14 @@ public class JmsProxyHandler implements
         {
             if(this.jmsObject != null)
             {
-                Method method = this.jmsObject.getClass().getMethod("close", new Class[]{});
+                Method method = this.jmsObject.getClass().getMethod("close");
                 
                 if(!method.isAccessible())
                 {
                     jmsComponent.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(method, true);
                 }
                 
-                method.invoke(this.jmsObject, new Object[]{});                
+                method.invoke(this.jmsObject);
             }
             
         }

Modified: openwebbeans/branches/cdi-2.0/webbeans-osgi/src/main/java/org/apache/webbeans/osgi/scanner/OsgiMetaDataScannerService.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-osgi/src/main/java/org/apache/webbeans/osgi/scanner/OsgiMetaDataScannerService.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-osgi/src/main/java/org/apache/webbeans/osgi/scanner/OsgiMetaDataScannerService.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-osgi/src/main/java/org/apache/webbeans/osgi/scanner/OsgiMetaDataScannerService.java Mon Aug 24 19:16:40 2015
@@ -234,7 +234,7 @@ public class OsgiMetaDataScannerService
             {
                 URL jarURL = bundle.getEntry(jarName);
 
-                logger.info("adding the following beans.xml URL: " + jarURL.toExternalForm());
+                logger.info("adding the following beans.xml URL: " + jarURL != null ? jarURL.toExternalForm() : null);
 
                 beanXMLs.add(jarURL);
                 beanArchiveJarNames.add(jarName);

Modified: openwebbeans/branches/cdi-2.0/webbeans-spi/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-spi/pom.xml?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-spi/pom.xml (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-spi/pom.xml Mon Aug 24 19:16:40 2015
@@ -39,6 +39,7 @@
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-el_2.2_spec</artifactId>
             <scope>provided</scope>
+            <optional>true</optional>
         </dependency>
 
         <dependency>
@@ -60,11 +61,13 @@
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-jta_1.1_spec</artifactId>
             <scope>provided</scope>
+            <optional>true</optional>
         </dependency>
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-validation_1.0_spec</artifactId>
             <scope>provided</scope>
+            <optional>true</optional>
         </dependency>
     </dependencies>
       

Modified: openwebbeans/branches/cdi-2.0/webbeans-spi/src/main/java/org/apache/webbeans/spi/plugins/OpenWebBeansJavaEEPlugin.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-spi/src/main/java/org/apache/webbeans/spi/plugins/OpenWebBeansJavaEEPlugin.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-spi/src/main/java/org/apache/webbeans/spi/plugins/OpenWebBeansJavaEEPlugin.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-spi/src/main/java/org/apache/webbeans/spi/plugins/OpenWebBeansJavaEEPlugin.java Mon Aug 24 19:16:40 2015
@@ -31,4 +31,10 @@ package org.apache.webbeans.spi.plugins;
 public interface OpenWebBeansJavaEEPlugin extends OpenWebBeansPlugin
 {
     boolean isEEComponent(Class<?> impl);
+
+    /**
+     * Gets invoked when the EE integration should register it's
+     * CDI Beans. E.g. ValidatorBean, PrincipalBean, etc
+     */
+    void registerEEBeans();
 }

Modified: openwebbeans/branches/cdi-2.0/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties Mon Aug 24 19:16:40 2015
@@ -33,5 +33,5 @@ org.apache.webbeans.spi.ConversationServ
 org.apache.webbeans.application.supportsConversation=true
 
 
-# we have to switch back to the un-cached version of the normal scoping handler 
+# we have to switch back to the un-cached version of the normal scoping handler
 org.apache.webbeans.proxy.mapping.javax.enterprise.context.ApplicationScoped=org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler

Modified: openwebbeans/branches/cdi-2.0/webbeans-tomcat6/src/main/java/org/apache/webbeans/web/tomcat/TomcatUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-tomcat6/src/main/java/org/apache/webbeans/web/tomcat/TomcatUtil.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-tomcat6/src/main/java/org/apache/webbeans/web/tomcat/TomcatUtil.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-tomcat6/src/main/java/org/apache/webbeans/web/tomcat/TomcatUtil.java Mon Aug 24 19:16:40 2015
@@ -70,7 +70,7 @@ public class TomcatUtil
         }
     }
 
-    private static class Instance
+    private static final class Instance
     {
         private Object object;
         private CreationalContext<?> context;

Modified: openwebbeans/branches/cdi-2.0/webbeans-tomcat6/src/main/java/org/apache/webbeans/web/tomcat/TomcatWebPlugin.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-tomcat6/src/main/java/org/apache/webbeans/web/tomcat/TomcatWebPlugin.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-tomcat6/src/main/java/org/apache/webbeans/web/tomcat/TomcatWebPlugin.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-tomcat6/src/main/java/org/apache/webbeans/web/tomcat/TomcatWebPlugin.java Mon Aug 24 19:16:40 2015
@@ -33,7 +33,7 @@ import javax.servlet.http.HttpSessionLis
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.spi.SecurityService;
 import org.apache.webbeans.spi.plugins.AbstractOwbPlugin;
-import org.apache.webbeans.spi.plugins.OpenWebBeansWebPlugin;
+import org.apache.webbeans.spi.plugins.OpenWebBeansPlugin;
 
 /**
  * Tomcat plugin for OWB.
@@ -41,7 +41,7 @@ import org.apache.webbeans.spi.plugins.O
  * @version $Rev$ $Date$
  *
  */
-public class TomcatWebPlugin extends AbstractOwbPlugin implements OpenWebBeansWebPlugin
+public class TomcatWebPlugin extends AbstractOwbPlugin implements OpenWebBeansPlugin
 {
     //Security service implementation.
     private final TomcatSecurityService securityService = new TomcatSecurityService();
@@ -128,10 +128,4 @@ public class TomcatWebPlugin extends Abs
         
         return false;
     }
-
-    @Override
-    public String currentSessionId()
-    {
-        return null; // TODO
-    }
 }

Modified: openwebbeans/branches/cdi-2.0/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/ContextLifecycleListener.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/ContextLifecycleListener.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/ContextLifecycleListener.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/ContextLifecycleListener.java Mon Aug 24 19:16:40 2015
@@ -71,8 +71,6 @@ public class ContextLifecycleListener im
 
                         context.addApplicationListener(TomcatSecurityFilter.class.getName());
                         context.addApplicationEventListener(this);
-
-                        context.addContainerListener(new TomcatContainerListener());
                     }
                 }
             }

Modified: openwebbeans/branches/cdi-2.0/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatUtil.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatUtil.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatUtil.java Mon Aug 24 19:16:40 2015
@@ -70,7 +70,7 @@ public class TomcatUtil
         }
     }
 
-    private static class Instance
+    private static final class Instance
     {
         private Object object;
         private CreationalContext<?> context;

Modified: openwebbeans/branches/cdi-2.0/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatWebPlugin.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatWebPlugin.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatWebPlugin.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatWebPlugin.java Mon Aug 24 19:16:40 2015
@@ -33,7 +33,7 @@ import javax.servlet.http.HttpSessionLis
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.spi.SecurityService;
 import org.apache.webbeans.spi.plugins.AbstractOwbPlugin;
-import org.apache.webbeans.spi.plugins.OpenWebBeansWebPlugin;
+import org.apache.webbeans.spi.plugins.OpenWebBeansPlugin;
 
 /**
  * Tomcat plugin for OWB.
@@ -41,7 +41,7 @@ import org.apache.webbeans.spi.plugins.O
  * @version $Rev: 940336 $ $Date: 2010-05-03 02:32:18 +0300 (Mon, 03 May 2010) $
  *
  */
-public class TomcatWebPlugin extends AbstractOwbPlugin implements OpenWebBeansWebPlugin
+public class TomcatWebPlugin extends AbstractOwbPlugin implements OpenWebBeansPlugin
 {
     //Security service implementation.
     private final TomcatSecurityService securityService = new TomcatSecurityService();
@@ -129,9 +129,4 @@ public class TomcatWebPlugin extends Abs
         return false;
     }
 
-    @Override
-    public String currentSessionId()
-    {
-        return null; // TODO
-    }
 }

Modified: openwebbeans/branches/cdi-2.0/webbeans-web/src/it/webcdiapp/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-web/src/it/webcdiapp/pom.xml?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-web/src/it/webcdiapp/pom.xml (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-web/src/it/webcdiapp/pom.xml Mon Aug 24 19:16:40 2015
@@ -30,6 +30,11 @@
 
     <name>Webbeans Web IT</name>
 
+    <!--
+        For locally debugging this integration test you need to first build the module.
+        Afterwards cd into target/it/webcdiapp and start tomcat with
+        $ mvn clean package tomcat7:run -Dtomcat.fork=false
+    -->
 
     <properties>
         <tomcat.version>7.0.61</tomcat.version>

Modified: openwebbeans/branches/cdi-2.0/webbeans-web/src/it/webcdiapp/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-web/src/it/webcdiapp/src/main/webapp/WEB-INF/web.xml?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
Binary files - no diff available.

Modified: openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java Mon Aug 24 19:16:40 2015
@@ -18,14 +18,26 @@
  */
 package org.apache.webbeans.servlet;
 
+import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.WebBeansContext;
-
+import org.apache.webbeans.el.ELContextStore;
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.spi.ContainerLifecycle;
+import org.apache.webbeans.spi.ContextsService;
+import org.apache.webbeans.util.WebBeansUtil;
+import org.apache.webbeans.web.util.ServletCompatibilityUtil;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.context.spi.Context;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 import javax.servlet.ServletRequestEvent;
 import javax.servlet.ServletRequestListener;
 import javax.servlet.http.HttpSessionEvent;
 import javax.servlet.http.HttpSessionListener;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * Initializing the beans container for using in an web application
@@ -39,14 +51,17 @@ import javax.servlet.http.HttpSessionLis
  * {@link WebBeansConfigurationFilter} and {@link WebBeansConfigurationHttpSessionListener}
  * instead.
  *
- * @see BeginWebBeansConfigurationListener
- * @see EndWebBeansConfigurationListener
  */
 public class WebBeansConfigurationListener implements ServletContextListener, ServletRequestListener, HttpSessionListener
 {
+    private static final Logger logger = WebBeansLoggerFacade.getLogger(WebBeansConfigurationListener.class);
+
+
+    /**Manages the container lifecycle*/
+    protected ContainerLifecycle lifeCycle = null;
+
     private WebBeansContext webBeansContext;
-    private BeginWebBeansConfigurationListener beginWebBeansConfigurationListener;
-    private EndWebBeansConfigurationListener endWebBeansConfigurationListener;
+    private ContextsService contextsService;
 
     /**
      * Default constructor
@@ -54,49 +69,161 @@ public class WebBeansConfigurationListen
     public WebBeansConfigurationListener()
     {
         webBeansContext = WebBeansContext.getInstance();
-        beginWebBeansConfigurationListener = new BeginWebBeansConfigurationListener(webBeansContext);
-        endWebBeansConfigurationListener = new EndWebBeansConfigurationListener(webBeansContext);
+        contextsService = webBeansContext.getContextsService();
     }
 
-
+    /**
+     * {@inheritDoc}
+     */
     @Override
-    public void contextInitialized(ServletContextEvent sce)
+    public void contextInitialized(ServletContextEvent event)
     {
-        beginWebBeansConfigurationListener.contextInitialized(sce);
+        this.lifeCycle = webBeansContext.getService(ContainerLifecycle.class);
 
-        // for setting the lifecycle
-        endWebBeansConfigurationListener.contextInitialized(sce);
+        try
+        {
+            this.lifeCycle.startApplication(event);
+        }
+        catch (Exception e)
+        {
+            logger.log(Level.SEVERE,
+                WebBeansLoggerFacade.constructMessage(
+                    OWBLogConst.ERROR_0018,
+                    ServletCompatibilityUtil.getServletInfo(event.getServletContext())));
+            WebBeansUtil.throwRuntimeExceptions(e);
+        }
     }
 
+
+    /**
+     * {@inheritDoc}
+     */
     @Override
-    public void contextDestroyed(ServletContextEvent sce)
+    public void requestInitialized(ServletRequestEvent event)
     {
-        endWebBeansConfigurationListener.contextDestroyed(sce);
+        try
+        {
+            if (logger.isLoggable(Level.FINE))
+            {
+                logger.log(Level.FINE, "Starting a new request : [{0}]", event == null ? "null" : event.getServletRequest().getRemoteAddr());
+            }
+
+            this.lifeCycle.getContextService().startContext(RequestScoped.class, event);
+
+            // we don't initialise the Session here but do it lazily if it gets requested
+            // the first time. See OWB-457
+        }
+        catch (Exception e)
+        {
+            logger.log(Level.SEVERE,
+                WebBeansLoggerFacade.constructMessage(OWBLogConst.ERROR_0019, event == null ? "null" : event.getServletRequest()));
+            WebBeansUtil.throwRuntimeExceptions(e);
+        }
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
-    public void sessionCreated(HttpSessionEvent se)
+    public void sessionCreated(HttpSessionEvent event)
     {
-        beginWebBeansConfigurationListener.sessionCreated(se);
+        try
+        {
+            if (logger.isLoggable(Level.FINE))
+            {
+                logger.log(Level.FINE, "Starting a session with session id : [{0}]", event.getSession().getId());
+            }
+            this.lifeCycle.getContextService().startContext(SessionScoped.class, event.getSession());
+        }
+        catch (Exception e)
+        {
+            logger.log(Level.SEVERE,
+                WebBeansLoggerFacade.constructMessage(OWBLogConst.ERROR_0020, event.getSession()));
+            WebBeansUtil.throwRuntimeExceptions(e);
+        }
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
-    public void sessionDestroyed(HttpSessionEvent se)
+    public void contextDestroyed(ServletContextEvent event)
     {
-        endWebBeansConfigurationListener.sessionDestroyed(se);
-    }
+        if (lifeCycle != null)
+        {
+            lifeCycle.stopApplication(event);
+        }
 
+        // just to be sure that we didn't lazily create anything...
+        cleanupRequestThreadLocals();
+    }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
-    public void requestInitialized(ServletRequestEvent sre)
+    public void requestDestroyed(ServletRequestEvent event)
     {
-        beginWebBeansConfigurationListener.requestInitialized(sre);
+        if (logger.isLoggable(Level.FINE))
+        {
+            logger.log(Level.FINE, "Destroying a request : [{0}]", event == null ? "null" : event.getServletRequest().getRemoteAddr());
+        }
+
+        // clean up the EL caches after each request
+        ELContextStore elStore = ELContextStore.getInstance(false);
+        if (elStore != null)
+        {
+            elStore.destroyELContextStore();
+        }
+
+        this.lifeCycle.getContextService().endContext(RequestScoped.class, event);
+
+        this.cleanupRequestThreadLocals();
     }
 
+
+    /**
+     * {@inheritDoc}
+     */
     @Override
-    public void requestDestroyed(ServletRequestEvent sre)
+    public void sessionDestroyed(HttpSessionEvent event)
+    {
+        if (logger.isLoggable(Level.FINE))
+        {
+            logger.log(Level.FINE, "Destroying a session with session id : [{0}]", event.getSession().getId());
+        }
+        boolean mustDestroy = ensureRequestScope();
+
+        this.lifeCycle.getContextService().endContext(SessionScoped.class, event.getSession());
+
+        if (mustDestroy)
+        {
+            requestDestroyed(null);
+        }
+    }
+
+    private boolean ensureRequestScope()
+    {
+        Context context = this.lifeCycle.getContextService().getCurrentContext(RequestScoped.class);
+
+        if (context == null || !context.isActive())
+        {
+            requestInitialized(null);
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Ensures that all ThreadLocals, which could have been set in this
+     * requests Thread, are removed in order to prevent memory leaks.
+     */
+    private void cleanupRequestThreadLocals()
     {
-        endWebBeansConfigurationListener.requestDestroyed(sre);
+        if (contextsService != null)
+        {
+            contextsService.removeThreadLocals();
+        }
     }
 
 }

Modified: openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java Mon Aug 24 19:16:40 2015
@@ -32,8 +32,10 @@ import org.apache.webbeans.context.Sessi
 import org.apache.webbeans.context.SingletonContext;
 import org.apache.webbeans.conversation.ConversationManager;
 import org.apache.webbeans.el.ELContextStore;
+import org.apache.webbeans.event.NotificationManager;
+import org.apache.webbeans.intercept.SessionScopedBeanInterceptorHandler;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
-import org.apache.webbeans.web.intercept.RequestScopedBeanInterceptorHandler;
+import org.apache.webbeans.intercept.RequestScopedBeanInterceptorHandler;
 
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.context.ContextException;
@@ -96,6 +98,7 @@ public class WebContextsService extends
     protected Pattern eagerSessionPattern = null;
 
 
+    protected Boolean fireRequestLifecycleEvents = null;
 
     /**
      * Creates a new instance.
@@ -234,6 +237,7 @@ public class WebContextsService extends
         else if(scopeType.equals(Dependent.class))
         {
             //Do nothing
+            return;
         }
         else if (scopeType.equals(Singleton.class))
         {
@@ -317,6 +321,7 @@ public class WebContextsService extends
         else if (scopeType.equals(Dependent.class))
         {
             //Do nothing
+            return;
         }
         else if (scopeType.equals(Singleton.class))
         {
@@ -344,7 +349,7 @@ public class WebContextsService extends
 
         Object payload = null;
 
-        if(startupObject != null && startupObject instanceof ServletRequestEvent)
+        if(startupObject instanceof ServletRequestEvent)
         {
             HttpServletRequest request = (HttpServletRequest) ((ServletRequestEvent) startupObject).getServletRequest();
             requestContext.setServletRequest(request);
@@ -359,7 +364,11 @@ public class WebContextsService extends
                 }
             }
         }
-        webBeansContext.getBeanManagerImpl().fireEvent(payload != null ? payload : new Object(), InitializedLiteral.INSTANCE_REQUEST_SCOPED);
+        if (shouldFireRequestLifecycleEvents())
+        {
+            webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+                payload != null ? payload : new Object(), InitializedLiteral.INSTANCE_REQUEST_SCOPED);
+        }
     }
 
     protected boolean shouldEagerlyInitializeSession(HttpServletRequest request)
@@ -401,10 +410,16 @@ public class WebContextsService extends
             Object payload = null;
             if (context.getServletRequest() != null)
             {
-                payload = context.getServletRequest().getSession();
+                payload = context.getHttpSession();
+                if (payload == null)
+                {
+                    // in tomcat it will be null if invalidate was called
+                    payload = context.getServletRequest().getSession(false);
+                }
             }
 
-            webBeansContext.getBeanManagerImpl().fireEvent(payload != null ? payload : new Object(), DestroyedLiteral.INSTANCE_SESSION_SCOPED);
+            webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+                payload != null ? payload : new Object(), DestroyedLiteral.INSTANCE_SESSION_SCOPED);
 
         }
 
@@ -417,13 +432,21 @@ public class WebContextsService extends
             elStore.destroyELContextStore();
         }
 
-        Object payload = null;
-
-        if (endObject != null && endObject instanceof ServletRequestEvent)
+        if (shouldFireRequestLifecycleEvents())
         {
-            payload = ((ServletRequestEvent) endObject).getServletRequest();
+            Object payload = null;
+
+            if (endObject != null && endObject instanceof ServletRequestEvent)
+            {
+                payload = ((ServletRequestEvent) endObject).getServletRequest();
+            }
+            webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+                payload != null ? payload : new Object(), DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
         }
-        webBeansContext.getBeanManagerImpl().fireEvent(payload != null ? payload : new Object(), DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
+
+        // clean the proxy cache ThreadLocals
+        RequestScopedBeanInterceptorHandler.removeThreadLocals();
+        SessionScopedBeanInterceptorHandler.removeThreadLocals();
 
         //Clear thread locals
         conversationContexts.set(null);
@@ -464,7 +487,8 @@ public class WebContextsService extends
                     {
                         currentSessionContext = new SessionContext();
                         currentSessionContext.setActive(true);
-                        webBeansContext.getBeanManagerImpl().fireEvent(session, InitializedLiteral.INSTANCE_SESSION_SCOPED);
+                        webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+                            session, InitializedLiteral.INSTANCE_SESSION_SCOPED);
                         session.setAttribute(OWB_SESSION_CONTEXT_ATTRIBUTE_NAME, currentSessionContext);
                     }
                 }
@@ -495,7 +519,7 @@ public class WebContextsService extends
         // whether the session is destroyed because it is expired
         boolean sessionIsExpiring = false;
 
-        if (endObject != null && endObject instanceof HttpSession)
+        if (endObject instanceof HttpSession)
         {
             session = (HttpSession) endObject;
             if (context == null && session.getAttribute(OWB_SESSION_CONTEXT_ATTRIBUTE_NAME) != null)
@@ -518,11 +542,13 @@ public class WebContextsService extends
             ServletRequestContext requestContext = getRequestContext(true);
 
             if (destroySessionImmediately
-                    || requestContext == null || requestContext.getServletRequest() == null || requestContext.getServletRequest().getSession() == null
-                    || sessionIsExpiring)
+                || requestContext == null || requestContext.getServletRequest() == null
+                || requestContext.getServletRequest().getSession(false) == null
+                || sessionIsExpiring)
             {
                 context.destroy();
-                webBeansContext.getBeanManagerImpl().fireEvent(session != null ? session : new Object(), DestroyedLiteral.INSTANCE_SESSION_SCOPED);
+                webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+                    session != null ? session : new Object(), DestroyedLiteral.INSTANCE_SESSION_SCOPED);
 
                 // Clear thread locals
                 sessionContexts.set(null);
@@ -531,9 +557,13 @@ public class WebContextsService extends
             else
             {
                 requestContext.setPropagatedSessionContext(context);
+                // this is to be spec compliant but depending the servlet container
+                // it can be dangerous if sessions are pooled (ie you can fire a session used by another request)
+                requestContext.setHttpSession(session);
             }
         }
 
+        SessionScopedBeanInterceptorHandler.removeThreadLocals();
     }
 
 
@@ -561,7 +591,7 @@ public class WebContextsService extends
      */
     protected void initApplicationContext(Object startupObject)
     {
-        if (applicationContext != null)
+        if (applicationContext != null && !applicationContext.isDestroyed())
         {
             applicationContext.setActive(true);
             return;
@@ -584,14 +614,15 @@ public class WebContextsService extends
     protected void destroyApplicationContext(Object endObject)
     {
         //Destroy context
-        if(applicationContext != null)
+        if(applicationContext != null && !applicationContext.isDestroyed())
         {
             applicationContext.destroy();
             // this is needed to get rid of ApplicationScoped beans which are cached inside the proxies...
             webBeansContext.getBeanManagerImpl().clearCacheProxies();
 
-            Object payload = endObject != null && endObject instanceof ServletContext ? endObject : new Object();
-            webBeansContext.getBeanManagerImpl().fireEvent(payload, DestroyedLiteral.INSTANCE_APPLICATION_SCOPED);
+            Object payload = endObject instanceof ServletContext ? endObject : new Object();
+            webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+                payload, DestroyedLiteral.INSTANCE_APPLICATION_SCOPED);
         }
     }
     
@@ -612,8 +643,10 @@ public class WebContextsService extends
             {
                 singletonContext = new SingletonContext();
                 singletonContext.setActive(true);
-                Object payLoad = startupObject != null && startupObject instanceof ServletContext ? (ServletContext) startupObject : new Object();
-                webBeansContext.getBeanManagerImpl().fireEvent(payLoad, InitializedLiteral.INSTANCE_SINGLETON_SCOPED);
+                Object payLoad = startupObject instanceof ServletContext
+                    ? (ServletContext) startupObject : new Object();
+                webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+                    payLoad, InitializedLiteral.INSTANCE_SINGLETON_SCOPED);
             }
         }
     }
@@ -629,7 +662,8 @@ public class WebContextsService extends
             singletonContext.destroy();
             singletonContext = null;
             Object payload = endObject != null ? endObject : new Object();
-            webBeansContext.getBeanManagerImpl().fireEvent(payload, DestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
+            webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+                payload, DestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
         }
     }
 
@@ -644,7 +678,7 @@ public class WebContextsService extends
             return;
         }
 
-        if (startObject != null && startObject instanceof ConversationContext)
+        if (startObject instanceof ConversationContext)
         {
             //X TODO check if this branch is still needed
             ConversationContext context = (ConversationContext) startObject;
@@ -668,7 +702,8 @@ public class WebContextsService extends
         if (context != null)
         {
             context.destroy();
-            webBeansContext.getBeanManagerImpl().fireEvent(new Object(), DestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
+            webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+                new Object(), DestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
         }
 
         conversationContexts.set(null);
@@ -726,8 +761,9 @@ public class WebContextsService extends
 
                 if (conversationContext.getConversation().isTransient())
                 {
-                    webBeansContext.getBeanManagerImpl().fireEvent(conversationManager.getLifecycleEventPayload(conversationContext),
-                            InitializedLiteral.INSTANCE_CONVERSATION_SCOPED);
+                    webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+                        conversationManager.getLifecycleEventPayload(conversationContext),
+                        InitializedLiteral.INSTANCE_CONVERSATION_SCOPED);
                 }
 
 
@@ -741,6 +777,18 @@ public class WebContextsService extends
         return conversationContext;
     }
 
+    protected boolean shouldFireRequestLifecycleEvents()
+    {
+        if (fireRequestLifecycleEvents == null)
+        {
+            NotificationManager notificationManager = webBeansContext.getBeanManagerImpl().getNotificationManager();
+            fireRequestLifecycleEvents
+                = notificationManager.hasContextLifecycleObserver(InitializedLiteral.INSTANCE_REQUEST_SCOPED) ||
+                  notificationManager.hasContextLifecycleObserver(DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
+        }
+
+        return fireRequestLifecycleEvents;
+    }
 
 
     /**

Modified: openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebConversationService.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebConversationService.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebConversationService.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebConversationService.java Mon Aug 24 19:16:40 2015
@@ -24,7 +24,6 @@ import javax.servlet.http.HttpSession;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.context.RequestContext;
 import org.apache.webbeans.spi.ContextsService;
 import org.apache.webbeans.spi.ConversationService;
 
@@ -126,11 +125,7 @@ public class WebConversationService impl
         ContextsService contextsService = webBeansContext.getContextsService();
         if (contextsService instanceof WebContextsService)
         {
-            RequestContext requestContext = ((WebContextsService) contextsService).getRequestContext(false);
-            if (requestContext instanceof ServletRequestContext)
-            {
-                return ((ServletRequestContext) requestContext).getServletRequest();
-            }
+            return ((WebContextsService) contextsService).getRequestContext(false).getServletRequest();
         }
 
         return null;

Modified: openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java Mon Aug 24 19:16:40 2015
@@ -113,17 +113,24 @@ public final class WebContainerLifecycle
             setJspELFactory((ServletContext) startupObject, resolver);
         }
 
-        // Add BeanManager to the 'javax.enterprise.inject.spi.BeanManager' servlet context attribute
-        ServletContext servletContext = (ServletContext)(startupObject);
-        servletContext.setAttribute(BeanManager.class.getName(), getBeanManager());
+        ServletContext servletContext =  null;
+        if (startupObject instanceof ServletContext)
+        {
+            servletContext = (ServletContext)(startupObject);
+
+            // Add BeanManager to the 'javax.enterprise.inject.spi.BeanManager' servlet context attribute
+            servletContext.setAttribute(BeanManager.class.getName(), getBeanManager());
+        }
 
         // fire @Initialized(ApplicationScoped.class) if any observer for it exists
-        if (webBeansContext.getBeanManagerImpl().getNotificationManager().hasLifecycleObserver(InitializedLiteral.INSTANCE_APPLICATION_SCOPED))
+        if (webBeansContext.getBeanManagerImpl().getNotificationManager().
+            hasContextLifecycleObserver(InitializedLiteral.INSTANCE_APPLICATION_SCOPED))
         {
             // we need to temporarily start the ReqeustContext
             webBeansContext.getContextsService().startContext(RequestScoped.class, null);
 
-            webBeansContext.getBeanManagerImpl().fireEvent(servletContext != null ? servletContext : new Object(), InitializedLiteral.INSTANCE_APPLICATION_SCOPED);
+            webBeansContext.getBeanManagerImpl().fireEvent(
+                servletContext != null ? servletContext : new Object(), InitializedLiteral.INSTANCE_APPLICATION_SCOPED);
 
             // shut down the RequestContext again
             webBeansContext.getContextsService().endContext(RequestScoped.class, null);

Modified: openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/util/ServletCompatibilityUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/util/ServletCompatibilityUtil.java?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/util/ServletCompatibilityUtil.java (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-web/src/main/java/org/apache/webbeans/web/util/ServletCompatibilityUtil.java Mon Aug 24 19:16:40 2015
@@ -23,7 +23,7 @@ import javax.servlet.ServletContext;
 /**
  * This utility helps to be compatible with Servlet API 2.4
  */
-public class ServletCompatibilityUtil
+public final class ServletCompatibilityUtil
 {
 
     // avoid instantiation

Modified: openwebbeans/branches/cdi-2.0/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL: http://svn.apache.org/viewvc/openwebbeans/branches/cdi-2.0/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1697484&r1=1697483&r2=1697484&view=diff
==============================================================================
--- openwebbeans/branches/cdi-2.0/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties (original)
+++ openwebbeans/branches/cdi-2.0/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties Mon Aug 24 19:16:40 2015
@@ -48,13 +48,6 @@ org.apache.webbeans.spi.ContextsService=
 org.apache.webbeans.application.jsp=false
 ################################################################################################
 
-########################### Proxy Implmenentation Mapping ######################################
-# This allows mapping a Scope Annotation class to a specific InterceptorProxy which are
-# typically sub classes of NormalScopedBeanInterceptorHandler
-#
-org.apache.webbeans.proxy.mapping.javax.enterprise.context.RequestScoped=org.apache.webbeans.web.intercept.RequestScopedBeanInterceptorHandler
-################################################################################################
-
 ################################### Default Conversation Service ###############################
 # Servlet related implementation of org.apache.webbeans.corespi.ConversationService.
 # This one does support conversation propagation via cid request parameter.



Mime
View raw message