[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openejb-cvs
Subject:    [1/2] tomee git commit: replacing default conversation service by our own just using servlet api
From:       rmannibucau () apache ! org
Date:       2014-12-28 21:29:31
Message-ID: 6402c10853864e33ac1837197bb51af0 () git ! apache ! org
[Download RAW message or body]

Repository: tomee
Updated Branches:
  refs/heads/develop 9f7bfd4b4 -> eca9915ca


replacing default conversation service by our own just using servlet api


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

Branch: refs/heads/develop
Commit: 3a94878be8979b25f4315d27cadbe497c5b93198
Parents: 9f7bfd4
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Sun Dec 28 22:10:15 2014 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Sun Dec 28 22:10:15 2014 +0100

----------------------------------------------------------------------
 .../openejb/assembler/classic/Assembler.java    | 15 ++++-----
 .../openejb/cdi/CdiAppContextsService.java      | 22 ++++++++++--
 .../openejb/cdi/OpenEJBTransactionService.java  | 15 +++------
 .../openejb/cdi/ThreadSingletonServiceImpl.java | 35 ++++++++------------
 tck/cdi-embedded/src/test/resources/failing.xml |  2 +-
 5 files changed, 45 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/3a94878b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
                
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java \
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
 index dcfef92..b46ac25 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
                
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
 @@ -1424,7 +1424,6 @@ public class Assembler extends AssemblerTool implements \
org.apache.openejb.spi.A  
             services.put(JNDIService.class, new OpenEJBJndiService());
             services.put(AppContext.class, appContext);
-            services.put(TransactionService.class, new OpenEJBTransactionService());
             services.put(ScannerService.class, new CdiScanner());
             services.put(BeanArchiveService.class, new OpenEJBBeanInfoService());
             services.put(ELAdaptor.class, new CustomELAdapter(appContext));
@@ -1432,18 +1431,16 @@ public class Assembler extends AssemblerTool implements \
org.apache.openejb.spi.A  
             final Properties properties = new Properties();
             properties.setProperty(org.apache.webbeans.spi.SecurityService.class.getName(), \
ManagedSecurityService.class.getName()); +            \
properties.setProperty(ContextsService.class.getName(), \
CdiAppContextsService.class.getName()); +            \
properties.setProperty(ResourceInjectionService.class.getName(), \
CdiResourceInjectionService.class.getName()); +            \
properties.setProperty(TransactionService.class.getName(), \
OpenEJBTransactionService.class.getName());  
             webBeansContext = new WebBeansContext(services, properties);
 
-            webBeansContext.registerService(ContextsService.class, new \
                CdiAppContextsService(webBeansContext, true));
-            webBeansContext.registerService(ResourceInjectionService.class, new \
                CdiResourceInjectionService(webBeansContext));
-
             appContext.setCdiEnabled(false);
-            OpenEJBTransactionService.class.cast(services.get(TransactionService.class)).setWebBeansContext(webBeansContext);
                
-
-        appContext.set(WebBeansContext.class, webBeansContext);
-        appContext.setWebBeansContext(webBeansContext);
-    }
+            appContext.set(WebBeansContext.class, webBeansContext);
+            appContext.setWebBeansContext(webBeansContext);
+        }
     }
 
     private TransactionPolicyFactory createTransactionPolicyFactory(final EjbJarInfo \
ejbJar, final ClassLoader classLoader) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/3a94878b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
                
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java \
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
 index 28bca5d..a83a96c 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
                
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
 @@ -60,7 +60,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Map;
 
