Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Frost2011-10-24 09:35:00 -0400
committerChristopher Frost2011-10-24 09:35:00 -0400
commit875f850f78799efad6bc7a8c11b5b38346a48900 (patch)
tree221e36140cd0c140a7ef94774602ded3e935cd59
parent76712428d42df78cdceb24e028c7f45ffb129319 (diff)
downloadorg.eclipse.virgo.medic-875f850f78799efad6bc7a8c11b5b38346a48900.tar.gz
org.eclipse.virgo.medic-875f850f78799efad6bc7a8c11b5b38346a48900.tar.xz
org.eclipse.virgo.medic-875f850f78799efad6bc7a8c11b5b38346a48900.zip
Adding in null check for when the dump dir doesnt exist
-rw-r--r--org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/FileSystemDumpInspector.java86
-rw-r--r--org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/MedicMBeanExporter.java3
-rw-r--r--org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/management/FileSystemDumpInspectorTests.java23
3 files changed, 75 insertions, 37 deletions
diff --git a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/FileSystemDumpInspector.java b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/FileSystemDumpInspector.java
index 4a933fb..eadcda4 100644
--- a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/FileSystemDumpInspector.java
+++ b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/FileSystemDumpInspector.java
@@ -21,6 +21,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.virgo.medic.dump.DumpGenerator;
+import org.eclipse.virgo.medic.impl.config.ConfigurationProvider;
import org.eclipse.virgo.util.io.FileSystemUtils;;
/**
@@ -32,24 +33,25 @@ import org.eclipse.virgo.util.io.FileSystemUtils;;
public class FileSystemDumpInspector implements DumpInspector {
private final Logger logger = LoggerFactory.getLogger(FileSystemDumpInspector.class);
-
- private final File dumpDirectory;
private final DumpGenerator generator;
+
+ private final ConfigurationProvider configurationProvider;
/**
*
*
*/
- public FileSystemDumpInspector(DumpGenerator generator, String dumpDir) {
+ public FileSystemDumpInspector(DumpGenerator generator, ConfigurationProvider configurationProvider) {
this.generator = generator;
- this.dumpDirectory = new File(dumpDir);
+ this.configurationProvider = configurationProvider;
}
@Override
public String[] getDumps() throws IOException {
- if(this.dumpDirectory.exists() && this.dumpDirectory.isDirectory()){
- return FileSystemUtils.list(this.dumpDirectory, this.logger);
+ File dumpDir = getDumpDirectory();
+ if(dumpDir != null && dumpDir.exists() && dumpDir.isDirectory()){
+ return FileSystemUtils.list(dumpDir, this.logger);
} else {
return new String[0];
}
@@ -57,14 +59,15 @@ public class FileSystemDumpInspector implements DumpInspector {
@Override
public String[] getDumpEntries(String dumpId) throws IOException {
- File dumpDir = new File(this.dumpDirectory, dumpId);
- String[] items;
- if(dumpDir.exists() && dumpDir.isDirectory()){
- items = FileSystemUtils.list(dumpDir, this.logger);
+ if(dumpId == null){
+ return new String[0];
+ }
+ File dumpDir = new File(getDumpDirectory(), dumpId);
+ if(dumpDir != null && dumpDir.exists() && dumpDir.isDirectory()){
+ return FileSystemUtils.list(dumpDir, this.logger);
} else {
- items = new String[0];
+ return new String[0];
}
- return items;
}
@Override
@@ -73,28 +76,31 @@ public class FileSystemDumpInspector implements DumpInspector {
return new String[0];
}
List<String> lines = new ArrayList<String>();
- File dumpEntry = new File(this.dumpDirectory, dumpId + File.separatorChar + entryName);
- if(dumpEntry != null){
- LineNumberReader reader = null;
- try {
- reader = new LineNumberReader(new FileReader(dumpEntry));
- while (reader.ready()){
- String rawLine = reader.readLine();
- if(rawLine != null){
- lines.add(this.escapeAngleBrackets(rawLine));
- }
- }
- reader.close();
- } catch (IOException e) {
- logger.error("Error while reading dump file " + dumpEntry.getPath(), e);
+ File dumpDir = getDumpDirectory();
+ if(dumpDir != null && dumpDir.exists() && dumpDir.isDirectory()){
+ File dumpEntry = new File(dumpDir, dumpId + File.separatorChar + entryName);
+ if(dumpEntry != null){
+ LineNumberReader reader = null;
try {
- if(reader != null){
- reader.close();
+ reader = new LineNumberReader(new FileReader(dumpEntry));
+ while (reader.ready()){
+ String rawLine = reader.readLine();
+ if(rawLine != null){
+ lines.add(this.escapeAngleBrackets(rawLine));
+ }
}
- } catch (IOException e1) {
- // no-op to close stream
+ reader.close();
+ } catch (IOException e) {
+ logger.error("Error while reading dump file " + dumpEntry.getPath(), e);
+ try {
+ if(reader != null){
+ reader.close();
+ }
+ } catch (IOException e1) {
+ // no-op to close stream
+ }
+ // no-op just return the default null value and let the js deal with it
}
- // no-op just return the default null value and let the js deal with it
}
}
return lines.toArray(new String[lines.size()]);
@@ -107,12 +113,24 @@ public class FileSystemDumpInspector implements DumpInspector {
@Override
public void delete(String dumpId) {
- File root = new File(this.dumpDirectory, dumpId);
- if(root.exists() && root.isDirectory()){
- FileSystemUtils.deleteRecursively(root);
+ File dumpDir = getDumpDirectory();
+ if(dumpDir.exists() && dumpDir.isDirectory()){
+ File root = new File(dumpDir, dumpId);
+ if(root.exists() && root.isDirectory()){
+ FileSystemUtils.deleteRecursively(root);
+ }
}
}
+ private File getDumpDirectory(){
+ String dumpDirectory = configurationProvider.getConfiguration().get(ConfigurationProvider.KEY_DUMP_ROOT_DIRECTORY);
+ File dumpDir = new File(dumpDirectory);
+ if(dumpDir.exists() && dumpDir.isDirectory()){
+ return dumpDir;
+ }
+ return null;
+ }
+
private String escapeAngleBrackets(String unfriendlyMarkup) {
String processed = unfriendlyMarkup.replace("<", "&#60;");
processed = processed.replace(">", "&#62;");
diff --git a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/MedicMBeanExporter.java b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/MedicMBeanExporter.java
index 609c86d..98f2c20 100644
--- a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/MedicMBeanExporter.java
+++ b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/management/MedicMBeanExporter.java
@@ -45,8 +45,7 @@ public class MedicMBeanExporter {
public MedicMBeanExporter(ConfigurationProvider configurationProvider, DumpGenerator dumpGenerator) {
try {
ObjectName dumpMBeanName = new ObjectName(String.format("%s:type=Medic,name=DumpInspector", DOMAIN));
- String dumpDirectory = configurationProvider.getConfiguration().get(ConfigurationProvider.KEY_DUMP_ROOT_DIRECTORY);
- registeredMBean = this.server.registerMBean(new FileSystemDumpInspector(dumpGenerator, dumpDirectory), dumpMBeanName);
+ registeredMBean = this.server.registerMBean(new FileSystemDumpInspector(dumpGenerator, configurationProvider), dumpMBeanName);
} catch (Exception e) {
logger.error("Unable to register the DumpInspectorMBean", e);
}
diff --git a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/management/FileSystemDumpInspectorTests.java b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/management/FileSystemDumpInspectorTests.java
index b17978e..8a6a5db 100644
--- a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/management/FileSystemDumpInspectorTests.java
+++ b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/management/FileSystemDumpInspectorTests.java
@@ -10,8 +10,12 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
import org.eclipse.virgo.medic.dump.DumpGenerator;
+import org.eclipse.virgo.medic.impl.config.ConfigurationChangeListener;
+import org.eclipse.virgo.medic.impl.config.ConfigurationProvider;
import org.junit.Before;
import org.junit.Test;
@@ -24,7 +28,24 @@ public class FileSystemDumpInspectorTests {
@Before
public void setup() {
this.dumpGenerator = createMock(DumpGenerator.class);
- this.fileSystemDumpInspector = new FileSystemDumpInspector(dumpGenerator, "src/test/resources/testDumps/serviceability/dump");
+ this.fileSystemDumpInspector = new FileSystemDumpInspector(dumpGenerator, new ConfigurationProvider() {
+
+ @Override
+ public boolean removeChangeListener(ConfigurationChangeListener listener) {
+ return false;
+ }
+
+ @Override
+ public Dictionary<String, String> getConfiguration() {
+ Dictionary<String, String> props = new Hashtable<String, String>();
+ props.put(KEY_DUMP_ROOT_DIRECTORY, "src/test/resources/testDumps/serviceability/dump");
+ return props;
+ }
+
+ @Override
+ public void addChangeListener(ConfigurationChangeListener listener) {
+ }
+ });
}
@Test

Back to the top