Apache Lucene open-source search software
SOLR-7546: bin/post (and SimplePostTool in -Dauto=yes mode) now sends rather than skips files without a known content type, as application/octet-stream, provided it still is in the allowed filetypes setting
Erik Hatcher64274166b856
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex fa56919f2b3..eb34e60a0d4 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -195,6 +195,9 @@ New FeaturesExample: json.facet={ numProducts : "hll(product_id)" }(yonik)+* SOLR-7546: bin/post (and SimplePostTool in -Dauto=yes mode) now sends rather than skips files+ without a known content type, as "application/octet-stream", provided it still is in the+ allowed filetypes setting. (ehatcher)Bug Fixes----------------------diff --git a/solr/core/src/java/org/apache/solr/util/SimplePostTool.java b/solr/core/src/java/org/apache/solr/util/SimplePostTool.javaindex 73c5e7ea04c..2e79e071d1a 100644--- a/solr/core/src/java/org/apache/solr/util/SimplePostTool.java+++ b/solr/core/src/java/org/apache/solr/util/SimplePostTool.java@@ -360,8 +360,6 @@ public class SimplePostTool {}private void reset() {- fileTypes = DEFAULT_FILE_TYPES;- globFileFilter = this.getFileFilterFromFileTypes(fileTypes);backlog = new ArrayList<>();visited = new HashSet<>();}@@ -774,22 +772,19 @@ public class SimplePostTool {if(type == null) {type = guessType(file);}- if(type != null) {- if(type.equals("application/xml") || type.equals("text/csv") || type.equals("application/json")) {- // Default handler- } else {- // SolrCell- suffix = "/extract";- String urlStr = appendUrlPath(solrUrl, suffix).toString();- if(urlStr.indexOf("resource.name")==-1)- urlStr = appendParam(urlStr, "resource.name=" + URLEncoder.encode(file.getAbsolutePath(), "UTF-8"));- if(urlStr.indexOf("literal.id")==-1)- urlStr = appendParam(urlStr, "literal.id=" + URLEncoder.encode(file.getAbsolutePath(), "UTF-8"));- url = new URL(urlStr);- }+ // TODO: Add a flag that disables /update and sends all to /update/extract, to avoid CSV, JSON, and XML files+ // TODO: from being interpreted as Solr documents internally+ if(type.equals("application/xml") || type.equals("text/csv") || type.equals("application/json")) {+ // Default handler} else {- warn("Skipping "+file.getName()+". Unsupported file type for auto mode.");- return;+ // SolrCell+ suffix = "/extract";+ String urlStr = appendUrlPath(solrUrl, suffix).toString();+ if(urlStr.indexOf("resource.name")==-1)+ urlStr = appendParam(urlStr, "resource.name=" + URLEncoder.encode(file.getAbsolutePath(), "UTF-8"));+ if(urlStr.indexOf("literal.id")==-1)+ urlStr = appendParam(urlStr, "literal.id=" + URLEncoder.encode(file.getAbsolutePath(), "UTF-8"));+ url = new URL(urlStr);}} else {if(type == null) type = DEFAULT_CONTENT_TYPE;@@ -821,13 +816,15 @@ public class SimplePostTool {/*** Guesses the type of a file, based on file name suffix+ * Returns "application/octet-stream" if no corresponding mimeMap type.* @param file the file* @return the content-type guessed*/protected static String guessType(File file) {String name = file.getName();String suffix = name.substring(name.lastIndexOf(".")+1);- return mimeMap.get(suffix.toLowerCase(Locale.ROOT));+ String type = mimeMap.get(suffix.toLowerCase(Locale.ROOT));+ return (type != null) ? type : "application/octet-stream";}/**diff --git a/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java b/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.javaindex 68e537ec4ad..9ecfa2eaf0e 100644--- a/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java+++ b/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java@@ -145,7 +145,7 @@ public class SimplePostToolTest extends SolrTestCaseJ4 {File f = new File("foo.doc");assertEquals("application/msword", SimplePostTool.guessType(f));f = new File("foobar");- assertEquals(null, SimplePostTool.guessType(f));+ assertEquals("application/octet-stream", SimplePostTool.guessType(f));}@Test