fix #10075 fix deserialization by overriding PreferredLoaderObjectInputStream from...
authorAndreas Müller <a.mueller@bgbm.org>
Thu, 16 Jun 2022 19:47:24 +0000 (21:47 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Thu, 16 Jun 2022 19:47:24 +0000 (21:47 +0200)
eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/RemoteInvocationTermCacher.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/net/sf/ehcache/util/PreferredLoaderObjectInputStream.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/springframework/remoting/httpinvoker/CachingHttpInvokerProxyFactoryBean.java

index 62e292adb5d7b6a619a21160f93720020b751fb2..d61b09580409758e5990f6bb4f328de31c2e3f6a 100644 (file)
@@ -186,6 +186,7 @@ Export-Package: com.sun.istack.internal.tools,
  net.sf.ehcache.config,
  net.sf.ehcache.statistics,
  net.sf.ehcache.store,
+ net.sf.ehcache.util,
  net.sf.json;uses:="net.sf.json.processors,net.sf.json.util,org.apache.commons.lang.exception",
  org.aopalliance.aop,
  org.apache.commons.collections;uses:="org.apache.commons.collections.keyvalue,new org.apache.commons.collections",
index e6a9b4cec515351f25514a3812760a6b056e7690..d350bcd7e3376a779d740d56e1e007688c3db871 100644 (file)
@@ -23,6 +23,10 @@ import eu.etaxonomy.cdm.model.term.DefinedTermBase;
 import eu.etaxonomy.cdm.model.term.TermType;
 
 
+/**
+ * Note by AM (2022-06-15): This caches terms. But it seems that only the method
+ * "listByTermType" from term service is cached.
+ */
 public class RemoteInvocationTermCacher implements IRemoteInvocationTermCacher {
 
     private static final Logger logger = LogManager.getLogger(RemoteInvocationTermCacher.class);
diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/net/sf/ehcache/util/PreferredLoaderObjectInputStream.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/net/sf/ehcache/util/PreferredLoaderObjectInputStream.java
new file mode 100644 (file)
index 0000000..4263627
--- /dev/null
@@ -0,0 +1,87 @@
+/**
+ *  Copyright Terracotta, Inc.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package net.sf.ehcache.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.util.HashMap;
+
+/**
+ * Note by AM (2022-06-15): this is an exact copy of the same class in ehcache (v2.x)
+ *     but with correct handling for primitive types.
+ *     This class should be removed when upgrading to ehcache 3.x as it seems not to exist in
+ *     this version anymore.
+ *
+ *     For further information see #10075 and #10077
+ *
+ * =========================================
+ * Original javadoc:
+ *
+ * ObjectInputStream that uses a supplied classloader when resolving classes
+ *
+ * @author teck
+ */
+public class PreferredLoaderObjectInputStream extends ObjectInputStream {
+
+    private final ClassLoader loader;
+
+    /**
+     * Constructor
+     *
+     * @param in
+     * @throws IOException
+     */
+    public PreferredLoaderObjectInputStream(InputStream in, ClassLoader loader) throws IOException {
+        super(in);
+        this.loader = loader;
+    }
+
+// ************** REPLACED METHOD ********************************/
+
+    @Override
+    protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+
+        try {
+            return Class.forName(desc.getName(), false, loader);
+        } catch (ClassNotFoundException ex) {
+            Class<?> cl = primClasses.get(desc.getName());
+            if (cl != null) {
+                return cl;
+            } else {
+                throw ex;
+            }
+        }
+    }
+    //copied from
+    /** table mapping primitive type names to corresponding class objects */
+    private static final HashMap<String, Class<?>> primClasses
+        = new HashMap<>(8, 1.0F);
+    static {
+        primClasses.put("boolean", boolean.class);
+        primClasses.put("byte", byte.class);
+        primClasses.put("char", char.class);
+        primClasses.put("short", short.class);
+        primClasses.put("int", int.class);
+        primClasses.put("long", long.class);
+        primClasses.put("float", float.class);
+        primClasses.put("double", double.class);
+        primClasses.put("void", void.class);
+    }
+
+}
index 93c680150ab5fb65d5d6f7b0c5a4ca46a254c2d1..07b2cf26dd9c43252431fe35cfdc64eefe60b320 100644 (file)
@@ -89,6 +89,7 @@ public class CachingHttpInvokerProxyFactoryBean extends HttpInvokerProxyFactoryB
         RemoteInvocationResult invocationResult = doExecuteRequest(invocation, originalInvocation);
         if(invocationResult.getValue() != null && !invocationResult.hasException()) {
 
+            //Note AM (2022-06-15): the debug information seem to be misleading (also because cache() is not used/implemented anymore)
             if(persistingMethods.contains(invocation.getMethodName())) {
                 invocationResult = new RemoteInvocationResult(cdmEntitySessionManager().load(invocationResult.getValue(), true));
                 logger.debug("Entity cached with updating cached data");