You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by eh...@apache.org on 2015/05/18 17:51:45 UTC

svn commit: r1680047 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/java/org/apache/solr/util/SimplePostTool.java core/src/test/org/apache/solr/util/SimplePostToolTest.java

Author: ehatcher
Date: Mon May 18 15:51:44 2015
New Revision: 1680047

URL: http://svn.apache.org/r1680047
Log:
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

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SimplePostTool.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1680047&r1=1680046&r2=1680047&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Mon May 18 15:51:44 2015
@@ -195,6 +195,9 @@ New Features
   Example:  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
 ----------------------

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SimplePostTool.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SimplePostTool.java?rev=1680047&r1=1680046&r2=1680047&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SimplePostTool.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SimplePostTool.java Mon May 18 15:51:44 2015
@@ -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";
   }
 
   /**

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java?rev=1680047&r1=1680046&r2=1680047&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java Mon May 18 15:51:44 2015
@@ -145,7 +145,7 @@ public class SimplePostToolTest extends
     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