You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2022/08/29 09:22:17 UTC

[myfaces] branch main updated: MYFACES-4445

This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/main by this push:
     new 573a56b07 MYFACES-4445
573a56b07 is described below

commit 573a56b07b478598c76b88e35b9040e2fa966a39
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Mon Aug 29 11:22:09 2022 +0200

    MYFACES-4445
---
 .../java/org/apache/myfaces/cdi/util/CDIUtils.java    | 19 +++++++++++++++++++
 .../org/apache/myfaces/push/cdi/PushContextImpl.java  | 11 +++++++----
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/cdi/util/CDIUtils.java b/impl/src/main/java/org/apache/myfaces/cdi/util/CDIUtils.java
index f6d29da27..ad0177bbd 100644
--- a/impl/src/main/java/org/apache/myfaces/cdi/util/CDIUtils.java
+++ b/impl/src/main/java/org/apache/myfaces/cdi/util/CDIUtils.java
@@ -23,6 +23,7 @@ import java.lang.reflect.Type;
 import java.util.Collections;
 import java.util.Set;
 import jakarta.enterprise.context.ContextNotActiveException;
+import jakarta.enterprise.context.RequestScoped;
 import jakarta.enterprise.context.SessionScoped;
 import jakarta.enterprise.context.spi.Context;
 
@@ -153,6 +154,24 @@ public class CDIUtils
         return false;
     }
     
+    public static boolean isRequestScopeActive(BeanManager beanManager)
+    {
+        try 
+        {
+            Context ctx = beanManager.getContext(RequestScoped.class);
+            return ctx != null;
+        }
+        catch (ContextNotActiveException ex)
+        {
+            //No op
+        }
+        catch (Exception ex)
+        {
+            //No op
+        }
+        return false;
+    }
+    
     public static boolean isViewScopeActive(BeanManager beanManager)
     {
         try 
diff --git a/impl/src/main/java/org/apache/myfaces/push/cdi/PushContextImpl.java b/impl/src/main/java/org/apache/myfaces/push/cdi/PushContextImpl.java
index 29ea8053e..d0c0742b7 100644
--- a/impl/src/main/java/org/apache/myfaces/push/cdi/PushContextImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/push/cdi/PushContextImpl.java
@@ -69,12 +69,15 @@ public class PushContextImpl implements PushContext
         WebsocketViewBean viewTokenBean = null;
         WebsocketSessionBean sessionTokenBean = null;
         
-        if (CDIUtils.isSessionScopeActive(beanManager))
+        if (CDIUtils.isRequestScopeActive(beanManager))
         {
-            sessionTokenBean = CDIUtils.get(beanManager, WebsocketSessionBean.class, false);
-            if (CDIUtils.isViewScopeActive(beanManager))
+            if (CDIUtils.isSessionScopeActive(beanManager))
             {
-                viewTokenBean = CDIUtils.get(beanManager, WebsocketViewBean.class, false);
+                sessionTokenBean = CDIUtils.get(beanManager, WebsocketSessionBean.class, false);
+                if (CDIUtils.isViewScopeActive(beanManager))
+                {
+                    viewTokenBean = CDIUtils.get(beanManager, WebsocketViewBean.class, false);
+                }
             }
         }