[webbeans-commits] Webbeans SVN: r1713 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: jsf and 1 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Thu Feb 26 05:10:34 EST 2009


Author: nickarls
Date: 2009-02-26 05:10:34 -0500 (Thu, 26 Feb 2009)
New Revision: 1713

Added:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/PhaseHelper.java
Removed:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/JSFHelper.java
Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ConversationEntry.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansServletFilter.java
Log:
additions to redirect filter
JSFHelper -> PhaseHelper
remove conversation handling from lifecycle for now


Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ConversationEntry.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ConversationEntry.java	2009-02-25 22:51:58 UTC (rev 1712)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ConversationEntry.java	2009-02-26 10:10:34 UTC (rev 1713)
@@ -26,7 +26,6 @@
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
 import org.jboss.webbeans.servlet.ConversationBeanStore;
-import org.jboss.webbeans.servlet.ServletLifecycle;
 
 /**
  * Represents a long-running conversation entry
@@ -101,7 +100,9 @@
       {
          cancelTermination();
       }
-      ServletLifecycle.instance().destroyConversation(session, cid);
+      ConversationContext terminationContext = new ConversationContext();
+      terminationContext.setBeanStore(new ConversationBeanStore(session, cid));
+      terminationContext.destroy();
       log.trace("Conversation " + cid + " destroyed");
    }
 

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java	2009-02-25 22:51:58 UTC (rev 1712)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java	2009-02-26 10:10:34 UTC (rev 1713)
@@ -28,13 +28,13 @@
 
 import org.jboss.webbeans.CurrentManager;
 import org.jboss.webbeans.WebBean;
+import org.jboss.webbeans.context.ConversationContext;
 import org.jboss.webbeans.conversation.bindings.ConversationConcurrentAccessTimeout;
 import org.jboss.webbeans.conversation.bindings.ConversationIdName;
 import org.jboss.webbeans.conversation.bindings.ConversationInactivityTimeout;
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
 import org.jboss.webbeans.servlet.HttpSessionManager;
-import org.jboss.webbeans.servlet.ServletLifecycle;
 
 /**
  * The default conversation manager
@@ -195,8 +195,7 @@
             longRunningConversations.get(cid).cancelTermination();
             longRunningConversations.get(cid).unlock();
          }
-         HttpSession session = CurrentManager.rootManager().getInstanceByType(HttpSessionManager.class).getSession();
-         ServletLifecycle.instance().destroyConversation(session, cid);
+         ConversationContext.INSTANCE.destroy();
       }
       // If Conversation.begin(String) is called, it might be that the
       // conversation will be switched. We need to unlock this original 

Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/JSFHelper.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/JSFHelper.java	2009-02-25 22:51:58 UTC (rev 1712)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/JSFHelper.java	2009-02-26 10:10:34 UTC (rev 1713)
@@ -1,167 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.webbeans.jsf;
-
-import java.io.IOException;
-
-import javax.faces.component.html.HtmlInputHidden;
-import javax.faces.context.FacesContext;
-import javax.inject.AnnotationLiteral;
-import javax.servlet.http.HttpSession;
-
-import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.conversation.bindings.ConversationIdName;
-import org.jboss.webbeans.log.LogProvider;
-import org.jboss.webbeans.log.Logging;
-
-/**
- * Helper class for JSF related operations
- * 
- * @author Nicklas Karlsson
- * 
- */
-public class JSFHelper
-{
-   private static LogProvider log = Logging.getLogProvider(JSFHelper.class);
-
-   private static final String CONVERSATION_PROPAGATION_COMPONENT_ID = "webbeans_conversation_propagation";
-
-   /**
-    * Gets a FacesContext instance
-    * 
-    * @return The current instance
-    */
-   private static FacesContext context()
-   {
-      return FacesContext.getCurrentInstance();
-   }
-
-   /**
-    * Checks if current request is a JSF postback
-    * 
-    * @return True if postback, false otherwise
-    */
-   public static boolean isPostback()
-   {
-      return context().getRenderKit().getResponseStateManager().isPostback(context());
-   }
-
-   /**
-    * Removes the conversation propagation component from the ui view root
-    */
-   public static void removePropagationComponent()
-   {
-      log.debug("Removed propagation component");
-      HtmlInputHidden propagationComponent = getPropagationComponent();
-      if (propagationComponent != null)
-      {
-         context().getViewRoot().getChildren().remove(propagationComponent);
-      }
-   }
-
-   /**
-    * Creates and/or updates the conversation propagation component in the UI
-    * view root
-    * 
-    * @param cid The conversation id to propagate
-    */
-   public static void createOrUpdatePropagationComponent(String cid)
-   {
-      HtmlInputHidden propagationComponent = getPropagationComponent();
-      if (propagationComponent == null)
-      {
-         log.trace("Created propagation component");
-         propagationComponent = (HtmlInputHidden) context().getApplication().createComponent(HtmlInputHidden.COMPONENT_TYPE);
-         propagationComponent.setId(CONVERSATION_PROPAGATION_COMPONENT_ID);
-         context().getViewRoot().getChildren().add(propagationComponent);
-      }
-      log.debug("Updated propagation component with cid " + cid);
-      propagationComponent.setValue(cid);
-   }
-
-   /**
-    * Gets the propagation component from the UI view root
-    * 
-    * @return The component (or null if not found)
-    */
-   private static HtmlInputHidden getPropagationComponent()
-   {
-      return (HtmlInputHidden) context().getViewRoot().findComponent(CONVERSATION_PROPAGATION_COMPONENT_ID);
-   }
-
-   /**
-    * Gets the propagated conversation id parameter from the request
-    * 
-    * @return The conversation id (or null if not found)
-    */
-   public static String getConversationIdFromRequest()
-   {
-      String cidName = CurrentManager.rootManager().getInstanceByType(String.class, new AnnotationLiteral<ConversationIdName>(){});
-      String cid = context().getExternalContext().getRequestParameterMap().get(cidName);
-      log.trace("Got cid " + cid + " from request");
-      return cid;
-   }
-
-   /**
-    * Gets the propagated conversation id from the propagation component
-    * 
-    * @return The conversation id (or null if not found)
-    * @throws IOException
-    */
-   public static String getConversationIdFromPropagationComponent()
-   {
-      String cid = null;
-      HtmlInputHidden propagationComponent = getPropagationComponent();
-      if (propagationComponent != null)
-      {
-         cid = propagationComponent.getValue().toString();
-      }
-      log.trace("Got cid " + cid + " from propagation component");
-      return cid;
-   }
-
-   /**
-    * Gets the propagated conversation id
-    * 
-    * @return The conversation id (or null if not found)
-    */
-   public static String getConversationId()
-   {
-      String cid = null;
-      if (isPostback())
-      {
-         cid = getConversationIdFromPropagationComponent();
-      }
-      else
-      {
-         cid = getConversationIdFromRequest();
-      }
-      log.debug("Resuming conversation " + cid);
-      return cid;
-   }
-
-   /**
-    * Gets the HTTP session
-    * 
-    * @return The session
-    */
-   public static HttpSession getHttpSession()
-   {
-      return (HttpSession) context().getExternalContext().getSession(true);
-   }
-
-}

Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/PhaseHelper.java (from rev 1712, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/JSFHelper.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/PhaseHelper.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/PhaseHelper.java	2009-02-26 10:10:34 UTC (rev 1713)
@@ -0,0 +1,167 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.jsf;
+
+import java.io.IOException;
+
+import javax.faces.component.html.HtmlInputHidden;
+import javax.faces.context.FacesContext;
+import javax.inject.AnnotationLiteral;
+import javax.servlet.http.HttpSession;
+
+import org.jboss.webbeans.CurrentManager;
+import org.jboss.webbeans.conversation.bindings.ConversationIdName;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
+/**
+ * Helper class for JSF related operations
+ * 
+ * @author Nicklas Karlsson
+ * 
+ */
+public class PhaseHelper
+{
+   private static LogProvider log = Logging.getLogProvider(PhaseHelper.class);
+
+   private static final String CONVERSATION_PROPAGATION_COMPONENT_ID = "webbeans_conversation_propagation";
+
+   /**
+    * Gets a FacesContext instance
+    * 
+    * @return The current instance
+    */
+   private static FacesContext context()
+   {
+      return FacesContext.getCurrentInstance();
+   }
+
+   /**
+    * Checks if current request is a JSF postback
+    * 
+    * @return True if postback, false otherwise
+    */
+   public static boolean isPostback()
+   {
+      return context().getRenderKit().getResponseStateManager().isPostback(context());
+   }
+
+   /**
+    * Removes the conversation propagation component from the ui view root
+    */
+   public static void removePropagationComponent()
+   {
+      log.debug("Removed propagation component");
+      HtmlInputHidden propagationComponent = getPropagationComponent();
+      if (propagationComponent != null)
+      {
+         context().getViewRoot().getChildren().remove(propagationComponent);
+      }
+   }
+
+   /**
+    * Creates and/or updates the conversation propagation component in the UI
+    * view root
+    * 
+    * @param cid The conversation id to propagate
+    */
+   public static void createOrUpdatePropagationComponent(String cid)
+   {
+      HtmlInputHidden propagationComponent = getPropagationComponent();
+      if (propagationComponent == null)
+      {
+         log.trace("Created propagation component");
+         propagationComponent = (HtmlInputHidden) context().getApplication().createComponent(HtmlInputHidden.COMPONENT_TYPE);
+         propagationComponent.setId(CONVERSATION_PROPAGATION_COMPONENT_ID);
+         context().getViewRoot().getChildren().add(propagationComponent);
+      }
+      log.debug("Updated propagation component with cid " + cid);
+      propagationComponent.setValue(cid);
+   }
+
+   /**
+    * Gets the propagation component from the UI view root
+    * 
+    * @return The component (or null if not found)
+    */
+   private static HtmlInputHidden getPropagationComponent()
+   {
+      return (HtmlInputHidden) context().getViewRoot().findComponent(CONVERSATION_PROPAGATION_COMPONENT_ID);
+   }
+
+   /**
+    * Gets the propagated conversation id parameter from the request
+    * 
+    * @return The conversation id (or null if not found)
+    */
+   public static String getConversationIdFromRequest()
+   {
+      String cidName = CurrentManager.rootManager().getInstanceByType(String.class, new AnnotationLiteral<ConversationIdName>(){});
+      String cid = context().getExternalContext().getRequestParameterMap().get(cidName);
+      log.trace("Got cid " + cid + " from request");
+      return cid;
+   }
+
+   /**
+    * Gets the propagated conversation id from the propagation component
+    * 
+    * @return The conversation id (or null if not found)
+    * @throws IOException
+    */
+   public static String getConversationIdFromPropagationComponent()
+   {
+      String cid = null;
+      HtmlInputHidden propagationComponent = getPropagationComponent();
+      if (propagationComponent != null)
+      {
+         cid = propagationComponent.getValue().toString();
+      }
+      log.trace("Got cid " + cid + " from propagation component");
+      return cid;
+   }
+
+   /**
+    * Gets the propagated conversation id
+    * 
+    * @return The conversation id (or null if not found)
+    */
+   public static String getConversationId()
+   {
+      String cid = null;
+      if (isPostback())
+      {
+         cid = getConversationIdFromPropagationComponent();
+      }
+      else
+      {
+         cid = getConversationIdFromRequest();
+      }
+      log.debug("Resuming conversation " + cid);
+      return cid;
+   }
+
+   /**
+    * Gets the HTTP session
+    * 
+    * @return The session
+    */
+   public static HttpSession getHttpSession()
+   {
+      return (HttpSession) context().getExternalContext().getSession(true);
+   }
+
+}


Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/PhaseHelper.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java	2009-02-25 22:51:58 UTC (rev 1712)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java	2009-02-26 10:10:34 UTC (rev 1713)
@@ -29,7 +29,6 @@
 import org.jboss.webbeans.log.Logging;
 import org.jboss.webbeans.servlet.ConversationBeanStore;
 import org.jboss.webbeans.servlet.HttpSessionManager;
-import org.jboss.webbeans.servlet.ServletLifecycle;
 
 /**
  * A phase listener for propagating conversation id over postbacks through a
@@ -69,11 +68,11 @@
       Conversation conversation = CurrentManager.rootManager().getInstanceByType(Conversation.class);
       if (conversation.isLongRunning())
       {
-         JSFHelper.createOrUpdatePropagationComponent(conversation.getId());
+         PhaseHelper.createOrUpdatePropagationComponent(conversation.getId());
       }
       else
       {
-         JSFHelper.removePropagationComponent();
+         PhaseHelper.removePropagationComponent();
       }
    }
 
@@ -109,11 +108,11 @@
    private void afterRestoreView()
    {
       log.trace("In after restore view phase");
-      HttpSession session = JSFHelper.getHttpSession();
+      HttpSession session = PhaseHelper.getHttpSession();
       CurrentManager.rootManager().getInstanceByType(HttpSessionManager.class).setSession(session);
-      CurrentManager.rootManager().getInstanceByType(ConversationManager.class).beginOrRestoreConversation(JSFHelper.getConversationId());
+      CurrentManager.rootManager().getInstanceByType(ConversationManager.class).beginOrRestoreConversation(PhaseHelper.getConversationId());
       String cid = CurrentManager.rootManager().getInstanceByType(Conversation.class).getId();
-      ServletLifecycle.instance().restoreConversation(session, cid);
+      ConversationContext.INSTANCE.setBeanStore(new ConversationBeanStore(session, cid));
    }
 
    /**

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java	2009-02-25 22:51:58 UTC (rev 1712)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java	2009-02-26 10:10:34 UTC (rev 1713)
@@ -152,26 +152,4 @@
       SessionContext.INSTANCE.setBeanStore(null);
    }
 
-   /**
-    * Restores a conversation
-    * 
-    * @param session The HTTP session
-    * @param cid The conversation to resume
-    */
-   public void restoreConversation(HttpSession session, String cid)
-   {
-      super.restoreConversation(session.getId() + "[" + cid + "]", new ConversationBeanStore(session, cid));
-   }
-
-   /**
-    * Destroys a conversation
-    * 
-    * @param session The HTTP session
-    * @param cid The conversation to destroy
-    */
-   public void destroyConversation(HttpSession session, String cid)
-   {
-      super.destroyConversation(session.getId() + "[" + cid + "]", new ConversationBeanStore(session, cid));
-   }
-
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansServletFilter.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansServletFilter.java	2009-02-25 22:51:58 UTC (rev 1712)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansServletFilter.java	2009-02-26 10:10:34 UTC (rev 1713)
@@ -20,6 +20,7 @@
 
 import javax.context.Conversation;
 import javax.faces.context.FacesContext;
+import javax.inject.AnnotationLiteral;
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
@@ -30,6 +31,7 @@
 import javax.servlet.http.HttpServletResponseWrapper;
 
 import org.jboss.webbeans.CurrentManager;
+import org.jboss.webbeans.conversation.bindings.ConversationIdName;
 
 /**
  * Filter for handling conversation propagation over redirects
@@ -37,35 +39,51 @@
  * @author Nicklas Karlsson
  * 
  */
-// TODO: Quick and dirty, not for actual usage yet ;-)
 public class WebBeansServletFilter implements Filter
 {
 
-   private class RedirectUrl
+   /**
+    * Helper class for handling URLs
+    * 
+    * @author Nicklas Karlsson
+    */
+   private class UrlTransformer
    {
       private String URL;
       private FacesContext context;
 
-      public RedirectUrl(String URL)
+      private boolean isUrlAbsolute()
       {
+         // TODO: any API call to do this?
+         return URL.startsWith("http://") || URL.startsWith("https://");
+      }
+
+      public UrlTransformer(String URL)
+      {
          this.URL = URL;
          context = FacesContext.getCurrentInstance();
       }
 
-      public RedirectUrl appendCid(String cid)
+      public UrlTransformer appendConversation(String cid)
       {
-         URL = URL + (URL.indexOf("?") > 0 ? "&" : "?") + "cid=" + cid;
+         String cidName = CurrentManager.rootManager().getInstanceByType(String.class, new AnnotationLiteral<ConversationIdName>()
+         {
+         });
+         URL = URL + (URL.indexOf("?") > 0 ? "&" : "?") + cidName + "=" + cid;
          return this;
       }
 
-      public RedirectUrl getRedirectView()
+      public UrlTransformer getRedirectView()
       {
-         String requestPath = context.getExternalContext().getRequestContextPath();
-         URL = URL.substring(URL.indexOf(requestPath) + requestPath.length());
+         if (isUrlAbsolute())
+         {
+            String requestPath = context.getExternalContext().getRequestContextPath();
+            URL = URL.substring(URL.indexOf(requestPath) + requestPath.length());
+         }
          return this;
       }
 
-      public RedirectUrl getActionUrl()
+      public UrlTransformer getActionUrl()
       {
          URL = context.getApplication().getViewHandler().getActionURL(context, URL);
          return this;
@@ -96,7 +114,7 @@
             Conversation conversation = CurrentManager.rootManager().getInstanceByType(Conversation.class);
             if (conversation.isLongRunning())
             {
-               path = new RedirectUrl(path).getRedirectView().getActionUrl().appendCid(conversation.getId()).encode();
+               path = new UrlTransformer(path).getRedirectView().getActionUrl().appendConversation(conversation.getId()).encode();
             }
             super.sendRedirect(path);
          }




More information about the weld-commits mailing list