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 2011/01/07 13:38:24 UTC

svn commit: r1056287 - in /openwebbeans/trunk: webbeans-el10/src/main/java/org/apache/webbeans/el10/ webbeans-impl/src/main/java/org/apache/webbeans/el/ webbeans-impl/src/main/java/org/apache/webbeans/plugins/ webbeans-jsf/src/main/java/org/apache/webb...

Author: gerdogdu
Date: Fri Jan  7 12:38:23 2011
New Revision: 1056287

URL: http://svn.apache.org/viewvc?rev=1056287&view=rev
Log:
[OWB-514] Leak in ELContextStore

Modified:
    openwebbeans/trunk/webbeans-el10/src/main/java/org/apache/webbeans/el10/EL10Resolver.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java
    openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/plugin/OpenWebBeansJsfPlugin.java
    openwebbeans/trunk/webbeans-jsf12/src/main/java/org/apache/webbeans/jsf12/plugin/OpenWebBeansJsfPlugin.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java

Modified: openwebbeans/trunk/webbeans-el10/src/main/java/org/apache/webbeans/el10/EL10Resolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-el10/src/main/java/org/apache/webbeans/el10/EL10Resolver.java?rev=1056287&r1=1056286&r2=1056287&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-el10/src/main/java/org/apache/webbeans/el10/EL10Resolver.java (original)
+++ openwebbeans/trunk/webbeans-el10/src/main/java/org/apache/webbeans/el10/EL10Resolver.java Fri Jan  7 12:38:23 2011
@@ -31,8 +31,10 @@ import javax.enterprise.context.Dependen
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 
+import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.el.ELContextStore;
+import org.apache.webbeans.spi.plugins.AbstractOwbJsfPlugin;
 
 public class EL10Resolver extends ELResolver
 {
@@ -59,9 +61,27 @@ public class EL10Resolver extends ELReso
     }
 
     @Override
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({"unchecked","deprecation"})
     public Object getValue(ELContext context, Object obj, Object property) throws NullPointerException, PropertyNotFoundException, ELException
     {
+        //Check that application is OWB enabled
+        //For JSF applications that are not
+        //OWB enabled, no need to go with this resolver....
+        AbstractOwbJsfPlugin jsfPlugin = WebBeansContext.getInstance().getPluginLoader().getJsfPlugin();
+        
+        //No JSF plugin, sure that not OWB  
+        if(jsfPlugin == null)
+        {
+            return null;
+        }        
+        else
+        {
+            if(!jsfPlugin.isOwbApplication())
+            {
+                return null;
+            }
+        }
+        
         //Bean instance
         Object contextualInstance = null;
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java?rev=1056287&r1=1056286&r2=1056287&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java Fri Jan  7 12:38:23 2011
@@ -31,7 +31,9 @@ import javax.enterprise.context.Dependen
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 
+import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.spi.plugins.AbstractOwbJsfPlugin;
 
 /**
  * JSF or JSP expression language a.k.a EL resolver.
@@ -89,18 +91,38 @@ public class WebBeansELResolver extends 
      * {@inheritDoc}
      */    
     @Override
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({"unchecked","deprecation"})
     public Object getValue(ELContext context, Object obj, Object property) throws NullPointerException, PropertyNotFoundException, ELException
     {
+        //Check that application is OWB enabled
+        //For JSF applications that are not
+        //OWB enabled, no need to go with this resolver....
+        AbstractOwbJsfPlugin jsfPlugin = WebBeansContext.getInstance().getPluginLoader().getJsfPlugin();
+        
+        //No JSF plugin, sure that not OWB  
+        if(jsfPlugin == null)
+        {
+            return null;
+        }        
+        //If PluginLoader is called by application explicitly
+        //But not OWB application
+        else
+        {
+            if(!jsfPlugin.isOwbApplication())
+            {
+                return null;
+            }
+        }
+        
         //Bean instance
         Object contextualInstance = null;
-
+        ELContextStore elContextStore = null;
         if (obj == null)
         {
             //Name of the bean
             String name = (String) property;
             //Local store, create if not exist
-            ELContextStore elContextStore = ELContextStore.getInstance(true);
+            elContextStore = ELContextStore.getInstance(true);
 
             contextualInstance = elContextStore.findBeanByName(name);
 
@@ -134,7 +156,7 @@ public class WebBeansELResolver extends 
                 }
             }
         }
-
+        
         return contextualInstance;
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java?rev=1056287&r1=1056286&r2=1056287&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java Fri Jan  7 12:38:23 2011
@@ -29,6 +29,7 @@ import org.apache.webbeans.config.OWBLog
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.spi.plugins.AbstractOwbJsfPlugin;
 import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
 import org.apache.webbeans.spi.plugins.OpenWebBeansJavaEEPlugin;
 import org.apache.webbeans.spi.plugins.OpenWebBeansPlugin;
@@ -184,6 +185,11 @@ public class PluginLoader
      */
     public OpenWebBeansEjbPlugin getEjbPlugin()
     {
+        if(!pluginsExist())
+        {
+            return null;
+        }
+        
         for(OpenWebBeansPlugin plugin : this.plugins)
         {
             if(plugin instanceof OpenWebBeansEjbPlugin)
@@ -194,6 +200,30 @@ public class PluginLoader
         
         return null;
     }
+    
+    /**
+     * Gets JSF plugin.
+     * 
+     * @return JSF plugin
+     */
+    public AbstractOwbJsfPlugin getJsfPlugin()
+    {
+        if(!pluginsExist())
+        {
+            return null;
+        }
+        
+        for(OpenWebBeansPlugin plugin : this.plugins)
+        {
+            if(plugin instanceof AbstractOwbJsfPlugin)
+            {
+                return (AbstractOwbJsfPlugin)plugin;
+            }
+        }
+        
+        return null;
+    }   
+    
  
     /**
      * Gets ejb lifecycle annotations plugin
@@ -202,6 +232,11 @@ public class PluginLoader
      */
     public OpenWebBeansEjbLCAPlugin getEjbLCAPlugin()
     {
+        if(!pluginsExist())
+        {
+            return null;
+        }
+        
         for(OpenWebBeansPlugin plugin : this.plugins)
         {
             if(plugin instanceof OpenWebBeansEjbLCAPlugin)
@@ -219,6 +254,11 @@ public class PluginLoader
      */
     public OpenWebBeansJmsPlugin getJmsPlugin()
     {
+        if(!pluginsExist())
+        {
+            return null;
+        }
+        
         for(OpenWebBeansPlugin plugin : this.plugins)
         {
             if(plugin instanceof OpenWebBeansJmsPlugin)
@@ -233,6 +273,11 @@ public class PluginLoader
     
     public OpenWebBeansJavaEEPlugin getJavaEEPlugin()
     {
+        if(!pluginsExist())
+        {
+            return null;
+        }
+        
         for(OpenWebBeansPlugin plugin : this.plugins)
         {
             if(plugin instanceof OpenWebBeansJavaEEPlugin)
@@ -246,6 +291,11 @@ public class PluginLoader
     
     public OpenWebBeansWebPlugin getWebPlugin()
     {
+        if(!pluginsExist())
+        {
+            return null;
+        }
+        
         for(OpenWebBeansPlugin plugin : this.plugins)
         {
             if(plugin instanceof OpenWebBeansWebPlugin)
@@ -257,6 +307,15 @@ public class PluginLoader
         return null;        
     }    
     
+    private boolean pluginsExist()
+    {
+        if(this.plugins == null)
+        {
+            return false;
+        }
+        
+        return true;
+    }
     
     public boolean isShowDown()
     {

Modified: openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/plugin/OpenWebBeansJsfPlugin.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/plugin/OpenWebBeansJsfPlugin.java?rev=1056287&r1=1056286&r2=1056287&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/plugin/OpenWebBeansJsfPlugin.java (original)
+++ openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/plugin/OpenWebBeansJsfPlugin.java Fri Jan  7 12:38:23 2011
@@ -19,14 +19,17 @@
 package org.apache.webbeans.jsf.plugin;
 
 import javax.faces.component.UIComponent;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.servlet.ServletContext;
 
+import org.apache.webbeans.config.OpenWebBeansConfiguration;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
-import org.apache.webbeans.spi.plugins.AbstractOwbPlugin;
+import org.apache.webbeans.spi.plugins.AbstractOwbJsfPlugin;
 import org.apache.webbeans.util.ClassUtil;
 
-public class OpenWebBeansJsfPlugin extends AbstractOwbPlugin
+public class OpenWebBeansJsfPlugin extends AbstractOwbJsfPlugin
 {
-
     /** {@inheritDoc} */
     public void isManagedBean( Class<?> clazz ) throws WebBeansConfigurationException 
     {
@@ -36,4 +39,20 @@ public class OpenWebBeansJsfPlugin exten
                                                      + " can not implement JSF UIComponent");
         }
     }
+    
+    @Override
+    public boolean isOwbApplication()
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        if(facesContext == null)
+        {
+            throw new IllegalStateException("FacesContext is null");
+        }
+        
+        ExternalContext ext = facesContext.getExternalContext();
+        ServletContext servletContext = (ServletContext) ext.getContext();
+        Object attribute = servletContext.getAttribute(OpenWebBeansConfiguration.PROPERTY_OWB_APPLICATION);
+        
+        return attribute != null ? true : false;
+    }
 }

Modified: openwebbeans/trunk/webbeans-jsf12/src/main/java/org/apache/webbeans/jsf12/plugin/OpenWebBeansJsfPlugin.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jsf12/src/main/java/org/apache/webbeans/jsf12/plugin/OpenWebBeansJsfPlugin.java?rev=1056287&r1=1056286&r2=1056287&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-jsf12/src/main/java/org/apache/webbeans/jsf12/plugin/OpenWebBeansJsfPlugin.java (original)
+++ openwebbeans/trunk/webbeans-jsf12/src/main/java/org/apache/webbeans/jsf12/plugin/OpenWebBeansJsfPlugin.java Fri Jan  7 12:38:23 2011
@@ -18,15 +18,19 @@
  */
 package org.apache.webbeans.jsf12.plugin;
 
+
 import javax.faces.component.UIComponent;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.servlet.ServletContext;
 
+import org.apache.webbeans.config.OpenWebBeansConfiguration;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
-import org.apache.webbeans.spi.plugins.AbstractOwbPlugin;
+import org.apache.webbeans.spi.plugins.AbstractOwbJsfPlugin;
 import org.apache.webbeans.util.ClassUtil;
 
-public class OpenWebBeansJsfPlugin extends AbstractOwbPlugin
+public class OpenWebBeansJsfPlugin extends AbstractOwbJsfPlugin
 {
-
     /** {@inheritDoc} */
     public void isManagedBean( Class<?> clazz ) throws WebBeansConfigurationException 
     {
@@ -36,4 +40,23 @@ public class OpenWebBeansJsfPlugin exten
                                                      + " can not implement JSF UIComponent");
         }
     }
+
+    @Override
+    public boolean isOwbApplication()
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        if(facesContext == null)
+        {
+            throw new IllegalStateException("FacesContext is null");
+        }
+        
+        ExternalContext ext = facesContext.getExternalContext();
+        ServletContext servletContext = (ServletContext) ext.getContext();
+        Object attribute = servletContext.getAttribute(OpenWebBeansConfiguration.PROPERTY_OWB_APPLICATION);
+        
+        return attribute != null ? true : false;
+    }
+    
+    
+    
 }

Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java?rev=1056287&r1=1056286&r2=1056287&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java (original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java Fri Jan  7 12:38:23 2011
@@ -91,7 +91,7 @@ public final class WebContainerLifecycle
      */
     protected void afterStartApplication(Object startupObject) throws Exception
     {
-        String strDelay = WebBeansContext.getInstance().getOpenWebBeansConfiguration().getProperty(OpenWebBeansConfiguration.CONVERSATION_PERIODIC_DELAY,"150000");
+        String strDelay = getWebBeansContext().getOpenWebBeansConfiguration().getProperty(OpenWebBeansConfiguration.CONVERSATION_PERIODIC_DELAY,"150000");
         long delay = Long.parseLong(strDelay);
 
         service = Executors.newScheduledThreadPool(1);
@@ -115,7 +115,7 @@ public final class WebContainerLifecycle
                 logger.debug("Default JSPFactroy instance has not found");
             }
         }
-
+        
         // Add BeanManager to the 'javax.enterprise.inject.spi.BeanManager' servlet context attribute
         ServletContext servletContext = (ServletContext)(startupObject);
         servletContext.setAttribute(BeanManager.class.getName(), getBeanManager());



Re: svn commit: r1056287 - in /openwebbeans/trunk: webbeans-el10/src/main/java/org/apache/webbeans/el10/ webbeans-impl/src/main/java/org/apache/webbeans/el/ webbeans-impl/src/main/java/org/apache/webbeans/plugins/ webbeans-jsf/src/main/java/org/apache/webb...

Posted by David Jencks <da...@yahoo.com>.
Before concealing the use of WebBeansContext.getInstance() with this annotation I'd like to see a comment explaining why this is the only way to get the WebBeansContext.

thanks
david jencks

On Jan 7, 2011, at 4:38 AM, gerdogdu@apache.org wrote:

>     @Override
> -    @SuppressWarnings("unchecked")
> +    @SuppressWarnings({"unchecked","deprecation"})
>     public Object getValue(ELContext context, Object obj, Object property) throws NullPointerException, PropertyNotFoundException, ELException
>     {