deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject deltaspike git commit: DELTASPIKE-932 merged cookies
Date Mon, 29 Jun 2015 20:24:16 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master ff4c502f2 -> 1f15e89e4


DELTASPIKE-932 merged cookies

Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/1f15e89e
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/1f15e89e
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/1f15e89e

Branch: refs/heads/master
Commit: 1f15e89e4c9dc59f7b292a29be7a0e3279ea1e3f
Parents: ff4c502
Author: Thomas Andraschko <tandraschko@apache.org>
Authored: Mon Jun 29 22:24:08 2015 +0200
Committer: Thomas Andraschko <tandraschko@apache.org>
Committed: Mon Jun 29 22:24:08 2015 +0200

----------------------------------------------------------------------
 .../component/window/WindowIdHtmlRenderer.java  |  6 ++++-
 .../strategy/AbstractClientWindowStrategy.java  | 20 +++++++++++------
 .../strategy/ClientSideWindowStrategy.java      |  7 +++---
 .../window/strategy/LazyWindowStrategy.java     |  5 ++---
 .../jsf/impl/util/ClientWindowHelper.java       | 23 ++++++--------------
 .../resources/deltaspike/windowhandler.js       |  6 +++--
 .../main/resources/static/windowhandler.html    |  2 +-
 7 files changed, 36 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1f15e89e/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHtmlRenderer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHtmlRenderer.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHtmlRenderer.java
index ddac083..ad992e9 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHtmlRenderer.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHtmlRenderer.java
@@ -27,6 +27,7 @@ import javax.faces.render.FacesRenderer;
 import javax.faces.render.Renderer;
 import java.io.IOException;
 import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
 
 import org.apache.deltaspike.core.api.provider.BeanProvider;
 import org.apache.deltaspike.core.spi.scope.window.WindowContext;
@@ -79,8 +80,11 @@ public class WindowIdHtmlRenderer extends Renderer
         if (cookie != null && cookie instanceof Cookie)
         {
             Cookie servletCookie = (Cookie) cookie;
-            ClientWindowHelper.removeRequestWindowIdCookie(context, servletCookie);
             writer.write("window.deltaspikeInitialRedirectWindowId='" + servletCookie.getValue()
+ "';");
+            
+            // expire/remove cookie
+            servletCookie.setMaxAge(0);
+            ((HttpServletResponse) context.getExternalContext().getResponse()).addCookie(servletCookie);
         }
 
         writer.endElement("script");

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1f15e89e/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/AbstractClientWindowStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/AbstractClientWindowStrategy.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/AbstractClientWindowStrategy.java
index a985630..7009dd4 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/AbstractClientWindowStrategy.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/AbstractClientWindowStrategy.java
@@ -63,7 +63,6 @@ public abstract class AbstractClientWindowStrategy implements ClientWindow
         this.maxWindowIdCount = ClientWindowHelper.getMaxWindowIdLength();
     }
 
-
     @Override
     public String getWindowId(FacesContext facesContext)
     {
@@ -78,9 +77,12 @@ public abstract class AbstractClientWindowStrategy implements ClientWindow
 
         windowId = getOrCreateWindowId(facesContext);
 
-        if (windowId != null && windowId.length() > this.maxWindowIdCount)
+        if (windowId != null)
         {
-            windowId = windowId.substring(0, this.maxWindowIdCount);
+            if (windowId.length() > this.maxWindowIdCount)
+            {
+                windowId = windowId.substring(0, this.maxWindowIdCount);
+            }
 
             requestMap.put(CACHE_WINDOW_ID, windowId);
         }
@@ -115,10 +117,7 @@ public abstract class AbstractClientWindowStrategy implements ClientWindow
         return false;
     }
 
