svn commit: r1868298 - /ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/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: r1868298 - /ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java

jleroux@apache.org
Author: jleroux
Date: Fri Oct 11 16:45:16 2019
New Revision: 1868298

URL: http://svn.apache.org/viewvc?rev=1868298&view=rev
Log:
Fixed: NotSerializableException after uploading images to an order
(OFBIZ-11123)

I found that using in r1866259 the same fix than Si Chen used in OFBIZ-750 was
wrong. The code just above this fix is

{code:java}
if (obj instanceof Serializable) {
    reqAttrMap.put(name, obj);
}
{code}

The problem with this code is that if does not handle inner Maps which may
contain a non Serializable Object. So the solution is rather to get one level
deeper and apply the same. We can then remove the harcoded lines with
"uploadedFile" and "_REQUEST_HANDLER_" below. Then all possible cases are handled
as long as we have not inner-inner-Maps



Modified:
    ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java

Modified: ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java?rev=1868298&r1=1868297&r2=1868298&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java Fri Oct 11 16:45:16 2019
@@ -870,12 +870,14 @@ public class RequestHandler {
             String name = attributeNameEnum.nextElement();
             Object obj = req.getAttribute(name);
             if (obj instanceof Serializable) {
+                if (obj instanceof Map) {
+                    // See OFBIZ-750 and OFBIZ-11123 for cases where a value in an inner Map is not serializable
+                    UtilMisc.makeMapSerializable(UtilGenerics.cast(obj));
+                }
                 reqAttrMap.put(name, obj);
             }
         }
         if (reqAttrMap.size() > 0) {
-            reqAttrMap.remove("_REQUEST_HANDLER_");  // RequestHandler is not serializable and must be removed first.  See http://issues.apache.org/jira/browse/OFBIZ-750
-            reqAttrMap.remove("uploadedFile");  // uploadedFileis not serializable (it's a HeapByteBuffer) and must be removed first.  See http://issues.apache.org/jira/browse/OFBIZ-11123
             byte[] reqAttrMapBytes = UtilObject.getBytes(reqAttrMap);
             if (reqAttrMapBytes != null) {
                 req.getSession().setAttribute("_REQ_ATTR_MAP_", StringUtil.toHexString(reqAttrMapBytes));