You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2014/04/16 15:42:37 UTC

svn commit: r1587904 - in /myfaces/orchestra/trunk/core22: ./ src/main/java/org/apache/myfaces/orchestra/conversation/ src/main/java/org/apache/myfaces/orchestra/conversation/jsf/ src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/ ...

Author: lu4242
Date: Wed Apr 16 13:42:36 2014
New Revision: 1587904

URL: http://svn.apache.org/r1587904
Log:
ORCHESTRA-65 Create artifacts compatible with JSF 2.2

Added:
    myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/JsfClientWindowHandler.java
    myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/ClientWindowHandler.java
    myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/ExternalSpecifications.java
    myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraLifecycleWrapper.java
    myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraLifecycleWrapperFactory.java
    myfaces/orchestra/trunk/core22/src/main/resources/META-INF/olc.faces-config.xml
Modified:
    myfaces/orchestra/trunk/core22/   (props changed)
    myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java
    myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/UISeparateConversationContext.java
    myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/FrameworkAdapter.java
    myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java
    myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/RequestParameterResponseWrapper.java
    myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/jsf/RequestParameterExternalContextWrapper.java
    myfaces/orchestra/trunk/core22/src/main/resources/META-INF/faces-config.xml

Propchange: myfaces/orchestra/trunk/core22/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Apr 16 13:42:36 2014
@@ -6,6 +6,7 @@
 .externalToolBuilders
 .project
 .settings
+dependency-reduced-pom.xml
 derby.log
 maven-eclipse.xml
 myfacesOrchestraDB

Modified: myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java?rev=1587904&r1=1587903&r2=1587904&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java (original)
+++ myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java Wed Apr 16 13:42:36 2014
@@ -80,6 +80,7 @@ public class ConversationManager impleme
     // This member must always be accessed with a lock held on the parent ConverstationManager instance;
     // a HashMap is not thread-safe and this class must be thread-safe.
     private final Map conversationContexts = new HashMap();
+    private final Map<String, Long> windowIdToConversationContextId = new HashMap<String, Long>(4);
 
     protected ConversationManager()
     {
@@ -172,12 +173,22 @@ public class ConversationManager impleme
         Long conversationContextId = (Long)fa.getRequestAttribute(CONVERSATION_CONTEXT_REQ);
         if (conversationContextId == null)
         {
-            if (fa.containsRequestParameterAttribute(CONVERSATION_CONTEXT_PARAM))
+            String clientWindowId = fa.getClientWindowHandler().getId(fa);
+            if (clientWindowId != null)
             {
-                String urlConversationContextId = fa.getRequestParameterAttribute(
-                        CONVERSATION_CONTEXT_PARAM).toString();
-                conversationContextId = new Long(
-                        Long.parseLong(urlConversationContextId, Character.MAX_RADIX));
+                // Take it from the environment
+                conversationContextId = windowIdToConversationContextId.get(clientWindowId);
+            }
+            else
+            {
+                // Fallback to url parameter
+                if (fa.containsRequestParameterAttribute(CONVERSATION_CONTEXT_PARAM))
+                {
+                    String urlConversationContextId = fa.getRequestParameterAttribute(
+                            CONVERSATION_CONTEXT_PARAM).toString();
+                    conversationContextId = new Long(
+                            Long.parseLong(urlConversationContextId, Character.MAX_RADIX));
+                }
             }
         }
         return conversationContextId;
@@ -208,6 +219,11 @@ public class ConversationManager impleme
             conversationContextId = createNextConversationContextId();
             FrameworkAdapter fa = FrameworkAdapter.getCurrentInstance();
             fa.setRequestAttribute(CONVERSATION_CONTEXT_REQ, conversationContextId);
+            String clientWindowId = fa.getClientWindowHandler().getId(fa);
+            if (clientWindowId != null)
+            {
+                windowIdToConversationContextId.put(clientWindowId, conversationContextId);
+            }
         }
 
         return conversationContextId;
