tika-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1225448 - in /tika/trunk: tika-core/src/main/java/org/apache/tika/fork/ForkClient.java tika-core/src/main/java/org/apache/tika/fork/ForkParser.java tika-parsers/src/test/java/org/apache/tika/parser/fork/ForkParserIntegrationTest.java
Date Thu, 29 Dec 2011 06:35:03 GMT
Author: nick
Date: Thu Dec 29 06:35:02 2011
New Revision: 1225448

URL: http://svn.apache.org/viewvc?rev=1225448&view=rev
Log:
TIKA-830 Improved error message in the ForkParser if we are unable to serialize the parse
objects

Modified:
    tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkClient.java
    tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkParser.java
    tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/fork/ForkParserIntegrationTest.java

Modified: tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkClient.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkClient.java?rev=1225448&r1=1225447&r2=1225448&view=diff
==============================================================================
--- tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkClient.java (original)
+++ tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkClient.java Thu Dec 29 06:35:02
2011
@@ -22,6 +22,7 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.NotSerializableException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -29,6 +30,7 @@ import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
 import java.util.zip.ZipEntry;
 
+import org.apache.tika.exception.TikaException;
 import org.apache.tika.io.IOExceptionWithCause;
 import org.apache.tika.io.IOUtils;
 import org.xml.sax.ContentHandler;
@@ -50,7 +52,7 @@ class ForkClient {
     private final InputStream error;
 
     public ForkClient(ClassLoader loader, Object object, String java)
-            throws IOException {
+            throws IOException, TikaException {
         boolean ok = false;
         try {
             this.loader = loader;
@@ -100,7 +102,7 @@ class ForkClient {
 
 
     public synchronized Throwable call(String method, Object... args)
-            throws IOException {
+            throws IOException, TikaException {
         List<ForkResource> r = new ArrayList<ForkResource>(resources);
         output.writeByte(ForkServer.CALL);
         output.writeUTF(method);
@@ -119,7 +121,7 @@ class ForkClient {
      * @throws IOException if the object could not be serialized
      */
     private void sendObject(Object object, List<ForkResource> resources)
-            throws IOException {
+            throws IOException, TikaException {
         int n = resources.size();
         if (object instanceof InputStream) {
             resources.add(new InputStreamResource((InputStream) object));
@@ -132,7 +134,14 @@ class ForkClient {
             object = new ClassLoaderProxy(n);
         }
 
-        ForkObjectInputStream.sendObject(object, output);
+        try {
+           ForkObjectInputStream.sendObject(object, output);
+        } catch(NotSerializableException nse) {
+           // Build a more friendly error message for this
+           throw new TikaException(
+                 "Unable to serialize " + object.getClass().getSimpleName() +
+                 " to pass to the Forked Parser", nse);
+        }
 
         waitForResponse(resources);
     }

Modified: tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkParser.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkParser.java?rev=1225448&r1=1225447&r2=1225448&view=diff
==============================================================================
--- tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkParser.java (original)
+++ tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkParser.java Thu Dec 29 06:35:02
2011
@@ -130,7 +130,12 @@ public class ForkParser extends Abstract
         try {
             t = client.call("parse", stream, handler, metadata, context);
             alive = true;
+        } catch (TikaException te) {
+            // Problem occurred on our side
+            alive = true;
+            throw te;
         } catch (IOException e) {
+            // Problem occurred on the other side
             throw new TikaException(
                     "Failed to communicate with a forked parser process."
                     + " The process has most likely crashed due to some error"

Modified: tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/fork/ForkParserIntegrationTest.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/fork/ForkParserIntegrationTest.java?rev=1225448&r1=1225447&r2=1225448&view=diff
==============================================================================
--- tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/fork/ForkParserIntegrationTest.java
(original)
+++ tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/fork/ForkParserIntegrationTest.java
Thu Dec 29 06:35:02 2011
@@ -18,6 +18,7 @@ package org.apache.tika.parser.fork;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.NotSerializableException;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
@@ -26,6 +27,7 @@ import junit.framework.TestCase;
 
 import org.apache.tika.Tika;
 import org.apache.tika.config.TikaConfig;
+import org.apache.tika.detect.Detector;
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.fork.ForkParser;
 import org.apache.tika.metadata.Metadata;
@@ -127,6 +129,38 @@ public class ForkParserIntegrationTest e
             assertEquals(brokenParser.e, e.getCause());
         }
     }
+    
+    /**
+     * If we supply a non serializable object on the ParseContext,
+     *  check we get a helpful exception back
+     */
+    public void testParserHandlingOfNonSerializable() throws Exception {
+       ForkParser parser = new ForkParser(
+             ForkParserIntegrationTest.class.getClassLoader(),
+             tika.getParser());
+       
+       ParseContext context = new ParseContext();
+       context.set(Detector.class, new Detector() {
+          public MediaType detect(InputStream input, Metadata metadata) {
+             return MediaType.OCTET_STREAM;
+          }
+       });
+
+       try {
+          ContentHandler output = new BodyContentHandler();
+          InputStream stream = ForkParserIntegrationTest.class.getResourceAsStream(
+              "/test-documents/testTXT.txt");
+          parser.parse(stream, output, new Metadata(), context);
+          fail("Should have blown up with a non serializable ParseContext");
+       } catch(TikaException e) {
+          // Check the right details
+          assertNotNull(e.getCause());
+          assertEquals(NotSerializableException.class, e.getCause().getClass());
+          assertEquals("Unable to serialize ParseContext to pass to the Forked Parser", e.getMessage());
+       } finally {
+          parser.close();
+       }
+    }
 
     /**
      * TIKA-808 - Ensure that parsing of our test PDFs work under



Mime
View raw message