mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-11-09 15:36:40 +00:00
[HER-1687] H3 web UI: adding non-existent job directory gives unhelpful NPE
* Engine.java
return 'false' rather than NPE when given directory non-existent/contains no .cxml
* EngineResource.java
better handle empty 'add' path; show NACK flash when 'add' has no effect
This commit is contained in:
1 parent
4a0f809c0d
commit
58513a8940
2 files changed
+21
-3
No files matched your search
@@ -88,10 +88,15 @@ public class Engine {
|
||||
}
|
||||
|
||||
public boolean considerAsJobDirectory(File dir) {
|
||||
for (File cxml : dir.listFiles(new FilenameFilter() {
|
||||
File[] candidateConfigs = dir.listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".cxml");
|
||||
}})) {
|
||||
}});
|
||||
if(candidateConfigs==null) {
|
||||
// directory did not exist or did not contain cxml
|
||||
return false;
|
||||
}
|
||||
for (File cxml : candidateConfigs) {
|
||||
try {
|
||||
CrawlJob cj = new CrawlJob(cxml);
|
||||
if(!jobConfigs.containsKey(cj.getShortName())) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.archive.crawler.framework.CrawlJob;
|
||||
import org.archive.crawler.framework.Engine;
|
||||
import org.restlet.Context;
|
||||
@@ -73,7 +74,17 @@ public class EngineResource extends Resource {
|
||||
if("rescan".equals(action)) {
|
||||
getEngine().findJobConfigs();
|
||||
} else if ("add".equals(action)) {
|
||||
getEngine().considerAsJobDirectory(new File(form.getFirstValue("addpath")));
|
||||
String path = form.getFirstValue("addpath");
|
||||
if(path==null) {
|
||||
path = "";
|
||||
}
|
||||
boolean added = false;
|
||||
if(StringUtils.isNotBlank(path)) {
|
||||
added = getEngine().considerAsJobDirectory(new File(path));
|
||||
}
|
||||
if(!added) {
|
||||
Flash.addFlash(getResponse(), "not a valid preexisting job directory: \""+path+"\"", Flash.Kind.NACK);
|
||||
}
|
||||
}
|
||||
// default: redirect to GET self
|
||||
getResponse().redirectSeeOther(getRequest().getOriginalRef());
|
||||
@@ -98,6 +109,8 @@ public class EngineResource extends Resource {
|
||||
pw.println("</head><body>");
|
||||
pw.println("<h1>"+engineTitle+"</h1>");
|
||||
|
||||
Flash.renderFlashesHTML(pw, getRequest());
|
||||
|
||||
pw.println("<b>Memory: </b>");
|
||||
pw.println(engine.heapReport());
|
||||
pw.println("<br/><br/>");
|
||||
|
||||
Reference in new issue
Block a user