@@ -338,6 +354,11 @@ public class ConversationManager impleme
     {
         FrameworkAdapter fa = FrameworkAdapter.getCurrentInstance();
         fa.setRequestAttribute(CONVERSATION_CONTEXT_REQ, ctx.getIdAsLong());
+        String clientWindowId = fa.getClientWindowHandler().getId(fa);
+        if (clientWindowId != null)
+        {
+            windowIdToConversationContextId.put(clientWindowId, ctx.getIdAsLong());
+        }
     }
 
     /**
@@ -385,6 +406,18 @@ public class ConversationManager impleme
         synchronized(conversationContexts)
         {
             conversationContexts.remove(context.getIdAsLong());
+            
+            Long ccid = context.getIdAsLong();
+            // Linear complexity but usually there are few windows per user.
+            for (Iterator<Map.Entry<String,Long>> it = windowIdToConversationContextId.entrySet().iterator();
+                    it.hasNext();)
+            {
+                Map.Entry<String,Long> entry = it.next();
+                if (ccid.equals(entry.getValue()))
+                {
+                    it.remove();
+                }
+            }
         }
 
         ConversationContext parent = context.getParent();

Added: myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/JsfClientWindowHandler.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/JsfClientWindowHandler.java?rev=1587904&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/JsfClientWindowHandler.java (added)
+++ myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/JsfClientWindowHandler.java Wed Apr 16 13:42:36 2014
@@ -0,0 +1,51 @@
+/*
+ * 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.myfaces.orchestra.conversation.jsf;
+
+import javax.faces.context.FacesContext;
+import javax.faces.lifecycle.ClientWindow;
+import org.apache.myfaces.orchestra.frameworkAdapter.ClientWindowHandler;
+import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
+
+/**
+ *
+ */
+public class JsfClientWindowHandler extends ClientWindowHandler
+{
+
+    public JsfClientWindowHandler()
+    {
+    }
+
+    @Override
+    public String getId(FrameworkAdapter fa)
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        if (facesContext != null)
+        {
+            ClientWindow clientWindow = facesContext.getExternalContext().getClientWindow();
+            if (clientWindow != null)
+            {
+                return clientWindow.getId();
+            }
+        }
+        return null;
+    }
+    
+}

Modified: myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/UISeparateConversationContext.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/UISeparateConversationContext.java?rev=1587904&r1=1587903&r2=1587904&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/UISeparateConversationContext.java (original)
+++ myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/UISeparateConversationContext.java Wed Apr 16 13:42:36 2014
@@ -23,6 +23,7 @@ import java.io.IOException;
 
 import javax.faces.component.UIComponentBase;
 import javax.faces.context.FacesContext;
+import javax.faces.lifecycle.ClientWindow;
 
 import org.apache.myfaces.orchestra.conversation.ConversationRequestParameterProvider;
 import org.apache.myfaces.shared.renderkit.RendererUtils;
@@ -56,6 +57,12 @@ public class UISeparateConversationConte
         // those urls will trigger a new conversation context rather than inheriting the one
         // associated with this request.
         ConversationRequestParameterProvider.setInSeparationMode(true);
+        
+        ClientWindow clientWindow = context.getExternalContext().getClientWindow();
+        if (clientWindow != null && clientWindow.getId() != null)
+        {
+            clientWindow.disableClientWindowRenderMode(context);
+        }
     }
 
     public void encodeChildren(FacesContext context) throws IOException
@@ -72,6 +79,12 @@ public class UISeparateConversationConte
             // this flag so false is a reasonable assumption.
             //
             // TODO: actually save the original value?
+            ClientWindow clientWindow = context.getExternalContext().getClientWindow();
+            if (clientWindow != null && clientWindow.getId() != null)
+            {
+                clientWindow.enableClientWindowRenderMode(context);
+            }
+
             ConversationRequestParameterProvider.setInSeparationMode(false);
         }
     }

