This is an automated email from the ASF dual-hosted git repository.
jleroux pushed a commit to branch release17.12
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/release17.12 by this push:
new 6dc2669 Fixed: NotSerializableException using uploadPartyContentFile
service (OFBIZ-12050)
6dc2669 is described below
commit 6dc266996e177c5467152245289918a893be9309
Author: Jacques Le Roux <[email protected]>
AuthorDate: Fri Nov 6 10:59:58 2020 +0100
Fixed: NotSerializableException using uploadPartyContentFile service
(OFBIZ-12050)
This error appears after trying to upload a file to party content:
2020-11-06 07:48:22,488 |jsse-nio-8443-exec-7 |RequestHandler
|I|
Sending redirect to:
[https://localhost:8443/partymgr/control/viewprofile?partyId=admin].
2020-11-06 07:48:29,288 |jsse-nio-8443-exec-7 |UtilObject
|E|
null
java.io.NotSerializableException:
org.apache.commons.fileupload.disk.DiskFileItem
# Conflicts handled by hand
# framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
#
framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
---
.../main/java/org/apache/ofbiz/base/util/UtilMisc.java | 16 +++++++++++++++-
.../org/apache/ofbiz/webapp/control/RequestHandler.java | 17 ++++++++++++-----
2 files changed, 27 insertions(+), 6 deletions(-)
diff --git
a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
index 0f0a4f3..a0cb851 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
@@ -180,13 +180,27 @@ public final class UtilMisc {
if (Debug.verboseOn()) {
Debug.logVerbose("Found Map value that is not
Serializable: " + mapEntry.getKey() + "=" + mapEntry.getValue(), module);
}
-
}
}
for (String keyToRemove: keysToRemove) { map.remove(keyToRemove); }
}
/**
+ * This change an ArrayList to be Serializable by removing all entries
that are not Serializable.
+ * @param arrayList
+ */
+ public static <V> void makeArrayListSerializable(ArrayList<Object>
arrayList) {
+ // now filter out all non-serializable values
+ Iterator itr = arrayList.iterator();
+ while (itr.hasNext()) {
+ Object obj = itr.next();
+ if (!(obj instanceof Serializable)) {
+ itr.remove();
+ }
+ }
+ }
+
+ /**
* Sort a List of Maps by specified consistent keys.
* @param listOfMaps List of Map objects to sort.
* @param sortKeys List of Map keys to sort by.
diff --git
a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
index 556f4cf..d694ff9 100644
---
a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
+++
b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
@@ -25,6 +25,7 @@ import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.cert.X509Certificate;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
@@ -468,7 +469,7 @@ public class RequestHandler {
if (requestMap.event.metrics != null) {
requestMap.event.metrics.recordServiceRate(1,
System.currentTimeMillis() - startTime);
- }
+ }
// save the server hit for the request event
if (this.trackStats(request)) {
@@ -634,7 +635,7 @@ public class RequestHandler {
String responseStatusCode = nextRequestResponse.statusCode;
if(UtilValidate.isNotEmpty(responseStatusCode))
- statusCodeString = responseStatusCode;
+ statusCodeString = responseStatusCode;
if ("url".equals(nextRequestResponse.type)) {
@@ -824,7 +825,7 @@ public class RequestHandler {
statusCode = Integer.valueOf(statusCodeString);
} catch (NumberFormatException e) {
statusCode = 303;
- }
+ }
while (attributeNameEnum.hasMoreElements()) {
String name = attributeNameEnum.nextElement();
Object obj = req.getAttribute(name);
@@ -833,6 +834,12 @@ public class RequestHandler {
// See OFBIZ-750 and OFBIZ-11123 for cases where a value
in an inner Map is not serializable
UtilMisc.makeMapSerializable(UtilGenerics.cast(obj));
}
+ if (obj instanceof ArrayList) {
+ // See OFBIZ-10250 for cases where a value in an ArrayList
is not serializable
+ @SuppressWarnings("unchecked")
+ ArrayList<Object> arrayList = (ArrayList<Object>) obj;
+ UtilMisc.makeArrayListSerializable(arrayList);
+ }
reqAttrMap.put(name, obj);
}
}
@@ -844,7 +851,7 @@ public class RequestHandler {
}
// send the redirect
- try {
+ try {
resp.setStatus(statusCode);
resp.setHeader("Location", url);
resp.setHeader("Connection", "close");
@@ -1263,7 +1270,7 @@ public class RequestHandler {
Delegator delegator = (Delegator) request.getAttribute("delegator");
boolean showSessionIdInLog =
EntityUtilProperties.propertyValueEqualsIgnoreCase("requestHandler",
"show-sessionId-in-log", "Y", delegator);
if (showSessionIdInLog) {
- return " sessionId=" + UtilHttp.getSessionId(request);
+ return " sessionId=" + UtilHttp.getSessionId(request);
}
return " Hidden sessionId by default.";
}