You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2010/08/09 14:34:02 UTC
svn commit: r983614 - in
/myfaces/extensions/cdi/trunk/jee-modules/jsf-module:
api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/
impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/
impl/src/main/java/org/apach...
Author: gpetracek
Date: Mon Aug 9 12:34:01 2010
New Revision: 983614
URL: http://svn.apache.org/viewvc?rev=983614&view=rev
Log:
EXTCDI-1, EXTCDI-2 and EXTCDI-3 initial request refactoring
Modified:
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/ConfigParameter.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/DefaultWindowContextConfig.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultWindowContextManager.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/JsfAwareWindowContextConfig.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/util/ConversationUtils.java
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/ConfigParameter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/ConfigParameter.java?rev=983614&r1=983613&r2=983614&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/ConfigParameter.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/ConfigParameter.java Mon Aug 9 12:34:01 2010
@@ -35,6 +35,11 @@ public interface ConfigParameter
static final boolean URL_PARAMETER_ENABLED_DEFAULT = true;
+ static final String DISABLE_INITIAL_REDIRECT =
+ CoreCodiConfigParameter.BASE_NAME + "DISABLE_INITIAL_REDIRECT";
+
+ static final boolean DISABLE_INITIAL_REDIRECT_DEFAULT = false;
+
static final String GROUPED_CONVERSATION_TIMEOUT =
CoreCodiConfigParameter.BASE_NAME + "GROUPED_CONVERSATION_TIMEOUT";
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/DefaultWindowContextConfig.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/DefaultWindowContextConfig.java?rev=983614&r1=983613&r2=983614&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/DefaultWindowContextConfig.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/config/DefaultWindowContextConfig.java Mon Aug 9 12:34:01 2010
@@ -100,6 +100,30 @@ public class DefaultWindowContextConfig
return getAttribute(MAX_WINDOW_CONTEXT_COUNT, Integer.class);
}
+ public WindowHandler getWindowHandler()
+ {
+ return new DefaultWindowHandler(isUrlParameterSupported())
+ {
+ private static final long serialVersionUID = 7376499174252256735L;
+ };
+ }
+
+ public ConversationFactory getConversationFactory()
+ {
+ return new JsfAwareConversationFactory();
+ }
+
+ public WindowContextQuotaHandler getWindowContextQuotaHandler()
+ {
+ return new DefaultWindowContextQuotaHandler(getMaxWindowContextCount());
+ }
+
+ public boolean disableInitialRedirect()
+ {
+ lazyInit();
+ return getAttribute(DISABLE_INITIAL_REDIRECT, Boolean.class);
+ }
+
private void lazyInit()
{
if (configInitialized == null)
@@ -121,6 +145,7 @@ public class DefaultWindowContextConfig
initMaxWindowContextCount(facesContext, ProjectStage.SystemTest.equals(currentProjectStage));
initWindowContextTimeout(facesContext);
initGroupedConversationTimeout(facesContext);
+ initDisableInitialRedirect(facesContext);
}
private void initUrlParameterEnabled(FacesContext facesContext)
@@ -221,21 +246,27 @@ public class DefaultWindowContextConfig
setAttribute(GROUPED_CONVERSATION_TIMEOUT, Integer.parseInt(timeoutString));
}
- public WindowHandler getWindowHandler()
+ private void initDisableInitialRedirect(FacesContext facesContext)
{
- return new DefaultWindowHandler(isUrlParameterSupported())
+ boolean disableInitialRedirect = DISABLE_INITIAL_REDIRECT_DEFAULT;
+
+ String disableInitialRedirectString =
+ facesContext.getExternalContext().getInitParameter(DISABLE_INITIAL_REDIRECT);
+
+ if (disableInitialRedirectString == null)
{
- private static final long serialVersionUID = 7376499174252256735L;
- };
- }
+ setAttribute(DISABLE_INITIAL_REDIRECT, disableInitialRedirect);
+ return;
+ }
- public ConversationFactory getConversationFactory()
- {
- return new JsfAwareConversationFactory();
- }
+ disableInitialRedirectString = disableInitialRedirectString.trim();
- public WindowContextQuotaHandler getWindowContextQuotaHandler()
- {
- return new DefaultWindowContextQuotaHandler(getMaxWindowContextCount());
+ if ("".equals(disableInitialRedirectString))
+ {
+ setAttribute(DISABLE_INITIAL_REDIRECT, disableInitialRedirect);
+ return;
+ }
+
+ setAttribute(DISABLE_INITIAL_REDIRECT, Boolean.parseBoolean(disableInitialRedirectString));
}
}
\ No newline at end of file
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultWindowContextManager.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultWindowContextManager.java?rev=983614&r1=983613&r2=983614&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultWindowContextManager.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultWindowContextManager.java Mon Aug 9 12:34:01 2010
@@ -21,7 +21,6 @@ package org.apache.myfaces.extensions.cd
import org.apache.myfaces.extensions.cdi.core.api.resolver.ConfigResolver;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.Conversation;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.WindowContext;
-import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.WindowContextConfig;
import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage;
import org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.WindowContextManager;
import org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.EditableConversation;
@@ -35,6 +34,7 @@ import org.apache.myfaces.extensions.cdi
import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.JsfUtils;
import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.RequestCache;
import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils.*;
+import static org.apache.myfaces.extensions.cdi.javaee.jsf.impl.util.ConversationUtils.resolveWindowContextId;
import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.EditableWindowContext;
import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.JsfAwareWindowContextConfig;
import org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.spi.EditableWindowContextManager;
@@ -62,6 +62,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap;
import java.lang.annotation.Annotation;
+import java.io.IOException;
/**
* @author Gerhard Petracek
@@ -83,7 +84,7 @@ public class DefaultWindowContextManager
@SuppressWarnings({"UnusedDeclaration"})
private ProjectStage projectStage;
- private WindowContextConfig windowContextConfig;
+ private JsfAwareWindowContextConfig jsfAwareWindowContextConfig;
private WindowHandler windowHandler;
@@ -94,13 +95,10 @@ public class DefaultWindowContextManager
@PostConstruct
protected void init()
{
- this.windowContextConfig = this.configResolver.resolve(WindowContextConfig.class);
+ this.jsfAwareWindowContextConfig = this.configResolver.resolve(JsfAwareWindowContextConfig.class);
- JsfAwareWindowContextConfig jsfAwareWindowContextConfig =
- configResolver.resolve(JsfAwareWindowContextConfig.class);
-
- this.windowHandler = jsfAwareWindowContextConfig.getWindowHandler();
- this.windowContextQuotaHandler = jsfAwareWindowContextConfig.getWindowContextQuotaHandler();
+ this.windowHandler = this.jsfAwareWindowContextConfig.getWindowHandler();
+ this.windowContextQuotaHandler = this.jsfAwareWindowContextConfig.getWindowContextQuotaHandler();
this.projectStageDevelopment = ProjectStage.Development.equals(this.projectStage);
}
@@ -122,11 +120,20 @@ public class DefaultWindowContextManager
//don't change/optimize this observer!!!
protected void cleanup(@Observes @AfterPhase(PhaseId.RESTORE_VIEW) PhaseEvent phaseEvent,
- RequestTypeResolver requestTypeResolver,
- WindowContext windowContext)
+ RequestTypeResolver requestTypeResolver)
{
+
+ if (!requestTypeResolver.isPostRequest() && !requestTypeResolver.isPartialRequest())
+ {
+ boolean continueRequest = processGetRequest(phaseEvent.getFacesContext());
+ if (!continueRequest)
+ {
+ return;
+ }
+ }
+
//don't refactor it to a lazy restore
- storeCurrentViewIdAsNewViewId(phaseEvent.getFacesContext(), windowContext);
+ storeCurrentViewIdAsNewViewId(phaseEvent.getFacesContext(), getCurrentWindowContext());
//for performance reasons + cleanup at the beginning of the request (check timeout,...)
//+ we aren't allowed to cleanup in case of redirects
@@ -198,7 +205,7 @@ public class DefaultWindowContextManager
if(windowContextId == null)
{
- windowContextId = resolveWindowContextId(this.windowContextConfig.isUrlParameterSupported(),
+ windowContextId = resolveWindowContextId(this.jsfAwareWindowContextConfig.isUrlParameterSupported(),
this.windowHandler);
if (windowContextId == null)
@@ -247,7 +254,8 @@ public class DefaultWindowContextManager
if (result == null)
{
- result = new JsfWindowContext(windowContextId, this.windowContextConfig, this.projectStageDevelopment);
+ result = new JsfWindowContext(
+ windowContextId, this.jsfAwareWindowContextConfig, this.projectStageDevelopment);
this.windowContextMap.put(windowContextId, result);
}
@@ -421,4 +429,60 @@ public class DefaultWindowContextManager
{
return Collections.unmodifiableCollection(this.windowContextMap.values());
}
+
+ /**
+ * an external app might call a page without url parameter.
+ * to support such an use-case it's possible to
+ * - deactivate the url parameter support (requires a special WindowHandler see e.g.
+ * ServerSideWindowHandler for jsf2
+ * - disable the initial redirect
+ * - use windowId=automatedEntryPoint as url parameter to force a new window context
+ * @param facesContext current facesContext
+ * @return true if the current request should be continued
+ */
+ private boolean processGetRequest(FacesContext facesContext)
+ {
+ boolean isUrlParameterSupported = this.jsfAwareWindowContextConfig.isUrlParameterSupported();
+ boolean useWindowIdForFirstPage = !this.jsfAwareWindowContextConfig.disableInitialRedirect();
+
+ if(!isUrlParameterSupported)
+ {
+ useWindowIdForFirstPage = false;
+ }
+
+ if(useWindowIdForFirstPage)
+ {
+ String windowId = facesContext.getExternalContext()
+ .getRequestParameterMap().get(WINDOW_CONTEXT_ID_PARAMETER_KEY);
+
+ if("automatedEntryPoint".equalsIgnoreCase(windowId))
+ {
+ return true;
+ }
+
+ windowId = resolveWindowContextId(isUrlParameterSupported, ConversationUtils.getWindowHandler());
+
+ if(windowId == null)
+ {
+ redirect(facesContext);
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private void redirect(FacesContext facesContext)
+ {
+ try
+ {
+ String targetURL = facesContext.getApplication()
+ .getViewHandler().getActionURL(facesContext, facesContext.getViewRoot().getViewId());
+
+ this.windowHandler.sendRedirect(FacesContext.getCurrentInstance().getExternalContext(), targetURL);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/JsfAwareWindowContextConfig.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/JsfAwareWindowContextConfig.java?rev=983614&r1=983613&r2=983614&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/JsfAwareWindowContextConfig.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/spi/JsfAwareWindowContextConfig.java Mon Aug 9 12:34:01 2010
@@ -30,4 +30,6 @@ public abstract class JsfAwareWindowCont
public abstract ConversationFactory getConversationFactory();
public abstract WindowContextQuotaHandler getWindowContextQuotaHandler();
+
+ public abstract boolean disableInitialRedirect();
}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/util/ConversationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/util/ConversationUtils.java?rev=983614&r1=983613&r2=983614&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/util/ConversationUtils.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/util/ConversationUtils.java Mon Aug 9 12:34:01 2010
@@ -349,7 +349,7 @@ public class ConversationUtils
}
}
- public static WindowHandler getWindowHandler()
+ public static JsfAwareWindowContextConfig getJsfAwareWindowContextConfig()
{
Set<Bean<?>> configResolvers = getInstance().getBeanManager().getBeans(ConfigResolver.class);
@@ -357,7 +357,12 @@ public class ConversationUtils
ConfigResolver configResolver = (ConfigResolver) CodiUtils
.getOrCreateScopedInstanceOfBean(configResolvers.iterator().next());
- return configResolver.resolve(JsfAwareWindowContextConfig.class).getWindowHandler();
+ return configResolver.resolve(JsfAwareWindowContextConfig.class);
+ }
+
+ public static WindowHandler getWindowHandler()
+ {
+ return getJsfAwareWindowContextConfig().getWindowHandler();
}
public static WindowContextManager getWindowContextManager()