tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: EJB needs to trigger init/destroy events for request scope
Date Wed, 07 Jan 2015 10:59:03 GMT
Repository: tomee
Updated Branches:
  refs/heads/develop 74dd0462b -> a1b67450e


EJB needs to trigger init/destroy events for request scope


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

Branch: refs/heads/develop
Commit: a1b67450ea0e986c6e924a4c7534d1db06dd5669
Parents: 74dd046
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Wed Jan 7 11:53:49 2015 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Wed Jan 7 11:53:49 2015 +0100

----------------------------------------------------------------------
 .../openejb/cdi/CdiAppContextsService.java      | 21 ++++++++++++--------
 .../cdi/RequestScopedThreadContextListener.java |  7 +++----
 tck/cdi-embedded/src/test/resources/failing.xml |  2 +-
 3 files changed, 17 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/a1b67450/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 5e48183..a305e6c 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
@@ -62,6 +62,7 @@ import java.util.Collection;
 import java.util.Map;
 
 public class CdiAppContextsService extends AbstractContextsService implements ContextsService,
ConversationService {
+    public static final Object EJB_REQUEST_EVENT = new Object();
 
     private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB.createChild("cdi"),
CdiAppContextsService.class);
 
@@ -228,7 +229,7 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
     public void endContext(final Class<? extends Annotation> scopeType, final Object
endParameters) {
         if (supportsContext(scopeType)) {
             if (scopeType.equals(RequestScoped.class)) {
-                destroyRequestContext();
+                destroyRequestContext(endParameters);
             } else if (scopeType.equals(SessionScoped.class)) {
                 destroySessionContext((HttpSession) endParameters);
             } else if (scopeType.equals(ApplicationScoped.class)) {
@@ -273,7 +274,7 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
     public void startContext(final Class<? extends Annotation> scopeType, final Object
startParameter) throws ContextException {
         if (supportsContext(scopeType)) {
             if (scopeType.equals(RequestScoped.class)) {
-                initRequestContext((ServletRequestEvent) startParameter);
+                initRequestContext(startParameter);
             } else if (scopeType.equals(SessionScoped.class)) {
                 initSessionContext((HttpSession) startParameter);
             } else if (scopeType.equals(ApplicationScoped.class)) {
@@ -317,13 +318,13 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
 
     }
 
-    private void initRequestContext(final ServletRequestEvent event) {
+    private void initRequestContext(final Object event) {
         final ServletRequestContext rq = new ServletRequestContext();
         rq.setActive(true);
 
         requestContext.set(rq);// set thread local
-        if (event != null) {
-            final HttpServletRequest request = (HttpServletRequest) event.getServletRequest();
+        if (event != null && ServletRequestEvent.class.isInstance(event)) {
+            final HttpServletRequest request = (HttpServletRequest) ServletRequestEvent.class.cast(event).getServletRequest();
             ((ServletRequestContext) rq).setServletRequest(request);
 
             if (request != null) {
@@ -350,6 +351,8 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
                     }
                 }
             }
+        } else if (event == EJB_REQUEST_EVENT) {
+            webBeansContext.getBeanManagerImpl().fireEvent(event, InitializedLiteral.REQUEST);
         }
     }
 
@@ -370,12 +373,12 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
         }
     }
 
-    private void destroyRequestContext() {
+    private void destroyRequestContext(final Object end) {
         // execute request tasks
         endRequest();
 
         //Get context
-        final RequestContext context = getRequestContext(false);
+        final ServletRequestContext context = getRequestContext(false);
 
         //Destroy context
         if (context != null) {
@@ -383,9 +386,11 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
                 cleanupConversation();
             }
 
-            final HttpServletRequest servletRequest = ServletRequestContext.class.cast(context).getServletRequest();
+            final HttpServletRequest servletRequest = context.getServletRequest();
             if (servletRequest != null) {
                 webBeansContext.getBeanManagerImpl().fireEvent(servletRequest, DestroyedLiteral.REQUEST);
+            } else if (end == EJB_REQUEST_EVENT) {
+                webBeansContext.getBeanManagerImpl().fireEvent(end, DestroyedLiteral.REQUEST);
             }
             context.destroy();
         }

http://git-wip-us.apache.org/repos/asf/tomee/blob/a1b67450/container/openejb-core/src/main/java/org/apache/openejb/cdi/RequestScopedThreadContextListener.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/RequestScopedThreadContextListener.java
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/RequestScopedThreadContextListener.java
index e06617d..732ebc8 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/RequestScopedThreadContextListener.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/RequestScopedThreadContextListener.java
@@ -25,13 +25,12 @@ import org.apache.webbeans.spi.ContextsService;
 
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.context.spi.Context;
+import javax.servlet.ServletRequestEvent;
 
 /**
  * @version $Rev$ $Date$
  */
 public class RequestScopedThreadContextListener implements ThreadContextListener {
-
-
     @Override
     public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext)
{
 
@@ -47,7 +46,7 @@ public class RequestScopedThreadContextListener implements ThreadContextListener
         final Context requestContext = contextsService.getCurrentContext(RequestScoped.class);
 
         if (requestContext == null) {
-            contextsService.startContext(RequestScoped.class, null);
+            contextsService.startContext(RequestScoped.class, CdiAppContextsService.EJB_REQUEST_EVENT);
             newContext.set(DestroyContext.class, new DestroyContext(contextsService, newContext));
         }
     }
@@ -64,7 +63,7 @@ public class RequestScopedThreadContextListener implements ThreadContextListener
             return;
         }
 
-        destroyContext.contextsService.endContext(RequestScoped.class, null);
+        destroyContext.contextsService.endContext(RequestScoped.class, CdiAppContextsService.EJB_REQUEST_EVENT);
         CdiAppContextsService.class.cast(destroyContext.contextsService).removeThreadLocals();
     }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/a1b67450/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 ad0858d..bc6142c 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.conversation.ClientConversationContextTest"
/>
+      <class name="org.jboss.cdi.tck.tests.context.request.event.async.RequestScopeEventAsyncTest"
/>
     </classes>
   </test>
 </suite>


Mime
View raw message