Added: myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/ClientWindowHandler.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/ClientWindowHandler.java?rev=1587904&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/ClientWindowHandler.java (added)
+++ myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/ClientWindowHandler.java Wed Apr 16 13:42:36 2014
@@ -0,0 +1,33 @@
+/*
+ * 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.myfaces.orchestra.frameworkAdapter;
+
+/**
+ *
+ */
+public abstract class ClientWindowHandler
+{
+    /**
+     * Return an id that identifies a window in a unique way and in that sense can hold a conversation.
+     * 
+     * @return 
+     */
+    public abstract String getId(FrameworkAdapter fa);
+}

Modified: myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/FrameworkAdapter.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/FrameworkAdapter.java?rev=1587904&r1=1587903&r2=1587904&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/FrameworkAdapter.java (original)
+++ myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/FrameworkAdapter.java Wed Apr 16 13:42:36 2014
@@ -21,6 +21,7 @@ package org.apache.myfaces.orchestra.fra
 import java.io.IOException;
 
 import org.apache.myfaces.orchestra.conversation.ConversationMessager;
+import org.apache.myfaces.orchestra.lib.ExternalSpecifications;
 
 /**
  * An interface that provides access to all the data necessary for Orchestra to work while isolating Orchestra
@@ -37,6 +38,8 @@ import org.apache.myfaces.orchestra.conv
 public abstract class FrameworkAdapter
 {
     private final static ThreadLocal instanceThreadLocal = new ThreadLocal();
+    
+    private final static String CLIENT_WINDOW_HANDLER_KEY = "oam.orchestra.ClientWindowHandler";
 
     private ConversationMessager conversationMessager;
     private boolean prepared = false;
@@ -233,4 +236,38 @@ public abstract class FrameworkAdapter
     {
         return "defaultView";
     }
+
+    public ClientWindowHandler getClientWindowHandler()
+    {
+        ClientWindowHandler clientWindowHandler = (ClientWindowHandler) getBean(CLIENT_WINDOW_HANDLER_KEY);
+        if (clientWindowHandler == null)
+        {
+            // This implementation is a bit odd, because it is checking for JSF in a "Framework Adapter" but
+            // you want to use the client window id in JSF and the conversation context id outside JSF, and
+            // in those applications another Framework Adapter not necessarily bound to JSF is used.
+            clientWindowHandler = (ClientWindowHandler) getRequestAttribute(CLIENT_WINDOW_HANDLER_KEY);
+            if (clientWindowHandler == null)
+            {
+                if(ExternalSpecifications.isJsfAvailable())
+                {
+                    clientWindowHandler = ExternalSpecifications.createDefaultJSFClientWindowHandler();
+                }
+                else
+                {
+                    clientWindowHandler = new NoOpClientWindowHandler();
+                }
+                setRequestAttribute(CLIENT_WINDOW_HANDLER_KEY, clientWindowHandler);
+            }
+        }
+        return clientWindowHandler;
+    }
+
+    private static class NoOpClientWindowHandler extends ClientWindowHandler
+    {
+        @Override
+        public String getId(FrameworkAdapter fa)
+        {
+            return null;
+        }
+    }
 }

Added: myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/ExternalSpecifications.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/ExternalSpecifications.java?rev=1587904&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/ExternalSpecifications.java (added)
+++ myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/ExternalSpecifications.java Wed Apr 16 13:42:36 2014
@@ -0,0 +1,114 @@
+/*
+ * 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.myfaces.orchestra.lib;
+
+import java.lang.reflect.Method;
+import java.util.logging.Logger;
+import org.apache.myfaces.orchestra.frameworkAdapter.ClientWindowHandler;
+
+/**
+ * Utility class for determining which specifications are available
+ * in the current process. The idea of this class is use reflection to make
+ * the library optional.
+ */
+public final class ExternalSpecifications
+{
+    private static final Logger log = Logger.getLogger(ExternalSpecifications.class.getName());
+    
+    private static volatile Boolean jsfApiAvailable;
+    
+    private static final Class<?> FACES_CONTEXT_CLASS;
+    private static final Method FACES_CONTEXT_GET_CURRENT_INSTANCE_METHOD;
+    private static final Class<?> DEFAULT_JSF_CLIENT_WINDOW_HANDLER_CLASS;
+    
+    static 
+    {
+        Class<?> facesContextClazz = null;
+        Class<?> defaultClientWindowHandlerClass = null;
+        Method m = null;
+        try
+        {
+            defaultClientWindowHandlerClass = Class.forName(
+                    "org.apache.myfaces.orchestra.conversation.jsf.JsfClientWindowHandler");
+            facesContextClazz = Class.forName("javax.faces.context.FacesContext");
+            if (facesContextClazz != null)
+            {
+                jsfApiAvailable = true;
+                m = facesContextClazz.getMethod("getCurrentInstance");
+            }
+        }
+        catch (ClassNotFoundException ex)
+        {
+            jsfApiAvailable = false;
+        }
+        catch (Throwable t)
+        {
+            jsfApiAvailable = false;
+        }
+        FACES_CONTEXT_CLASS = facesContextClazz;
+        FACES_CONTEXT_GET_CURRENT_INSTANCE_METHOD = m;
+        DEFAULT_JSF_CLIENT_WINDOW_HANDLER_CLASS = defaultClientWindowHandlerClass;
+    }
+    
+    public static boolean isJsfApiAvailable()
+    {
+        if (jsfApiAvailable == null)
+        {
+            try
+            {
+                jsfApiAvailable = (FACES_CONTEXT_CLASS != null);
+            }
+            catch (Throwable t)
+            {
+                jsfApiAvailable = false;
+            }
+        }
+        return jsfApiAvailable;
+    }
+    
+    public static boolean isJsfAvailable()
+    {
+        if (isJsfApiAvailable())
+        {
+            try 
+            {
+                Object o = FACES_CONTEXT_GET_CURRENT_INSTANCE_METHOD.invoke(FACES_CONTEXT_CLASS);
+                return o != null;
+            } 
+            catch (Throwable t) 
+            {
+                return false;
+            }
+        }
+        return false;
+    }
+    
+    public static ClientWindowHandler createDefaultJSFClientWindowHandler()
+    {
+        try
+        {
+            return (ClientWindowHandler) DEFAULT_JSF_CLIENT_WINDOW_HANDLER_CLASS.newInstance();
+        } 
+        catch (Throwable t)
+        {
+        }
+        return null;
+    }
+}

