openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1647821 - in /openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf: JSFUtil.java WebBeansPhaseListener.java
Date Wed, 24 Dec 2014 17:37:35 GMT
Author: rmannibucau
Date: Wed Dec 24 17:37:34 2014
New Revision: 1647821

URL: http://svn.apache.org/r1647821
Log:
conversationPropagation request param

Modified:
    openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/JSFUtil.java
    openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansPhaseListener.java

Modified: openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/JSFUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/JSFUtil.java?rev=1647821&r1=1647820&r2=1647821&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/JSFUtil.java (original)
+++ openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/JSFUtil.java Wed
Dec 24 17:37:34 2014
@@ -142,4 +142,14 @@ public final class JSFUtil
         return getJSFRequestParameter("cid");
     }
 
+    public static String getConversationPropagation()
+    {
+        final String conversationPropagation = getJSFRequestParameter("conversationPropagation");
+        if (conversationPropagation == null && "true".equalsIgnoreCase(getJSFRequestParameter("nocid")))
// compat
+        {
+            return "none";
+        }
+        return conversationPropagation;
+    }
+
 }

Modified: openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansPhaseListener.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansPhaseListener.java?rev=1647821&r1=1647820&r2=1647821&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansPhaseListener.java
(original)
+++ openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansPhaseListener.java
Wed Dec 24 17:37:34 2014
@@ -21,6 +21,8 @@ package org.apache.webbeans.jsf;
 import javax.enterprise.context.BusyConversationException;
 import javax.enterprise.context.Conversation;
 import javax.enterprise.context.NonexistentConversationException;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
@@ -102,18 +104,25 @@ public class WebBeansPhaseListener imple
             WebBeansContext webBeansContext = WebBeansContext.getInstance();
             ConversationManager conversationManager = webBeansContext.getConversationManager();
             Conversation conversation = conversationManager.getConversationBeanReference();
-            String cid = JSFUtil.getConversationId();
             ContextFactory contextFactory = webBeansContext.getContextFactory();
 
-            if (conversation.isTransient())
+            String propagation = JSFUtil.getConversationPropagation();
+            boolean createNew = "none".equals(propagation);
+
+            if (createNew)
+            {
+                contextFactory.initConversationContext(getRequest(phaseEvent));
+            }
+            else if (conversation.isTransient())
             {
                 if (logger.isLoggable(Level.FINE))
                 {
                     logger.log(Level.FINE, "Creating a new transitional conversation with
cid : [{0}]", conversation.getId());
                 }
-                contextFactory.initConversationContext(null);
+                contextFactory.initConversationContext(getRequest(phaseEvent));
 
                 //Not restore, throw exception
+                String cid = JSFUtil.getConversationId();
                 if(cid != null && !cid.equals(""))
                 {
                     throw new NonexistentConversationException("Propogated conversation with
cid=" + cid + " is not restored. It creates a new transient conversation.");
@@ -130,9 +139,10 @@ public class WebBeansPhaseListener imple
                 ConversationImpl owbConversation = (ConversationImpl)conversation;
                 if(!owbConversation.getInUsed().compareAndSet(false, true))
                 {
-                    contextFactory.initConversationContext(null);
+                    contextFactory.initConversationContext(getRequest(phaseEvent));
                     //Throw Busy exception
-                    throw new BusyConversationException("Propogated conversation with cid="
+ cid + " is used by other request. It creates a new transient conversation");
+                    throw new BusyConversationException(
+                            "Propogated conversation with cid=" + JSFUtil.getConversationId()
+ " is used by other request. It creates a new transient conversation");
                 }
                 else
                 {
@@ -143,6 +153,21 @@ public class WebBeansPhaseListener imple
         }
     }
 
+    // depend the lifecycle impl so give the request if we have it
+    private Object getRequest(final PhaseEvent phaseEvent)
+    {
+        final FacesContext facesContext = phaseEvent.getFacesContext();
+        if (facesContext != null)
+        {
+            final ExternalContext externalContext = facesContext.getExternalContext();
+            if (externalContext != null)
+            {
+                return externalContext.getRequest();
+            }
+        }
+        return null;
+    }
+
     @Override
     public PhaseId getPhaseId()
     {



Mime
View raw message