-    /**
-     * Extract the windowId for http POST
-     */
-    protected String getPostBackWindowId(FacesContext facesContext)
+    protected String getWindowIdPostParameter(FacesContext facesContext)
     {
         Map<String, String> requestParams = facesContext.getExternalContext().getRequestParameterMap();
         String windowId = requestParams.get(ClientWindowHelper.RequestParameters.POST_WINDOW_ID);
@@ -127,9 +126,16 @@ public abstract class AbstractClientWindowStrategy implements ClientWindow
         {
             windowId = requestParams.get(ClientWindowHelper.RequestParameters.JSF_POST_WINDOW_ID);
         }
+
         return windowId;
     }
 
+    protected String getWindowIdParameter(FacesContext facesContext)
+    {
+        Map<String, String> requestParameters = facesContext.getExternalContext().getRequestParameterMap();
+        return requestParameters.get(ClientWindowHelper.RequestParameters.GET_WINDOW_ID);
+    }
+    
     @Override
     public void disableClientWindowRenderMode(FacesContext facesContext)
     {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1f15e89e/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/ClientSideWindowStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/ClientSideWindowStrategy.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/ClientSideWindowStrategy.java
index fdf2ee9..6d2598a 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/ClientSideWindowStrategy.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/ClientSideWindowStrategy.java
@@ -60,7 +60,7 @@ public class ClientSideWindowStrategy extends AbstractClientWindowStrategy
 
         if (post)
         {
-            windowId = getPostBackWindowId(facesContext);
+            windowId = getWindowIdPostParameter(facesContext);
         }
         else if (isNoscriptRequest(facesContext.getExternalContext()))
         {
@@ -168,7 +168,8 @@ public class ClientSideWindowStrategy extends AbstractClientWindowStrategy
 
     protected String getVerifiedWindowIdFromCookie(ExternalContext externalContext)
     {
-        String cookieName = ClientWindowHelper.Cookies.WINDOW_ID_PREFIX + getRequestToken(externalContext);
+        String cookieName =
+                ClientWindowHelper.Cookies.REQUEST_WINDOW_ID_PREFIX + getRequestTokenParameter(externalContext);
         Cookie cookie = (Cookie) externalContext.getRequestCookieMap().get(cookieName);
 
         if (cookie != null)
@@ -184,7 +185,7 @@ public class ClientSideWindowStrategy extends AbstractClientWindowStrategy
         return null;
     }
 
-    protected String getRequestToken(ExternalContext externalContext)
+    protected String getRequestTokenParameter(ExternalContext externalContext)
     {
         String requestToken =
                 externalContext.getRequestParameterMap().get(ClientWindowHelper.RequestParameters.REQUEST_TOKEN);

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1f15e89e/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/LazyWindowStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/LazyWindowStrategy.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/LazyWindowStrategy.java
index c1ae6ca..794a1bc 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/LazyWindowStrategy.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/LazyWindowStrategy.java
@@ -38,15 +38,14 @@ public class LazyWindowStrategy extends AbstractClientWindowStrategy
 
         if (StringUtils.isEmpty(windowId))
         {
-            Map<String, String> requestParameters = facesContext.getExternalContext().getRequestParameterMap();
-            windowId = requestParameters.get(ClientWindowHelper.RequestParameters.GET_WINDOW_ID);
+            windowId = getWindowIdParameter(facesContext);
         }
 
         boolean post = isPost(facesContext);
 
         if (StringUtils.isEmpty(windowId) && post)
         {
-            windowId = getPostBackWindowId(facesContext);
+            windowId = getWindowIdPostParameter(facesContext);
         }
 
         if (StringUtils.isEmpty(windowId))

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1f15e89e/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java
index c86a9b3..971633b 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java
@@ -28,8 +28,6 @@ import javax.enterprise.inject.Typed;
 import javax.faces.FacesException;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletResponse;
 
 import org.apache.deltaspike.jsf.api.config.base.JsfBaseConfig;
 import org.apache.deltaspike.jsf.spi.scope.window.ClientWindow;
@@ -53,7 +51,6 @@ public abstract class ClientWindowHelper
     public abstract class Cookies
     {
         public static final String REQUEST_WINDOW_ID_PREFIX = "dsrwid-";
-        public static final String WINDOW_ID_PREFIX = "dsWindowId-";
     }
 
 
@@ -84,8 +81,8 @@ public abstract class ClientWindowHelper
         //only #encodeResourceURL is portable currently
         url = facesContext.getExternalContext().encodeResourceURL(url);
 
-        // see #729
-        addRequestWindowIdCookie(facesContext, newWindowId);
+        // rember the initial redirect windowId till the next request - see #729
+        addRequestWindowIdCookie(facesContext, newWindowId, newWindowId);
 
         try
         {
@@ -148,34 +145,28 @@ public abstract class ClientWindowHelper
         return url;
     }
 
-    public static void addRequestWindowIdCookie(FacesContext context, String windowId)
+    public static void addRequestWindowIdCookie(FacesContext context, String requestToken,
String windowId)
     {
         Map<String, Object> properties = new HashMap();
         properties.put("path", "/");
         properties.put("maxAge", 30);
 
         context.getExternalContext().addResponseCookie(
-                Cookies.REQUEST_WINDOW_ID_PREFIX + windowId, windowId, properties);
+                Cookies.REQUEST_WINDOW_ID_PREFIX + requestToken, windowId, properties);
     }
 
-    public static Object getRequestWindowIdCookie(FacesContext context, String windowId)
+    public static Object getRequestWindowIdCookie(FacesContext context, String requestToken)
     {
         Map<String, Object> cookieMap = context.getExternalContext().getRequestCookieMap();
 
-        if (cookieMap.containsKey(Cookies.REQUEST_WINDOW_ID_PREFIX + windowId))
+        if (cookieMap.containsKey(Cookies.REQUEST_WINDOW_ID_PREFIX + requestToken))
         {
-            return cookieMap.get(Cookies.REQUEST_WINDOW_ID_PREFIX + windowId);
+            return cookieMap.get(Cookies.REQUEST_WINDOW_ID_PREFIX + requestToken);
         }
 
         return null;
     }
 
-    public static void removeRequestWindowIdCookie(FacesContext context, Cookie cookie)
-    {
-        cookie.setMaxAge(0);
-        ((HttpServletResponse) context.getExternalContext().getResponse()).addCookie(cookie);
-    }
-
     public static int getMaxWindowIdLength()
     {
         int result = JsfBaseConfig.ScopeCustomization.WindowRestriction.ID_MAX_LENGTH;

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1f15e89e/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js
b/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js
index 5856340..38b1ee7 100644
--- a/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js
+++ b/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js
@@ -218,12 +218,14 @@ function eraseRequestCookie() {
     date.setTime(date.getTime()-(10*24*60*60*1000)); // - 10 day
     var expires = ";max-age=0;expires="+date.toGMTString();
     
-    var dsrid = getUrlParameter(window.location.href, 'dsrid'); // random request param
+    // CLIENT_WINDOW 
+    var dsrid = getUrlParameter(window.location.href, 'dsrid');
     if (dsrid) {
-        var cookieName = 'dsWindowId-' + dsrid;
+        var cookieName = 'dsrwid-' + dsrid;
         document.cookie = cookieName+"="+expires+"; path=/";
     }
 
+    // LAZY
     var dswid = getUrlParameter(window.location.href, 'dswid');
     if (dswid) {
         var cookieName = 'dsrwid-' + dswid;

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1f15e89e/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html b/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html
index 24b863a..251e183 100644
--- a/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html
+++ b/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html
@@ -166,7 +166,7 @@ window.onload = function() {
     // we still add hte windowId page param to support lazy windowId dropping for some clients
     newUrl = setUrlParam(newUrl, "dswid", urlId);
 
-    document.cookie = 'dsWindowId-' + requestToken + '=' + windowId + expires+"; path=/";
+    document.cookie = 'dsrwid-' + requestToken + '=' + windowId + expires+"; path=/";
 
     window.location = newUrl;
 }


Mime
View raw message