Modified: myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java?rev=1587904&r1=1587903&r2=1587904&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java (original)
+++ myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java Wed Apr 16 13:42:36 2014
@@ -129,6 +129,17 @@ public class OrchestraFacesContextFactor
                             }
     
                             h.init(facesContext);
+                            
+                            // Since when the facesContext is created the client window has not been
+                            // attached yet, it is necessary to wait a little in the initialization process,
+                            // so we start here the first handler and the remaining ones will be called
+                            // after lifecycle.attachWindow are called. This is only valid if the current
+                            // request is not a resource request.
+                            if (!facesContext.getApplication().getResourceHandler().isResourceRequest(facesContext))
+                            {
+                                facesContext.getAttributes().put("oam.orchestra.handlers", i);
+                                break;
+                            }
                         }
                     }
                     catch(RuntimeException e)

Added: myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraLifecycleWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraLifecycleWrapper.java?rev=1587904&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraLifecycleWrapper.java (added)
+++ myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraLifecycleWrapper.java Wed Apr 16 13:42:36 2014
@@ -0,0 +1,87 @@
+/*
+ * 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.myfaces.orchestra.lib.jsf;
+
+import java.util.ListIterator;
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleWrapper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ */
+public class OrchestraLifecycleWrapper extends LifecycleWrapper
+{
+    private final Log log = LogFactory.getLog(OrchestraLifecycleWrapper.class);
+
+    private Lifecycle delegate;
+
+    public OrchestraLifecycleWrapper(Lifecycle delegate)
+    {
+        this.delegate = delegate;
+    }
+
+    @Override
+    public void execute(FacesContext context) throws FacesException
+    {
+        // Only after this step, it is valid to call the lifecycle.
+        ListIterator i = (ListIterator) context.getAttributes().get("oam.orchestra.handlers");
+        if (i != null)
+        {
+            try
+            {
+                while (i.hasNext())
+                {
+                    RequestHandler h = (RequestHandler) i.next();
+
+                    if (log.isDebugEnabled())
+                    {
+                        log.debug("Running inithandler of type " + h.getClass().getName());
+                    }
+
+                    h.init(context);
+                }
+            }
+            catch (RuntimeException e)
+            {
+                // Oops, something went wrong. Undo any processing done by the
+                // RequestHandlers that have successfully run so far.
+                //
+                // Warning:: this tries to run deinit on the object that just
+                // failed to initialise. RequestHandler classes should be written
+                // to correctly handle this.
+                log.error("Problem initialising RequestHandler", e);
+                //_release(i);
+                throw e;
+            }
+        }
+        context.getAttributes().remove("oam.orchestra.handlers");
+        
+        super.execute(context);
+    }
+
+    @Override
+    public Lifecycle getWrapped()
+    {
+        return delegate;
+    }
+}