-public class CdiAppContextsService extends AbstractContextsService implements \
ContextsService { +public class CdiAppContextsService extends AbstractContextsService \
implements ContextsService, ConversationService {  
     private static final Logger logger = \
Logger.getInstance(LogCategory.OPENEJB.createChild("cdi"), \
CdiAppContextsService.class);  
@@ -87,7 +87,7 @@ public class CdiAppContextsService extends AbstractContextsService \
                implements Co
     private static final ThreadLocal<Collection<Runnable>> endRequestRunnables = new \
ThreadLocal<Collection<Runnable>>() {  @Override
         protected Collection<Runnable> initialValue() {
-            return new ArrayList<Runnable>();
+            return new ArrayList<>();
         }
     };
 
@@ -134,6 +134,16 @@ public class CdiAppContextsService extends \
AbstractContextsService implements Co  endRequestRunnables.get().add(runnable);
     }
 
+    @Override
+    public String getConversationId() {
+        return getHttpParameter("cid");
+    }
+
+    @Override
+    public String getConversationSessionId() {
+        return currentSessionId();
+    }
+
     public String currentSessionId() {
         final ServletRequestContext rc = requestContext.get();
         if (rc != null) {
@@ -650,6 +660,14 @@ public class CdiAppContextsService extends \
AbstractContextsService implements Co  return old;
     }
 
+    public String getHttpParameter(final String name) {
+        final ServletRequestContext req = getRequestContext(false);
+        if (req != null && req.getServletRequest() != null) {
+            return req.getServletRequest().getParameter(name);
+        }
+        return null;
+    }
+
     public static class State {
         private final ServletRequestContext request;
         private final SessionContext session;

http://git-wip-us.apache.org/repos/asf/tomee/blob/3a94878b/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBTransactionService.java
                
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBTransactionService.java \
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBTransactionService.java
 index 63393b7..4a7e719 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBTransactionService.java
                
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBTransactionService.java
 @@ -46,10 +46,11 @@ public class OpenEJBTransactionService implements \
                TransactionService {
     private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_CDI, \
OpenEJBTransactionService.class);  
     private final ContainerSystem containerSystem;
-    private WebBeansContext webBeansContext;
+    private final WebBeansContext webBeansContext;
 
-    public OpenEJBTransactionService() {
-        containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
+    public OpenEJBTransactionService(final WebBeansContext webBeansContext) {
+        this.containerSystem = \
SystemInstance.get().getComponent(ContainerSystem.class); +        \
this.webBeansContext = webBeansContext;  }
 
     @Override
@@ -94,12 +95,4 @@ public class OpenEJBTransactionService implements \
TransactionService {  new EventMetadataImpl(observer.getObservedType(), null, null,
                 qualifiers.toArray(new Annotation[qualifiers.size()]), \
webBeansContext));  }
-
-    public void setWebBeansContext(final WebBeansContext webBeansContext) {
-        this.webBeansContext = webBeansContext;
-    }
-
-    public WebBeansContext getWebBeansContext() {
-        return webBeansContext;
-    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/3a94878b/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java
                
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java \
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java
 index be5d649..ffd72d0 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java
                
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java
 @@ -90,7 +90,7 @@ public class ThreadSingletonServiceImpl implements \
ThreadSingletonService {  //initialize owb context, cf geronimo's OpenWebBeansGBean
         final Properties properties = new Properties();
 
-        final Map<Class<?>, Object> services = new HashMap<Class<?>, Object>();
+        final Map<Class<?>, Object> services = new HashMap<>();
         properties.setProperty(OpenWebBeansConfiguration.APPLICATION_IS_JSP, \
                "true");
         properties.setProperty(OpenWebBeansConfiguration.USE_EJB_DISCOVERY, "true");
         //from CDI builder
@@ -131,10 +131,14 @@ public class ThreadSingletonServiceImpl implements \
ThreadSingletonService {  
         properties.putAll(appContext.getProperties());
 
+        // services needing WBC as constructor param
+        properties.put(ContextsService.class.getName(), \
CdiAppContextsService.class.getName()); +        \
properties.put(ResourceInjectionService.class.getName(), \
CdiResourceInjectionService.class.getName()); +        \
properties.put(TransactionService.class.getName(), \
OpenEJBTransactionService.class.getName()); +
         services.put(BeanArchiveService.class, new OpenEJBBeanInfoService());
         services.put(AppContext.class, appContext);
         services.put(JNDIService.class, new OpenEJBJndiService());
-        services.put(TransactionService.class, new OpenEJBTransactionService());
         services.put(ELAdaptor.class, new CustomELAdapter(appContext));
         services.put(ScannerService.class, new CdiScanner());
         services.put(ApplicationBoundaryService.class, new \
DefaultApplicationBoundaryService()); @@ -145,8 +149,6 @@ public class \
ThreadSingletonServiceImpl implements ThreadSingletonService {  \
services.put(LoaderService.class, loaderService);  }
 
-        optional(services, ConversationService.class, \
                "org.apache.webbeans.jsf.DefaultConversationService");
-
         final ClassLoader oldClassLoader = \
Thread.currentThread().getContextClassLoader();  final ClassLoader cl;
         if (oldClassLoader != ThreadSingletonServiceImpl.class.getClassLoader() && \
ThreadSingletonServiceImpl.class.getClassLoader() != oldClassLoader.getParent()) { @@ \
-155,6 +157,7 @@ public class ThreadSingletonServiceImpl implements \
ThreadSingletonService {  cl = oldClassLoader;
         }
         Thread.currentThread().setContextClassLoader(cl);
+
         final WebBeansContext webBeansContext;
         Object old = null;
         try {
@@ -165,16 +168,18 @@ public class ThreadSingletonServiceImpl implements \
                ThreadSingletonService {
                 webBeansContext = new WebappWebBeansContext(services, properties, \
                appContext.getWebBeansContext());
                 startupObject.getWebContext().setWebbeansContext(webBeansContext);
             }
+
+            // we want the same reference as the ContextsService if that's our impl
+            if (webBeansContext.getOpenWebBeansConfiguration().supportsConversation()
 +                && \
"org.apache.webbeans.jsf.DefaultConversationService".equals(webBeansContext.getOpenWebBeansConfiguration().getProperty(ConversationService.class.getName()))) \
{ +                webBeansContext.registerService(ConversationService.class, \
ConversationService.class.cast(webBeansContext.getService(ContextsService.class))); + \
} +
             final BeanManagerImpl beanManagerImpl = \
webBeansContext.getBeanManagerImpl();  beanManagerImpl.addContext(new \
                TransactionContext());
             beanManagerImpl.addAdditionalInterceptorBindings(Transactional.class);
 
             SystemInstance.get().fireEvent(new \
                WebBeansContextCreated(webBeansContext));
-            OpenEJBTransactionService.class.cast(services.get(TransactionService.class)).setWebBeansContext(webBeansContext);
                
-
-            // do it only here to get the webbeanscontext
-            services.put(ContextsService.class, new \
                CdiAppContextsService(webBeansContext, true));
-            services.put(ResourceInjectionService.class, new \
CdiResourceInjectionService(webBeansContext));  
             old = contextEntered(webBeansContext);
             setConfiguration(webBeansContext.getOpenWebBeansConfiguration());
@@ -198,18 +203,6 @@ public class ThreadSingletonServiceImpl implements \
ThreadSingletonService {  return false;
     }
 
-    private <T> void optional(final Map<Class<?>, Object> services, final Class<T> \
                type, final String implementation) {
-        try { // use TCCL since we can use webapp enrichment for services
-            final Class clazz = \
                Thread.currentThread().getContextClassLoader().loadClass(implementation);
                
-            services.put(type, type.cast(clazz.newInstance()));
-            logger.debug(String.format("CDI Service Installed: %s = %s", \
                type.getName(), implementation));
-        } catch (final ClassNotFoundException e) {
-            logger.debug(String.format("CDI Service not installed: %s", \
                type.getName()));
-        } catch (final Exception e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
     //not sure what openejb will need
 
     private void setConfiguration(final OpenWebBeansConfiguration configuration) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/3a94878b/tck/cdi-embedded/src/test/resources/failing.xml
                
----------------------------------------------------------------------
diff --git a/tck/cdi-embedded/src/test/resources/failing.xml \
b/tck/cdi-embedded/src/test/resources/failing.xml index afef25c..aed8972 100644
--- a/tck/cdi-embedded/src/test/resources/failing.xml
+++ b/tck/cdi-embedded/src/test/resources/failing.xml
@@ -26,7 +26,7 @@
     -Dopenejb.deploymentId.format={appId}/{ejbJarId}/{ejbName}
     -->
     <classes>
-      <class name="org.jboss.cdi.tck.tests.context.application.async.ApplicationContextAsyncListenerTest" \
/> +      <class name="org.jboss.cdi.tck.tests.context.conversation.filter.ConversationFilterTest" \
/>  </classes>
   </test>
 </suite>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic