geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1026156 - in /geronimo/server/trunk/plugins: j2ee/geronimo-j2ee/ j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/ jetty8/geronimo-jetty8/ jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/ jetty8/geronimo...
Date Thu, 21 Oct 2010 22:09:04 GMT
Author: djencks
Date: Thu Oct 21 22:09:03 2010
New Revision: 1026156

URL: http://svn.apache.org/viewvc?rev=1026156&view=rev
Log:
GERONIMO-5050 mostly a thread/module based singleton scheme for OWB, and a bunch of other tweaks

Added:
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ThreadSingletonServiceAdapter.java   (with props)
    geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/GeronimoSingletonService.java   (with props)
    geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OpenWebBeansWebInitializer.java
      - copied, changed from r1022717, geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OpenWebBeansGBean.java
    geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/SingletonServiceInitializerGBean.java   (with props)
    geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/WebBeansConfigurationListener.java   (with props)
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/interceptor/OWBBeforeAfter.java   (with props)
Removed:
    geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OpenWebBeansGBean.java
Modified:
    geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/pom.xml
    geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
    geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/pom.xml
    geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/WebAppContextWrapper.java
    geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java
    geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/IntegrationContext.java
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/pom.xml
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbModuleImpl.java
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
    geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansModuleBuilderExtension.java
    geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OsgiMetaDataScannerService.java
    geronimo/server/trunk/plugins/openwebbeans/openwebbeans/src/main/plan/plan.xml
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/pom.xml?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/pom.xml (original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/pom.xml Thu Oct 21 22:09:03 2010
@@ -64,6 +64,56 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.openwebbeans</groupId>
+            <artifactId>openwebbeans-impl</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.openwebbeans</groupId>
+            <artifactId>openwebbeans-spi</artifactId>
+        </dependency>
+        <!--TODO can this be optional? -->
+        <dependency>
+            <groupId>org.apache.geronimo.bundles</groupId>
+            <artifactId>scannotation</artifactId>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.servicemix.bundles</groupId>
+            <artifactId>org.apache.servicemix.bundles.javassist</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-annotation_1.1_spec</artifactId>
+        </dependency>
+      
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jcdi_1.0_spec</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-interceptor_1.1_spec</artifactId>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-atinject_1.0_spec</artifactId>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-el_2.2_spec</artifactId>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-validation_1.0_spec</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.geronimo.framework</groupId>
             <artifactId>geronimo-kernel</artifactId>
             <version>${project.version}</version>

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java (original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java Thu Oct 21 22:09:03 2010
@@ -33,6 +33,7 @@ import java.util.Set;
 import javax.naming.Context;
 import javax.naming.NamingException;
 
+import org.apache.webbeans.inject.OWBInjector;
 import org.apache.xbean.recipe.ConstructionException;
 import org.apache.xbean.recipe.ObjectRecipe;
 import org.apache.xbean.recipe.Option;
@@ -178,6 +179,14 @@ public class Holder implements Serializa
         } catch (ConstructionException e) {
             throw (InstantiationException)new InstantiationException("Could not construct object").initCause(e);
         }
+        // TODO we likely don't want to create a new one each time -- investigate the destroy() method
+        OWBInjector beanInjector = new OWBInjector();
+        try {
+            beanInjector.inject(result);
+        } catch (Exception e) {
+            throw (InstantiationException)new InstantiationException("web beans injection problem").initCause(e);
+        }
+
         if (getPostConstruct() != null) {
             try {
                 apply(result, null, postConstruct);

Modified: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/pom.xml?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/pom.xml (original)
+++ geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/pom.xml Thu Oct 21 22:09:03 2010
@@ -61,6 +61,12 @@
             <artifactId>geronimo-web</artifactId>
             <version>${project.version}</version>
         </dependency>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.modules</groupId>
+            <artifactId>geronimo-openwebbeans</artifactId>
+            <version>${project.version}</version>
+        </dependency>
 
         <dependency>
             <groupId>org.apache.geronimo.framework</groupId>

Modified: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/WebAppContextWrapper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/WebAppContextWrapper.java?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/WebAppContextWrapper.java (original)
+++ geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/WebAppContextWrapper.java Thu Oct 21 22:09:03 2010
@@ -17,7 +17,6 @@
 
 package org.apache.geronimo.jetty8;
 
-import java.net.URL;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Hashtable;
@@ -49,12 +48,12 @@ import org.apache.geronimo.j2ee.manageme
 import org.apache.geronimo.jetty8.handler.GeronimoWebAppContext;
 import org.apache.geronimo.jetty8.handler.IntegrationContext;
 import org.apache.geronimo.jetty8.security.SecurityHandlerFactory;
-import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.ObjectNameUtil;
 import org.apache.geronimo.management.J2EEApplication;
 import org.apache.geronimo.management.J2EEServer;
 import org.apache.geronimo.management.geronimo.WebContainer;
 import org.apache.geronimo.management.geronimo.WebModule;
+import org.apache.geronimo.openwebbeans.OpenWebBeansWebInitializer;
 import org.apache.geronimo.security.jacc.ApplicationPolicyConfigurationManager;
 import org.apache.geronimo.security.jacc.RunAsSource;
 import org.apache.geronimo.transaction.GeronimoUserTransaction;
@@ -297,6 +296,8 @@ public class WebAppContextWrapper implem
         }
         //supply web.xml to jasper
         webAppContext.setAttribute(JASPER_WEB_XML_NAME, originalSpecDD);
+        new OpenWebBeansWebInitializer(integrationContext.getOWBContext(), webAppContext.getServletContext());
+
     }
 
 

Modified: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java (original)
+++ geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java Thu Oct 21 22:09:03 2010
@@ -39,11 +39,9 @@ import javax.servlet.Servlet;
 import javax.servlet.ServletContainerInitializer;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRegistration;
-import javax.servlet.ServletRegistration.Dynamic;
 import javax.servlet.ServletSecurityElement;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-
 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectorInstanceContext;
 import org.apache.geronimo.connector.outbound.connectiontracking.SharedConnectorInstanceContext;
 import org.apache.geronimo.osgi.web.WebApplicationConstants;
@@ -210,6 +208,7 @@ public class GeronimoWebAppContext exten
         boolean txActive = integrationContext.isTxActive();
         SharedConnectorInstanceContext newContext = integrationContext.newConnectorInstanceContext(baseRequest);
         ConnectorInstanceContext connectorContext = integrationContext.setConnectorInstance(baseRequest, newContext);
+        Map<String, Object> owbContext = integrationContext.contextEntered();
         try {
             try {
                 super.doScope(target, baseRequest, request, response);
@@ -217,6 +216,7 @@ public class GeronimoWebAppContext exten
                 integrationContext.restoreConnectorContext(connectorContext, baseRequest, newContext);
             }
         } finally {
+            integrationContext.contextExited(owbContext);
             integrationContext.restoreContext(context);
             integrationContext.completeTx(txActive, baseRequest);
         }

Modified: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/IntegrationContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/IntegrationContext.java?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/IntegrationContext.java (original)
+++ geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/IntegrationContext.java Thu Oct 21 22:09:03 2010
@@ -21,24 +21,24 @@
 package org.apache.geronimo.jetty8.handler;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
 import javax.naming.Context;
+import javax.resource.ResourceException;
+import javax.servlet.DispatcherType;
 import javax.servlet.ServletContainerInitializer;
-import javax.transaction.UserTransaction;
+import javax.servlet.ServletException;
 import javax.transaction.Status;
 import javax.transaction.SystemException;
-import javax.servlet.ServletException;
-import javax.servlet.DispatcherType;
-import javax.resource.ResourceException;
-
-import org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator;
-import org.apache.geronimo.connector.outbound.connectiontracking.SharedConnectorInstanceContext;
+import javax.transaction.UserTransaction;
 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectorInstanceContext;
+import org.apache.geronimo.connector.outbound.connectiontracking.SharedConnectorInstanceContext;
+import org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator;
 import org.apache.geronimo.j2ee.annotation.Holder;
 import org.apache.geronimo.naming.java.RootContext;
-import org.castor.cache.distributed.EHCache;
+import org.apache.geronimo.openwebbeans.GeronimoSingletonService;
 import org.eclipse.jetty.server.Request;
 import org.osgi.framework.Bundle;
 
@@ -55,6 +55,7 @@ public class IntegrationContext {
     private final Bundle bundle;
     private final Holder holder;
     private final Map<ServletContainerInitializer, Set<Class<?>>> servletContainerInitializerMap;
+    private final Map<String, Object> owbContext = new HashMap<String, Object>();
 
     public IntegrationContext(Context componentContext, Set<String> unshareableResources, Set<String> applicationManagedSecurityResources, TrackedConnectionAssociator trackedConnectionAssociator, UserTransaction userTransaction, Bundle bundle, Holder holder, Map<ServletContainerInitializer, Set<Class<?>>> servletContainerInitializerMap) {
         this.componentContext = componentContext;
@@ -173,4 +174,17 @@ public class IntegrationContext {
     public Map<ServletContainerInitializer, Set<Class<?>>> getServletContainerInitializerMap() {
         return servletContainerInitializerMap;
     }
+
+
+    public Map<String, Object> contextEntered() {
+        return GeronimoSingletonService.contextEntered(owbContext);
+    }
+
+    public void contextExited(Map<String, Object> oldOWBContext) {
+        GeronimoSingletonService.contextExited(oldOWBContext);
+    }
+
+    public Map<String, Object> getOWBContext() {
+        return owbContext;
+    }
 }

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/pom.xml?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/pom.xml (original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/pom.xml Thu Oct 21 22:09:03 2010
@@ -155,6 +155,12 @@
             <artifactId>geronimo-persistence-jpa20</artifactId>
             <version>${project.version}</version>
         </dependency>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.modules</groupId>
+            <artifactId>geronimo-openwebbeans</artifactId>
+            <version>${project.version}</version>
+        </dependency>
 
         <dependency>
             <groupId>org.apache.geronimo.framework</groupId>

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbModuleImpl.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbModuleImpl.java?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbModuleImpl.java (original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbModuleImpl.java Thu Oct 21 22:09:03 2010
@@ -72,7 +72,6 @@ public class EjbModuleImpl implements EJ
                          @ParamAttribute(name = "deploymentDescriptor") String deploymentDescriptor,
                          @ParamReference(name = "EJBCollection") Collection<? extends EjbDeployment> ejbs,
                          @ParamSpecial(type = SpecialAttributeType.classLoader) ClassLoader classLoader,
-                         @ParamSpecial(type = SpecialAttributeType.kernel) Kernel kernel,
                          @ParamReference(name = "OpenEjbSystem") OpenEjbSystem openEjbSystem,
                          @ParamAttribute(name = "ejbInfo") GeronimoEjbInfo ejbInfo) throws NamingException {
         this.objectName = objectName;

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java (original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java Thu Oct 21 22:09:03 2010
@@ -62,11 +62,14 @@ import org.apache.openejb.assembler.clas
 import org.apache.openejb.assembler.classic.SecurityServiceInfo;
 import org.apache.openejb.assembler.classic.TransactionServiceInfo;
 import org.apache.openejb.assembler.dynamic.PassthroughFactory;
+import org.apache.openejb.cdi.OWBContextThreadListener;
+import org.apache.openejb.cdi.ThreadSingletonService;
 import org.apache.openejb.config.AppModule;
 import org.apache.openejb.config.ClientModule;
 import org.apache.openejb.config.ConfigurationFactory;
 import org.apache.openejb.config.EjbModule;
 import org.apache.openejb.core.ServerFederation;
+import org.apache.openejb.core.ThreadContext;
 import org.apache.openejb.core.mdb.InboundRecovery;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.resource.XAResourceWrapper;
@@ -163,6 +166,10 @@ public class OpenEjbSystemGBean implemen
         // add our thread context listener
         GeronimoThreadContextListener.init();
 
+        SystemInstance.get().setComponent(ThreadSingletonService.class, new ThreadSingletonServiceAdapter());
+        //probably should be in openejb...
+        ThreadContext.addThreadContextListener(new OWBContextThreadListener());
+
         // process all resource adapters
         processResourceAdapterWrappers(resourceAdapters);
         processPersistenceUnitGBeans(persistenceUnitGBeans);

Added: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ThreadSingletonServiceAdapter.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ThreadSingletonServiceAdapter.java?rev=1026156&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ThreadSingletonServiceAdapter.java (added)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ThreadSingletonServiceAdapter.java Thu Oct 21 22:09:03 2010
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.geronimo.openejb;
+
+import java.util.Map;
+
+import org.apache.geronimo.openwebbeans.GeronimoSingletonService;
+import org.apache.geronimo.openwebbeans.OpenWebBeansWebInitializer;
+import org.apache.geronimo.openwebbeans.OsgiMetaDataScannerService;
+import org.apache.openejb.cdi.CdiAppContextsService;
+import org.apache.openejb.cdi.CdiResourceInjectionService;
+import org.apache.openejb.cdi.ThreadSingletonService;
+import org.apache.webbeans.config.OpenWebBeansConfiguration;
+import org.apache.webbeans.lifecycle.StandaloneLifeCycle;
+import org.apache.webbeans.spi.ResourceInjectionService;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ThreadSingletonServiceAdapter extends GeronimoSingletonService implements ThreadSingletonService {
+    public ThreadSingletonServiceAdapter() {
+        super();
+    }
+
+    @Override
+    public void initialize(org.apache.openejb.cdi.OWBContext owbContext) {
+        Object old = contextEntered(owbContext);
+        try {
+            setConfiguration(OpenWebBeansConfiguration.getInstance());
+        } finally {
+            contextExited(old);
+        }
+    }
+
+    private void setConfiguration(OpenWebBeansConfiguration configuration) {
+        configuration.setProperty(OpenWebBeansConfiguration.USE_EJB_DISCOVERY, "true");
+
+        configuration.setProperty(OpenWebBeansConfiguration.CONTAINER_LIFECYCLE, StandaloneLifeCycle.class.getName());
+        configuration.setProperty(OpenWebBeansConfiguration.JNDI_SERVICE, OpenWebBeansWebInitializer.NoopJndiService.class.getName());
+        configuration.setProperty(OpenWebBeansConfiguration.SCANNER_SERVICE, OsgiMetaDataScannerService.class.getName());
+        configuration.setProperty(OpenWebBeansConfiguration.CONTEXTS_SERVICE, CdiAppContextsService.class.getName());
+        configuration.setProperty(ResourceInjectionService.class.getName(), CdiResourceInjectionService.class.getName());
+//        configuration.setProperty(ELAdaptor.class.getName(), EL22Adaptor.class.getName());
+    }
+
+    @Override
+    public Object contextEntered(org.apache.openejb.cdi.OWBContext owbContext) {
+        return GeronimoSingletonService.contextEntered(owbContext.getSingletons());
+    }
+
+    @Override
+    public void contextExited(Object oldContext) {
+        if (oldContext != null && !(oldContext instanceof Map)) throw new IllegalArgumentException("Expecting a Map<String, Object> not " + oldContext.getClass().getName());
+        GeronimoSingletonService.contextExited((Map<String, Object>)oldContext);
+    }
+}

Propchange: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ThreadSingletonServiceAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ThreadSingletonServiceAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ThreadSingletonServiceAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansModuleBuilderExtension.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansModuleBuilderExtension.java?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansModuleBuilderExtension.java (original)
+++ geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansModuleBuilderExtension.java Thu Oct 21 22:09:03 2010
@@ -40,14 +40,12 @@ import org.apache.geronimo.j2ee.deployme
 import org.apache.geronimo.j2ee.deployment.NamingBuilder;
 import org.apache.geronimo.j2ee.deployment.WebModule;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
-import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.Naming;
 import org.apache.geronimo.kernel.config.ConfigurationStore;
 import org.apache.geronimo.kernel.repository.Environment;
-import org.apache.geronimo.openwebbeans.OpenWebBeansGBean;
+import org.apache.geronimo.openwebbeans.WebBeansConfigurationListener;
 import org.apache.geronimo.web.info.WebAppInfo;
 import org.apache.openejb.jee.WebApp;
-import org.apache.webbeans.servlet.WebBeansConfigurationListener;
 import org.apache.xbean.finder.ClassFinder;
 import org.apache.xmlbeans.XmlObject;
 import org.osgi.framework.Bundle;
@@ -65,6 +63,7 @@ public class OpenWebBeansModuleBuilderEx
     private final Environment defaultEnvironment;
     private final NamingBuilder namingBuilders;
 
+    //this is the geronimo copy
     private static final String CONTEXT_LISTENER_NAME = WebBeansConfigurationListener.class.getName();
 
     public OpenWebBeansModuleBuilderExtension(
@@ -124,7 +123,7 @@ public class OpenWebBeansModuleBuilderEx
         // add myfaces listener
         WebAppInfo webAppInfo = (WebAppInfo) webAppData.getAttribute("webAppInfo");
         if (webAppInfo != null && !webAppInfo.listeners.contains(CONTEXT_LISTENER_NAME)) {
-            webAppInfo.listeners.add(CONTEXT_LISTENER_NAME);
+            webAppInfo.listeners.add(0, CONTEXT_LISTENER_NAME);
         }
         AbstractName moduleName = moduleContext.getModuleName();
         Map<EARContext.Key, Object> buildingContext = new HashMap<EARContext.Key, Object>();
@@ -142,16 +141,16 @@ public class OpenWebBeansModuleBuilderEx
 
         namingBuilders.buildNaming(webApp, jettyWebApp, webModule, buildingContext);    
         
-        AbstractName webBeansGBeanName = moduleContext.getNaming().createChildName(moduleName, "webbeans-lifecycle", "webbeans");
-        GBeanData providerData = new GBeanData(webBeansGBeanName, OpenWebBeansGBean.class);
-        try {
-            moduleContext.addGBean(providerData);
-        } catch (GBeanAlreadyExistsException e) {
-            throw new DeploymentException("Duplicate webbean config gbean in web module", e);
-        }
+//        AbstractName webBeansGBeanName = moduleContext.getNaming().createChildName(moduleName, "webbeans-lifecycle", "webbeans");
+//        GBeanData providerData = new GBeanData(webBeansGBeanName, OpenWebBeansGBean.class);
+//        try {
+//            moduleContext.addGBean(providerData);
+//        } catch (GBeanAlreadyExistsException e) {
+//            throw new DeploymentException("Duplicate webbean config gbean in web module", e);
+//        }
 
         //make the web app start second after the webbeans machinery
-        webAppData.addDependency(webBeansGBeanName);
+//        webAppData.addDependency(webBeansGBeanName);
     }
 
     private boolean hasBeansXml(Bundle bundle) {

Added: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/GeronimoSingletonService.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/GeronimoSingletonService.java?rev=1026156&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/GeronimoSingletonService.java (added)
+++ geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/GeronimoSingletonService.java Thu Oct 21 22:09:03 2010
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.geronimo.openwebbeans;
+
+import java.util.Map;
+
+import org.apache.webbeans.config.WebBeansFinder;
+import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.spi.SingletonService;
+import org.osgi.framework.Bundle;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GeronimoSingletonService implements SingletonService {
+
+    private static final ThreadLocal<Map<String, Object>> contexts = new ThreadLocal<Map<String, Object>>();
+    private static Bundle bundle;
+
+    public static void init(Bundle owbBundle) {
+        bundle = owbBundle;
+        WebBeansFinder.setSingletonService(new GeronimoSingletonService());
+    }
+
+    public GeronimoSingletonService() {
+    }
+
+    public static Map<String, Object> contextEntered(Map<String, Object> newContext) {
+        Map<String, Object> oldContext = contexts.get();
+        contexts.set(newContext);
+        return oldContext;
+    }
+
+    public static void contextExited(Map<String, Object> oldContext) {
+        contexts.set(oldContext);
+    }
+
+    @Override
+    public Object get(Object key, String singletonClassName) {
+        Map<String, Object> context = getContext();
+        Object service = context.get(singletonClassName);
+        if (service == null) {
+            try {
+                Class clazz = bundle.loadClass(singletonClassName);
+                service = clazz.newInstance();
+            } catch (ClassNotFoundException e) {
+                throw new WebBeansException("Could not locate requested class " + singletonClassName + " in bundle " + bundle, e);
+            } catch (InstantiationException e) {
+                throw new WebBeansException("Could not create instance of class " + singletonClassName, e);
+            } catch (IllegalAccessException e) {
+                throw new WebBeansException("Could not create instance of class " + singletonClassName, e);
+            } catch (NoClassDefFoundError e) {
+                throw new WebBeansException("Could not locate requested class " + singletonClassName + " in bundle " + bundle, e);
+            }
+            context.put(singletonClassName, service);
+        }
+        return service;
+    }
+
+    private Map<String, Object> getContext() {
+        Map<String, Object> context = contexts.get();
+        if (context == null) {
+            throw new IllegalStateException("On a thread without an initialized context");
+        }
+        return context;
+    }
+
+    @Override
+    public void clear(Object key) {
+        getContext().clear();
+    }
+
+    @Override
+    public boolean isExist(Object key, String singletonClassName) {
+        return getContext().containsKey(singletonClassName);
+    }
+
+    @Override
+    public Object getExist(Object key, String singletonClassName) {
+        return getContext().get(singletonClassName);
+    }
+
+    @Override
+    public Object getKey(Object singleton) {
+        return null;
+    }
+}

Propchange: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/GeronimoSingletonService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/GeronimoSingletonService.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/GeronimoSingletonService.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OpenWebBeansWebInitializer.java (from r1022717, geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OpenWebBeansGBean.java)
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OpenWebBeansWebInitializer.java?p2=geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OpenWebBeansWebInitializer.java&p1=geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OpenWebBeansGBean.java&r1=1022717&r2=1026156&rev=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OpenWebBeansGBean.java (original)
+++ geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OpenWebBeansWebInitializer.java Thu Oct 21 22:09:03 2010
@@ -19,26 +19,49 @@
 
 package org.apache.geronimo.openwebbeans;
 
-import org.apache.geronimo.gbean.GBeanLifecycle;
-import org.apache.geronimo.gbean.annotation.GBean;
-import org.apache.geronimo.gbean.annotation.ParamSpecial;
-import org.apache.geronimo.gbean.annotation.SpecialAttributeType;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
 import org.apache.webbeans.config.OpenWebBeansConfiguration;
+import org.apache.webbeans.el.el22.EL22Adaptor;
+import org.apache.webbeans.lifecycle.LifecycleFactory;
+import org.apache.webbeans.spi.ContainerLifecycle;
 import org.apache.webbeans.spi.JNDIService;
+import org.apache.webbeans.spi.adaptor.ELAdaptor;
+import org.apache.webbeans.util.WebBeansUtil;
 import org.apache.webbeans.web.context.WebContextsService;
 import org.apache.webbeans.web.lifecycle.WebContainerLifecycle;
-import org.osgi.framework.BundleContext;
 
 /**
  *  
  * @version $Rev: 698441 $ $Date: 2008-09-24 00:10:08 -0700 (Wed, 24 Sep 2008) $
  */
-@GBean
-public class OpenWebBeansGBean implements GBeanLifecycle {
+public class OpenWebBeansWebInitializer {
     
-    public OpenWebBeansGBean(@ParamSpecial(type = SpecialAttributeType.bundleContext) final BundleContext bundleContext,
-                             @ParamSpecial(type = SpecialAttributeType.classLoader) ClassLoader classLoader) {
-        setConfiguration(OpenWebBeansConfiguration.getInstance());
+    public OpenWebBeansWebInitializer(Map<String, Object> owbContext, ServletContext servletContext) {
+        GeronimoSingletonService.contextEntered(owbContext);
+
+        try {
+            setConfiguration(OpenWebBeansConfiguration.getInstance());
+            //from OWB's WebBeansConfigurationListener
+            if (servletContext != null) {
+                ContainerLifecycle lifeCycle = LifecycleFactory.getInstance().getLifecycle();
+
+                try
+                {
+                        lifeCycle.startApplication(new ServletContextEvent(servletContext));
+                        servletContext.setAttribute(OpenWebBeansConfiguration.PROPERTY_OWB_APPLICATION, "true");
+                }
+                catch (Exception e)
+                {
+    //             logger.error(OWBLogConst.ERROR_0018, event.getServletContext().getContextPath());
+                     WebBeansUtil.throwRuntimeExceptions(e);
+                }
+            }
+        } finally {
+            GeronimoSingletonService.contextExited(null);
+        }
     }
 
     private void setConfiguration(OpenWebBeansConfiguration configuration) {
@@ -48,20 +71,9 @@ public class OpenWebBeansGBean implement
         configuration.setProperty(OpenWebBeansConfiguration.JNDI_SERVICE, NoopJndiService.class.getName());
         configuration.setProperty(OpenWebBeansConfiguration.SCANNER_SERVICE, OsgiMetaDataScannerService.class.getName());
         configuration.setProperty(OpenWebBeansConfiguration.CONTEXTS_SERVICE, WebContextsService.class.getName());
+        configuration.setProperty(ELAdaptor.class.getName(), EL22Adaptor.class.getName());
     }
 
-    public void doStart() {
-        System.out.println("Start OpenWebBeansGBean");
-    }
-
-    public void doStop() {
-        System.out.println("Stop OpenWebBeansGBean");
-    }
-
-    public void doFail() {
-        doStop();
-    }
-    
     public static class NoopJndiService implements JNDIService {
 
         public void bind(String name, Object object) {

Modified: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OsgiMetaDataScannerService.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OsgiMetaDataScannerService.java?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OsgiMetaDataScannerService.java (original)
+++ geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OsgiMetaDataScannerService.java Thu Oct 21 22:09:03 2010
@@ -81,24 +81,26 @@ public class OsgiMetaDataScannerService 
         Bundle mainBundle = BundleUtils.getContextBundle(true);
 
 
-        ServiceReference reference = mainBundle.getBundleContext().getServiceReference(PackageAdmin.class.getName());
-        try
-        {
-            PackageAdmin packageAdmin = (PackageAdmin) mainBundle.getBundleContext().getService(reference);
+        if (mainBundle != null) {
+            ServiceReference reference = mainBundle.getBundleContext().getServiceReference(PackageAdmin.class.getName());
+            try
+            {
+                PackageAdmin packageAdmin = (PackageAdmin) mainBundle.getBundleContext().getService(reference);
 
-            // search for all META-INF/beans.xml files
-            findBeansXml(mainBundle, packageAdmin);
+                // search for all META-INF/beans.xml files
+                findBeansXml(mainBundle, packageAdmin);
 
-            // search for all classes
-            findBeanClasses(mainBundle, packageAdmin);
-        }
-        catch(Exception e)
-        {
-            throw new WebBeansDeploymentException("problem while scanning OSGi bundle", e);
-        }
-        finally
-        {
-            mainBundle.getBundleContext().ungetService(reference);
+                // search for all classes
+                findBeanClasses(mainBundle, packageAdmin);
+            }
+            catch(Exception e)
+            {
+                throw new WebBeansDeploymentException("problem while scanning OSGi bundle", e);
+            }
+            finally
+            {
+                mainBundle.getBundleContext().ungetService(reference);
+            }
         }
 
     }

Added: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/SingletonServiceInitializerGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/SingletonServiceInitializerGBean.java?rev=1026156&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/SingletonServiceInitializerGBean.java (added)
+++ geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/SingletonServiceInitializerGBean.java Thu Oct 21 22:09:03 2010
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.geronimo.openwebbeans;
+
+import org.apache.geronimo.gbean.annotation.GBean;
+import org.apache.geronimo.gbean.annotation.ParamSpecial;
+import org.apache.geronimo.gbean.annotation.SpecialAttributeType;
+import org.osgi.framework.Bundle;
+
+/**
+ * @version $Rev$ $Date$
+ */
+
+@GBean
+public class SingletonServiceInitializerGBean {
+
+    public SingletonServiceInitializerGBean(@ParamSpecial(type = SpecialAttributeType.bundle) Bundle bundle) {
+        GeronimoSingletonService.init(bundle);
+    }
+}

Propchange: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/SingletonServiceInitializerGBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/SingletonServiceInitializerGBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/SingletonServiceInitializerGBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/WebBeansConfigurationListener.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/WebBeansConfigurationListener.java?rev=1026156&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/WebBeansConfigurationListener.java (added)
+++ geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/WebBeansConfigurationListener.java Thu Oct 21 22:09:03 2010
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.geronimo.openwebbeans;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.ServletRequestListener;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionActivationListener;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+import org.apache.webbeans.component.InjectionPointBean;
+import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.config.OpenWebBeansConfiguration;
+import org.apache.webbeans.conversation.ConversationManager;
+import org.apache.webbeans.corespi.ServiceLoader;
+import org.apache.webbeans.el.ELContextStore;
+import org.apache.webbeans.lifecycle.LifecycleFactory;
+import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.spi.ContainerLifecycle;
+import org.apache.webbeans.spi.FailOverService;
+import org.apache.webbeans.util.WebBeansUtil;
+import org.apache.webbeans.web.context.WebContextsService;
+
+/**
+ * @version $Rev$ $Date$
+ */
+/**
+ * Initializing the beans container for using in an web application
+ * environment.
+ *
+ * @version $Rev$ $Date$
+ */
+public class WebBeansConfigurationListener implements ServletContextListener, ServletRequestListener, HttpSessionListener, HttpSessionActivationListener
+{
+    /**Logger instance*/
+    private static final WebBeansLogger logger = WebBeansLogger.getLogger(WebBeansConfigurationListener.class);
+
+    protected FailOverService failoverService = null;
+
+    /**Manages the container lifecycle*/
+    protected ContainerLifecycle lifeCycle = null;
+    /**
+     * Default constructor
+     */
+    public WebBeansConfigurationListener()
+    {
+        failoverService = ServiceLoader.getService(FailOverService.class);
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void contextInitialized(ServletContextEvent event)
+    {
+        this.lifeCycle = LifecycleFactory.getInstance().getLifecycle();
+
+//        try
+//        {
+//                this.lifeCycle.startApplication(event);
+//                event.getServletContext().setAttribute(OpenWebBeansConfiguration.PROPERTY_OWB_APPLICATION, "true");
+//        }
+//        catch (Exception e)
+//        {
+//             logger.error(OWBLogConst.ERROR_0018, event.getServletContext().getContextPath());
+//             WebBeansUtil.throwRuntimeExceptions(e);
+//        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void contextDestroyed(ServletContextEvent event)
+    {
+        this.lifeCycle.stopApplication(event);
+        this.lifeCycle = null;
+        event.getServletContext().setAttribute(OpenWebBeansConfiguration.PROPERTY_OWB_APPLICATION, "false");
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void requestDestroyed(ServletRequestEvent event)
+    {
+        if (logger.wblWillLogDebug())
+        {
+            logger.debug("Destroying a request : [{0}]", event.getServletRequest().getRemoteAddr());
+        }
+
+        if (failoverService != null &&
+                failoverService.isSupportFailOver())
+        {
+            Object request = event.getServletRequest();
+            if(request instanceof HttpServletRequest)
+            {
+                HttpServletRequest httpRequest = (HttpServletRequest)request;
+                HttpSession session = httpRequest.getSession(false);
+                if (session != null)
+                {
+                    failoverService.sessionIsIdle(session);
+                }
+            }
+        }
+
+        // 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();
+    }
+
+    /**
+     * Ensures that all ThreadLocals, which could have been set in this
+     * request's Thread, are removed in order to prevent memory leaks.
+     */
+    private void cleanupRequestThreadLocals()
+    {
+        // TODO maybe there are more to cleanup
+
+        InjectionPointBean.removeThreadLocal();
+        WebContextsService.removeThreadLocals();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void requestInitialized(ServletRequestEvent event)
+    {
+        try
+        {
+            if (logger.wblWillLogDebug())
+            {
+                logger.debug("Starting a new request : [{0}]", 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.error(OWBLogConst.ERROR_0019, event.getServletRequest());
+            WebBeansUtil.throwRuntimeExceptions(e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void sessionCreated(HttpSessionEvent event)
+    {
+        try
+        {
+            if (logger.wblWillLogDebug())
+            {
+                logger.debug("Starting a session with session id : [{0}]", event.getSession().getId());
+            }
+            this.lifeCycle.getContextService().startContext(SessionScoped.class, event.getSession());
+        }
+        catch (Exception e)
+        {
+            logger.error(OWBLogConst.ERROR_0020, event.getSession());
+            WebBeansUtil.throwRuntimeExceptions(e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void sessionDestroyed(HttpSessionEvent event)
+    {
+        if (logger.wblWillLogDebug())
+        {
+            logger.debug("Destroying a session with session id : [{0}]", event.getSession().getId());
+        }
+        this.lifeCycle.getContextService().endContext(SessionScoped.class, event.getSession());
+
+        ConversationManager conversationManager = ConversationManager.getInstance();
+        conversationManager.destroyConversationContextWithSessionId(event.getSession().getId());
+    }
+
+    @Override
+    public void sessionWillPassivate(HttpSessionEvent event)
+    {
+        if (failoverService != null &&
+            failoverService.isSupportPassivation())
+        {
+            HttpSession session = event.getSession();
+            failoverService.sessionWillPassivate(session);
+        }
+
+    }
+
+    @Override
+    public void sessionDidActivate(HttpSessionEvent event)
+    {
+        if (failoverService.isSupportFailOver() ||
+            failoverService.isSupportPassivation())
+        {
+            HttpSession session = event.getSession();
+            failoverService.restoreBeans(session);
+        }
+    }
+}
+

Propchange: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/WebBeansConfigurationListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/WebBeansConfigurationListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/WebBeansConfigurationListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/plugins/openwebbeans/openwebbeans/src/main/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openwebbeans/openwebbeans/src/main/plan/plan.xml?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openwebbeans/openwebbeans/src/main/plan/plan.xml (original)
+++ geronimo/server/trunk/plugins/openwebbeans/openwebbeans/src/main/plan/plan.xml Thu Oct 21 22:09:03 2010
@@ -20,4 +20,6 @@
 
 <module xmlns="http://geronimo.apache.org/xml/ns/deployment-${geronimoSchemaVersion}">
 
+    <gbean name="OWBSingletonServiceInitializer" class="org.apache.geronimo.openwebbeans.SingletonServiceInitializerGBean"/>
+
 </module>

Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml (original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml Thu Oct 21 22:09:03 2010
@@ -59,6 +59,12 @@
             <version>${project.version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.geronimo.modules</groupId>
+            <artifactId>geronimo-openwebbeans</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
         <!-- g-security comes from this -->
         <dependency>
             <groupId>org.apache.geronimo.framework</groupId>

Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java (original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java Thu Oct 21 22:09:03 2010
@@ -48,7 +48,6 @@ import javax.servlet.ServletSecurityElem
 import org.apache.catalina.Container;
 import org.apache.catalina.ContainerListener;
 import org.apache.catalina.Engine;
-import org.apache.catalina.Globals;
 import org.apache.catalina.InstanceListener;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleListener;
@@ -76,6 +75,8 @@ import org.apache.geronimo.security.jacc
 import org.apache.geronimo.tomcat.interceptor.BeforeAfter;
 import org.apache.geronimo.tomcat.interceptor.ComponentContextBeforeAfter;
 import org.apache.geronimo.tomcat.interceptor.InstanceContextBeforeAfter;
+import org.apache.geronimo.tomcat.interceptor.OWBBeforeAfter;
+import org.apache.geronimo.tomcat.interceptor.PolicyContextBeforeAfter;
 import org.apache.geronimo.tomcat.interceptor.UserTransactionBeforeAfter;
 import org.apache.geronimo.tomcat.listener.DispatchListener;
 import org.apache.geronimo.tomcat.listener.RunAsInstanceListener;
@@ -144,6 +145,7 @@ public class GeronimoStandardContext ext
         // Create ReadOnlyContext
         javax.naming.Context enc = ctx.getJndiContext();
         setInstanceManager(ctx.getInstanceManager());
+        ServletContext servletContext = getServletContext();
 
         //try to make sure this mbean properties match those of the TomcatWebAppContext
         if (ctx instanceof TomcatWebAppContext) {
@@ -154,13 +156,13 @@ public class GeronimoStandardContext ext
             setJ2EEServer(tomcatWebAppContext.getJ2EEServer());
             //install jasper injection support if required
             if (tomcatWebAppContext.getRuntimeCustomizer() != null) {
-                Map<String, Object> servletContext = new HashMap<String, Object>();
+                Map<String, Object> attributes = new HashMap<String, Object>();
                 Map<Class, Object> customizerContext = new HashMap<Class, Object>();
-                customizerContext.put(Map.class, servletContext);
+                customizerContext.put(Map.class, attributes);
                 customizerContext.put(javax.naming.Context.class, enc);
                 tomcatWebAppContext.getRuntimeCustomizer().customize(customizerContext);
-                for (Map.Entry<String, Object> entry: servletContext.entrySet()) {
-                    getServletContext().setAttribute(entry.getKey(), entry.getValue());
+                for (Map.Entry<String, Object> entry: attributes.entrySet()) {
+                    servletContext.setAttribute(entry.getKey(), entry.getValue());
                 }
             }
             applicationPolicyConfigurationManager = tomcatWebAppContext.getApplicationPolicyConfigurationManager();
@@ -171,7 +173,6 @@ public class GeronimoStandardContext ext
             boolean metaComplete = (Boolean) tomcatWebAppContext.getDeploymentAttribute(WebAttributeName.META_COMPLETE.name());
             webSecurityConstraintStore = new WebSecurityConstraintStore(tomcatWebAppContext.getWebAppInfo(), bundle, schemaVersion >= 2.5f && !metaComplete, getInternalServletContext());
 
-            ServletContext servletContext = getServletContext();
             servletContext.setAttribute(InstanceManager.class.getName(), ctx.getInstanceManager());
 
             //Set some attributes passed from the deployment process
@@ -225,6 +226,8 @@ public class GeronimoStandardContext ext
             interceptor = new ComponentContextBeforeAfter(interceptor, index++, enc);
         }
 
+        interceptor = new OWBBeforeAfter(interceptor, index++, servletContext);
+        
         //Set a PolicyContext BeforeAfter
         SecurityHolder securityHolder = ctx.getSecurityHolder();
         if (securityHolder != null) {
@@ -245,7 +248,7 @@ public class GeronimoStandardContext ext
                     defaultSubject = ContextManager.EMPTY;
                 }
 
-//                interceptor = new PolicyContextBeforeAfter(interceptor, index++, index++, index++, policyContextId, defaultSubject);
+                interceptor = new PolicyContextBeforeAfter(interceptor, index++, index++, index++, policyContextId, defaultSubject);
 
             }
         }

Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java?rev=1026156&r1=1026155&r2=1026156&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java (original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java Thu Oct 21 22:09:03 2010
@@ -37,13 +37,13 @@ public class ComponentContextBeforeAfter
         context[index] = RootContext.getComponentContext();
         RootContext.setComponentContext(componentContext);
         if (next != null) {
-            next.before(context, httpRequest, httpResponse, 0);
+            next.before(context, httpRequest, httpResponse, dispatch);
         }
     }
 
     public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse, int dispatch) {
         if (next != null) {
-            next.after(context, httpRequest, httpResponse, 0);
+            next.after(context, httpRequest, httpResponse, dispatch);
         }
         RootContext.setComponentContext((Context) context[index]);
     }

Added: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/interceptor/OWBBeforeAfter.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/interceptor/OWBBeforeAfter.java?rev=1026156&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/interceptor/OWBBeforeAfter.java (added)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/interceptor/OWBBeforeAfter.java Thu Oct 21 22:09:03 2010
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.geronimo.tomcat.interceptor;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import org.apache.geronimo.openwebbeans.GeronimoSingletonService;
+import org.apache.geronimo.openwebbeans.OpenWebBeansWebInitializer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class OWBBeforeAfter implements BeforeAfter {
+
+    private final BeforeAfter next;
+    private final int index;
+    private final Map<String, Object> owbContext ;
+
+    public OWBBeforeAfter(BeforeAfter next, int index, ServletContext servletContext) {
+        this.next = next;
+        this.index = index;
+        this.owbContext = new HashMap<String, Object>();
+        new OpenWebBeansWebInitializer(owbContext, servletContext);
+    }
+
+    @Override
+    public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse, int dispatch) {
+        context[index] = GeronimoSingletonService.contextEntered(owbContext);
+        if (next != null) {
+            next.before(context, httpRequest, httpResponse, dispatch);
+        }
+    }
+
+    @Override
+    public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse, int dispatch) {
+        if (next != null) {
+            next.after(context, httpRequest, httpResponse, dispatch);
+        }
+        GeronimoSingletonService.contextExited((Map<String, Object>) context[index]);
+    }
+}

Propchange: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/interceptor/OWBBeforeAfter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/interceptor/OWBBeforeAfter.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/interceptor/OWBBeforeAfter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message