Added: myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraLifecycleWrapperFactory.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraLifecycleWrapperFactory.java?rev=1587904&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraLifecycleWrapperFactory.java (added)
+++ myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraLifecycleWrapperFactory.java Wed Apr 16 13:42:36 2014
@@ -0,0 +1,65 @@
+/*
+ * 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.myfaces.orchestra.lib.jsf;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+
+/**
+ *
+ */
+public class OrchestraLifecycleWrapperFactory extends LifecycleFactory
+{
+    private LifecycleFactory delegate;
+    
+    private final Map<String, Lifecycle> _lifecycles = new ConcurrentHashMap<String, Lifecycle>();
+
+    public OrchestraLifecycleWrapperFactory(LifecycleFactory delegate)
+    {
+        this.delegate = delegate;
+    }
+
+    @Override
+    public void addLifecycle(String lifecycleId, Lifecycle lifecycle)
+    {
+        Lifecycle o = new OrchestraLifecycleWrapper(lifecycle);
+        _lifecycles.put(lifecycleId, o);
+    }
+
+    @Override
+    public Lifecycle getLifecycle(String lifecycleId)
+    {
+        Lifecycle lifecycle = _lifecycles.get(this);
+        if (lifecycle == null)
+        {
+            lifecycle = new OrchestraLifecycleWrapper(delegate.getLifecycle(lifecycleId));
+            _lifecycles.put(lifecycleId, lifecycle);
+        }
+        return lifecycle;
+    }
+
+    @Override
+    public Iterator<String> getLifecycleIds()
+    {
+        return delegate.getLifecycleIds();
+    }
+}

