diff --git a/src/main/java/org/olat/ims/qti/process/DecompressibleInputStream.java b/src/main/java/org/olat/ims/qti/process/DecompressibleInputStream.java new file mode 100644 index 0000000000000000000000000000000000000000..a45c0988afefe1e1a15cfd9204803ed8bd7c03b5 --- /dev/null +++ b/src/main/java/org/olat/ims/qti/process/DecompressibleInputStream.java @@ -0,0 +1,68 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.ims.qti.process; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InvalidClassException; +import java.io.ObjectInputStream; +import java.io.ObjectStreamClass; + +import org.olat.core.logging.OLog; +import org.olat.core.logging.Tracing; + +/** + * + * http://stackoverflow.com/questions/795470/how-to-deserialize-an-object-persisted-in-a-db-now-when-the-object-has-different + * + * @author jorge, java forums + * + */ +public class DecompressibleInputStream extends ObjectInputStream { + + private static final OLog log = Tracing.createLoggerFor(DecompressibleInputStream.class); + + public DecompressibleInputStream(InputStream in) throws IOException { + super(in); + } + + @Override + protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { + ObjectStreamClass resultClassDescriptor = super.readClassDescriptor(); // initially streams descriptor + Class<?> localClass = Class.forName(resultClassDescriptor.getName()); // the class in the local JVM that this descriptor represents. + if (localClass == null) { + log.error("No local class for " + resultClassDescriptor.getName()); + return resultClassDescriptor; + } + ObjectStreamClass localClassDescriptor = ObjectStreamClass.lookup(localClass); + if (localClassDescriptor != null) { // only if class implements serializable + final long localSUID = localClassDescriptor.getSerialVersionUID(); + final long streamSUID = resultClassDescriptor.getSerialVersionUID(); + if (streamSUID != localSUID) { // check for serialVersionUID mismatch. + final StringBuilder s = new StringBuilder("Overriding serialized class version mismatch: "); + s.append("local serialVersionUID = ").append(localSUID).append(" stream serialVersionUID = ").append(streamSUID); + Exception e = new InvalidClassException(s.toString()); + log.warn(s.toString(), e); + resultClassDescriptor = localClassDescriptor; + } + } + return resultClassDescriptor; + } +} diff --git a/src/main/java/org/olat/ims/qti/process/FilePersister.java b/src/main/java/org/olat/ims/qti/process/FilePersister.java index 38d50860c0a889df826ba269f28f0922d49ef812..399a23e9f0dca687c00b3d84c108ece2cec7ca90 100644 --- a/src/main/java/org/olat/ims/qti/process/FilePersister.java +++ b/src/main/java/org/olat/ims/qti/process/FilePersister.java @@ -156,7 +156,7 @@ public class FilePersister implements Persister { } is = new FileInputStream(new File(fSerialDir, QTI_FILE)); BufferedInputStream bis = new BufferedInputStream(is, 262144); - ObjectInputStream oistream = new ObjectInputStream(bis); + ObjectInputStream oistream = new DecompressibleInputStream(bis); o = oistream.readObject(); oistream.close(); is.close(); @@ -166,6 +166,7 @@ public class FilePersister implements Persister { } } catch (Exception e) { + log.error("", e); try { if (is != null) is.close(); } catch (IOException e1) {