svn commit: r749970 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/UtilMisc.java webapp/src/org/ofbiz/webapp/control/RequestHandler.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r749970 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/UtilMisc.java webapp/src/org/ofbiz/webapp/control/RequestHandler.java

jonesde
Author: jonesde
Date: Wed Mar  4 11:49:27 2009
New Revision: 749970

URL: http://svn.apache.org/viewvc?rev=749970&view=rev
Log:
Some improvements to the last view and view save code to handle request attributes and more parameters, safe since they are never going int he URL or anything; this resolves the issues I was running into before with this, and hopefully with no side effects other than a few CPU cycles here and there; made sure that the stuff is serializable before putting into the session

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java?rev=749970&r1=749969&r2=749970&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java Wed Mar  4 11:49:27 2009
@@ -18,6 +18,7 @@
  *******************************************************************************/
 package org.ofbiz.base.util;
 
+import java.io.Serializable;
 import java.math.BigDecimal;
 import java.util.Collection;
 import java.util.Collections;
@@ -30,6 +31,8 @@
 import java.util.TreeMap;
 import java.util.TreeSet;
 
+import javax.servlet.ServletContext;
+
 import javolution.util.FastList;
 import javolution.util.FastMap;
 import javolution.util.FastSet;
@@ -193,6 +196,34 @@
         if (col != null) result.addAll(col);
         return result;
     }
+    
+    /**
+     * This change a Map to be Serializable by removing all entries with values that are not Serializable.  
+     *
+     * @param <K>
+     * @param <V>
+     * @param map
+     * @return
+     */
+    public static <K, V> void makeMapSerializable(Map<K, V> map) {
+        // now filter out all non-serializable values
+        Set<K> keysToRemove = FastSet.newInstance();
+        for (Map.Entry<K, V> mapEntry: map.entrySet()) {
+            Object entryValue = mapEntry.getValue();
+            if (entryValue != null && !(entryValue instanceof Serializable)) {
+                keysToRemove.add(mapEntry.getKey());
+                //Debug.logInfo("Found Map value that is not Serializable: " + mapEntry.getKey() + "=" + mapEntry.getValue(), module);
+            }
+            // this is very admittedly a hack, but this object seems to implement Serializable and may not really be, without this keep getting the error: "java.io.NotSerializableException: org.apache.catalina.core.ApplicationContextFacade"
+            if (entryValue != null && !(entryValue instanceof ServletContext)) {
+                keysToRemove.add(mapEntry.getKey());
+            }            
+        }
+        for (K keyToRemove: keysToRemove) { map.remove(keyToRemove); }
+        //if (!(map instanceof Serializable)) {
+        //    Debug.logInfo("Parameter Map is not Serializable!", module);
+        //}
+    }
 
     /**
      * Sort a List of Maps by specified consistent keys.

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java?rev=749970&r1=749969&r2=749970&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java Wed Mar  4 11:49:27 2009
@@ -28,6 +28,7 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
@@ -35,6 +36,7 @@
 import javax.servlet.http.HttpSession;
 
 import javolution.util.FastMap;
+import javolution.util.FastSet;
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.SSLUtil;
@@ -453,7 +455,7 @@
         // if the request has the save-last-view attribute set, save it now before the view can be rendered or other chain done so that the _LAST* session attributes will represent the previous request
         if (nextRequestResponse.saveLastView) {
             session.setAttribute("_SAVED_VIEW_NAME_", session.getAttribute("_LAST_VIEW_NAME_"));
-            session.setAttribute("_SAVED_VIEW_URL_PARAMS_", session.getAttribute("_LAST_VIEW_URL_PARAMS_"));
+            session.setAttribute("_SAVED_VIEW_PARAMS_", session.getAttribute("_LAST_VIEW_PARAMS_"));
         }
         
         if (nextRequestResponse != null && "request".equals(nextRequestResponse.type)) {
@@ -505,10 +507,10 @@
                 Map<String, Object> urlParams = null;
                 if (session.getAttribute("_SAVED_VIEW_NAME_") != null) {
                     viewName = (String) session.getAttribute("_SAVED_VIEW_NAME_");
-                    urlParams = (Map<String, Object>) session.getAttribute("_SAVED_VIEW_URL_PARAMS_");
+                    urlParams = (Map<String, Object>) session.getAttribute("_SAVED_VIEW_PARAMS_");
                 } else if (session.getAttribute("_LAST_VIEW_NAME_") != null) {
                     viewName = (String) session.getAttribute("_LAST_VIEW_NAME_");
-                    urlParams = (Map<String, Object>) session.getAttribute("_LAST_VIEW_URL_PARAMS_");
+                    urlParams = (Map<String, Object>) session.getAttribute("_LAST_VIEW_PARAMS_");
                 }
                 if (urlParams != null) {
                     for (Map.Entry<String, Object> urlParamEntry: urlParams.entrySet()) {
@@ -645,10 +647,13 @@
         // before mapping the view, set a request attribute so we know where we are
         req.setAttribute("_CURRENT_VIEW_", view);
         
-        // save the view in the session for the last view, plus the URL parameters Map; note that this is saved after the request/view processing has finished so when those run they will get the value from the previous request
-        Map<String, Object> queryStringParamMap = UtilHttp.getQueryStringOnlyParameterMap(req);
+        // save the view in the session for the last view, plus the parameters Map (can use all parameters as they will never go into a URL, will only stay in the session and extra data will be ignored as we won't go to the original request just the view); note that this is saved after the request/view processing has finished so when those run they will get the value from the previous request
+        Map<String, Object> paramMap = UtilHttp.getParameterMap(req);
+        // add in the attributes as well so everything needed for the rendering context will be in place if/when we get back to this view
+        paramMap.putAll(UtilHttp.getAttributeMap(req));
+        UtilMisc.makeMapSerializable(paramMap);
         req.getSession().setAttribute("_LAST_VIEW_NAME_", view);
-        req.getSession().setAttribute("_LAST_VIEW_URL_PARAMS_", queryStringParamMap);
+        req.getSession().setAttribute("_LAST_VIEW_PARAMS_", paramMap);
 
         ConfigXMLReader.ViewMap viewMap = (view == null ? null : getControllerConfig().viewMapMap.get(view));
         if (viewMap == null) {