diff options
author | Carsten Lund <lund@research.att.com> | 2017-05-02 02:05:12 +0000 |
---|---|---|
committer | Carsten Lund <lund@research.att.com> | 2017-05-02 02:05:12 +0000 |
commit | 03f9567726dfa0c6af315d88c316be9cb380d8ae (patch) | |
tree | f3602aeb53078b955ccb4a4f06220a0cc753e228 /ncomp-utils-journaling | |
parent | f096d31080e5a62120d6536681a0859d2202c717 (diff) |
[DCAE-15] Changes related to version 1.1 (2)
Change-Id: I3537af308ff9c7d6faebad4b5faee53890d03c9e
Signed-off-by: Carsten Lund <lund@research.att.com>
Diffstat (limited to 'ncomp-utils-journaling')
3 files changed, 30 insertions, 7 deletions
diff --git a/ncomp-utils-journaling/pom.xml b/ncomp-utils-journaling/pom.xml index 9832a1d..9741775 100644 --- a/ncomp-utils-journaling/pom.xml +++ b/ncomp-utils-journaling/pom.xml @@ -87,6 +87,13 @@ <version>1.9</version> </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.5</version> + </dependency> + + <dependency> <groupId>commons-cli</groupId> <artifactId>commons-cli</artifactId> diff --git a/ncomp-utils-journaling/src/main/java/org/openecomp/ncomp/utils/journaling/JournalingObject.java b/ncomp-utils-journaling/src/main/java/org/openecomp/ncomp/utils/journaling/JournalingObject.java index d294aa7..0be2649 100644 --- a/ncomp-utils-journaling/src/main/java/org/openecomp/ncomp/utils/journaling/JournalingObject.java +++ b/ncomp-utils-journaling/src/main/java/org/openecomp/ncomp/utils/journaling/JournalingObject.java @@ -28,7 +28,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.StreamCorruptedException; import java.lang.reflect.Field; @@ -44,6 +43,7 @@ import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; +import org.apache.commons.io.serialization.ValidatingObjectInputStream; import org.apache.log4j.Logger; import org.json.JSONObject; @@ -63,9 +63,13 @@ public abstract class JournalingObject { private int snapShotInterval = 30 * 60000; // every 30 minutes private Date lastSnapShot = new Date(); private int numLogs = 0; + static private List<String> whiteList = new ArrayList<String>(); static { startCleanupThread(); + whiteList.add("org.openecomp.ncomp.utils.journaling.*"); + whiteList.add("java.util.*"); + whiteList.add("java.lang.*"); } public JournalingObject(String context, JournalingObject parent) { @@ -254,7 +258,8 @@ public abstract class JournalingObject { try { logger.debug("reading" + file); BufferedInputStream fin = new BufferedInputStream(new FileInputStream(file),16777216); - ObjectInputStream in = new ObjectInputStream(fin); + ValidatingObjectInputStream in = new ValidatingObjectInputStream(fin); + addAccept(in); Object o = null; try { o = in.readObject(); @@ -281,7 +286,7 @@ public abstract class JournalingObject { return numLogs; } - @SuppressWarnings("static-access") + @SuppressWarnings({ "static-access", "deprecation" }) public static void main(String[] args) throws IOException, ClassNotFoundException { CommandLineParser parser = new GnuParser(); @@ -303,7 +308,8 @@ public abstract class JournalingObject { // String args1[] = line.getArgs(); if (line.hasOption("file")) { FileInputStream fin = new FileInputStream(new File(line.getOptionValue("file"))); - ObjectInputStream in = new ObjectInputStream(fin); + ValidatingObjectInputStream in = new ValidatingObjectInputStream(fin); + addAccept(in); try { while (true) { Object o; @@ -325,6 +331,15 @@ public abstract class JournalingObject { } } + private static void addAccept(ValidatingObjectInputStream in) { + for (String s : whiteList) { + in.accept(s); + } + } + public static void addClassToWhiteList(String s) { + whiteList.add(s); + } + static int num = 0; static private File saveObjectFile(File dir, String fname) { @@ -363,7 +378,8 @@ public abstract class JournalingObject { Object o = null; try { FileInputStream fin = new FileInputStream(file); - ObjectInputStream in = new ObjectInputStream(fin); + ValidatingObjectInputStream in = new ValidatingObjectInputStream(fin); + addAccept(in); try { while (true) { try { @@ -393,7 +409,7 @@ public abstract class JournalingObject { } catch (EOFException e) { logger.debug("initFromLog failed: " + file + " numEvents=" + numEvents + " o=" + o); } catch (Exception e) { - logger.warn("initFromLog failed: " + file + " numEvents=" + numEvents + " o=" + o.getClass()); + System.err.println(e); logger.debug("initFromLog failed: " + file + " numEvents=" + numEvents + " o=" + o); e.printStackTrace(); } diff --git a/ncomp-utils-journaling/src/main/java/org/openecomp/ncomp/utils/journaling/JournalingTest.java b/ncomp-utils-journaling/src/main/java/org/openecomp/ncomp/utils/journaling/JournalingTest.java index a1e7517..dba03ab 100644 --- a/ncomp-utils-journaling/src/main/java/org/openecomp/ncomp/utils/journaling/JournalingTest.java +++ b/ncomp-utils-journaling/src/main/java/org/openecomp/ncomp/utils/journaling/JournalingTest.java @@ -153,7 +153,7 @@ public class JournalingTest extends TestCase { for (int i = 0; i < 10; i++) { o.setS("foo:" + i); } - assertTrue(o.getLogSize() <= 2); + assertTrue(o.getLogSize() == 12); o.close(); for (int i = 0; i < 3; i++) { |