Modified: myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/RequestParameterResponseWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/RequestParameterResponseWrapper.java?rev=1587904&r1=1587903&r2=1587904&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/RequestParameterResponseWrapper.java (original)
+++ myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/RequestParameterResponseWrapper.java Wed Apr 16 13:42:36 2014
@@ -20,6 +20,7 @@ package org.apache.myfaces.orchestra.req
 
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponseWrapper;
+import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
 
 /**
  * This wrapper intercepts encodeURL and pass it to the {@link RequestParameterProviderManager}
@@ -27,6 +28,8 @@ import javax.servlet.http.HttpServletRes
  */
 public class RequestParameterResponseWrapper extends HttpServletResponseWrapper
 {
+    private Boolean _applyWrap = null;
+
     public RequestParameterResponseWrapper(HttpServletResponse httpServletResponse)
     {
         super(httpServletResponse);
@@ -49,7 +52,16 @@ public class RequestParameterResponseWra
     {
         if (url != null)
         {
-            url = RequestParameterProviderManager.getInstance().encodeAndAttachParameters(url);
+            if (_applyWrap == null)
+            {
+                FrameworkAdapter fa = FrameworkAdapter.getCurrentInstance();
+                // If there is not a client window id, add the query parameter
+                _applyWrap = (fa.getClientWindowHandler().getId(fa) == null);
+            }
+            if (Boolean.TRUE.equals(_applyWrap))
+            {
+                url = RequestParameterProviderManager.getInstance().encodeAndAttachParameters(url);
+            }
         }
 
         return super.encodeURL(url);

Modified: myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/jsf/RequestParameterExternalContextWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/jsf/RequestParameterExternalContextWrapper.java?rev=1587904&r1=1587903&r2=1587904&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/jsf/RequestParameterExternalContextWrapper.java (original)
+++ myfaces/orchestra/trunk/core22/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/jsf/RequestParameterExternalContextWrapper.java Wed Apr 16 13:42:36 2014
@@ -23,12 +23,14 @@ import java.util.Map;
 
 import javax.faces.context.ExternalContext;
 import javax.faces.context.ExternalContextWrapper;
+import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
 
 import org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterProviderManager;
 
 public class RequestParameterExternalContextWrapper extends ExternalContextWrapper
 {
     private ExternalContext _delegate;
+    private Boolean _applyWrap = null;
     
     public RequestParameterExternalContextWrapper(ExternalContext delegate)
     {
@@ -42,7 +44,13 @@ public class RequestParameterExternalCon
         // Mojarra 2.1.3 does not call encodeURL internally, but MyFaces 2.0.x/2.1.x does.
         // Anyway, the place to add Orchestra parameters for redirect should be here.
         String url = super.encodeRedirectURL(baseUrl, parameters);
-        if (url != null)
+        if (_applyWrap == null)
+        {
+            FrameworkAdapter fa = FrameworkAdapter.getCurrentInstance();
+            // If there is not a client window id, add the query parameter
+            _applyWrap = (fa.getClientWindowHandler().getId(fa) == null);
+        }
+        if (Boolean.TRUE.equals(_applyWrap) && url != null)
         {
             url = RequestParameterProviderManager.getInstance().encodeAndAttachParameters(url);
         }

Modified: myfaces/orchestra/trunk/core22/src/main/resources/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core22/src/main/resources/META-INF/faces-config.xml?rev=1587904&r1=1587903&r2=1587904&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core22/src/main/resources/META-INF/faces-config.xml (original)
+++ myfaces/orchestra/trunk/core22/src/main/resources/META-INF/faces-config.xml Wed Apr 16 13:42:36 2014
@@ -28,7 +28,7 @@
     <application>
         <variable-resolver>org.apache.myfaces.orchestra.viewController.jsf.ViewControllerVariableResolver</variable-resolver>
     </application>
-
+    
     <component>
         <component-type>org.apache.myfaces.orchestra.EndConversation</component-type>
         <component-class>org.apache.myfaces.orchestra.conversation.jsf.components.UIEndConversation</component-class>

Added: myfaces/orchestra/trunk/core22/src/main/resources/META-INF/olc.faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core22/src/main/resources/META-INF/olc.faces-config.xml?rev=1587904&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core22/src/main/resources/META-INF/olc.faces-config.xml (added)
+++ myfaces/orchestra/trunk/core22/src/main/resources/META-INF/olc.faces-config.xml Wed Apr 16 13:42:36 2014
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<faces-config version="2.2"
+    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
+    
+    <name>orchestra_lifecycle</name>
+    
+    <ordering>
+        <after>
+            <others/>
+        </after>
+    </ordering>
+    
+    <factory>
+        <lifecycle-factory>org.apache.myfaces.orchestra.lib.jsf.OrchestraLifecycleWrapperFactory</lifecycle-factory>
+    </factory>
+</faces-config>