You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/09/14 22:41:33 UTC

svn commit: r997085 - /myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java

Author: jakobk
Date: Tue Sep 14 20:41:32 2010
New Revision: 997085

URL: http://svn.apache.org/viewvc?rev=997085&view=rev
Log:
MYFACES-2921 FlashImpl should set a correct path for the Cookies

Modified:
    myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java?rev=997085&r1=997084&r2=997085&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java Tue Sep 14 20:41:32 2010
@@ -18,6 +18,15 @@
  */
 package org.apache.myfaces.shared.context.flash;
 
+import org.apache.myfaces.shared.util.ExternalContextUtils;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.Flash;
+import javax.faces.event.PhaseId;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
 import java.io.Serializable;
 import java.math.BigInteger;
 import java.security.NoSuchAlgorithmException;
@@ -31,16 +40,6 @@ import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.logging.Logger;
 
-import javax.faces.application.FacesMessage;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.Flash;
-import javax.faces.event.PhaseId;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.myfaces.shared.util.ExternalContextUtils;
-
 /**
  * Implementation of Flash object
  * 
@@ -550,6 +549,7 @@ public class FlashImpl extends Flash
         {
             Cookie cookie = new Cookie(FLASH_REDIRECT, "true");
             cookie.setMaxAge(-1);
+            cookie.setPath(_getCookiePath(externalContext));
             httpResponse.addCookie(cookie);
         }
         else
@@ -589,6 +589,7 @@ public class FlashImpl extends Flash
                 // the maxAge to 0 seconds. The effect is we passed FLASH_REDIRECT param 
                 // to this request object
                 cookie.setMaxAge(0);
+                cookie.setPath(_getCookiePath(externalContext));
                 cookie.setValue(null);
                 httpResponse.addCookie(cookie);
             }
@@ -694,6 +695,7 @@ public class FlashImpl extends Flash
         {
             Cookie cookie = new Cookie(FLASH_RENDER_MAP_TOKEN, tokenValue);
             cookie.setMaxAge(-1);
+            cookie.setPath(_getCookiePath(externalContext));
             httpResponse.addCookie(cookie);
         }
         else
@@ -959,6 +961,23 @@ public class FlashImpl extends Flash
         // always be an execute Map, however sometimes an empty one!
         map.clear();
     }
+
+    /**
+     * Returns the path for the Flash-Cookies.
+     * @param externalContext
+     * @return
+     */
+    private String _getCookiePath(ExternalContext externalContext)
+    {
+        String contextPath = externalContext.getRequestContextPath();
+
+        if (contextPath == null || "".equals(contextPath))
+        {
+            contextPath = "/";
+        }
+
+        return contextPath;
+    }
     
     /**
      * Convert the Object to a Boolean.