You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2024/05/24 10:27:13 UTC

(tika) branch TIKA-4260 created (now 7ad12958c)

This is an automated email from the ASF dual-hosted git repository.

tallison pushed a change to branch TIKA-4260
in repository https://gitbox.apache.org/repos/asf/tika.git


      at 7ad12958c TIKA-4260 -- add parseContext to fetcher WIP -- do not merge

This branch includes the following new commits:

     new 7ad12958c TIKA-4260 -- add parseContext to fetcher WIP -- do not merge

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(tika) 01/01: TIKA-4260 -- add parseContext to fetcher WIP -- do not merge

Posted by ta...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tallison pushed a commit to branch TIKA-4260
in repository https://gitbox.apache.org/repos/asf/tika.git

commit 7ad12958c554bade91aa2e566e127185ab7eec04
Author: tallison <ta...@apache.org>
AuthorDate: Fri May 24 06:26:56 2024 -0400

    TIKA-4260 -- add parseContext to fetcher WIP -- do not merge
---
 .../java/org/apache/tika/pipes/FetchEmitTuple.java | 91 +++++++---------------
 .../java/org/apache/tika/pipes/PipesServer.java    | 47 ++++++-----
 .../apache/tika/pipes/fetcher/EmptyFetcher.java    |  3 +-
 .../org/apache/tika/pipes/fetcher/Fetcher.java     |  3 +-
 .../apache/tika/pipes/fetcher/RangeFetcher.java    |  3 +-
 .../tika/pipes/fetcher/fs/FileSystemFetcher.java   |  5 +-
 .../apache/tika/pipes/fetcher/url/UrlFetcher.java  |  3 +-
 .../filelist/FileListPipesIterator.java            |  6 +-
 .../pipesiterator/fs/FileSystemPipesIterator.java  |  6 +-
 .../org/apache/tika/pipes/PipesServerTest.java     | 18 +++--
 .../org/apache/tika/pipes/async/MockFetcher.java   |  3 +-
 .../org/apache/tika/pipes/fetcher/MockFetcher.java |  3 +-
 12 files changed, 91 insertions(+), 100 deletions(-)

diff --git a/tika-core/src/main/java/org/apache/tika/pipes/FetchEmitTuple.java b/tika-core/src/main/java/org/apache/tika/pipes/FetchEmitTuple.java
index 0c0334fd4..a0f40901b 100644
--- a/tika-core/src/main/java/org/apache/tika/pipes/FetchEmitTuple.java
+++ b/tika-core/src/main/java/org/apache/tika/pipes/FetchEmitTuple.java
@@ -20,6 +20,7 @@ import java.io.Serializable;
 import java.util.Objects;
 
 import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.ParseContext;
 import org.apache.tika.pipes.emitter.EmitKey;
 import org.apache.tika.pipes.extractor.EmbeddedDocumentBytesConfig;
 import org.apache.tika.pipes.fetcher.FetchKey;
@@ -36,41 +37,30 @@ public class FetchEmitTuple implements Serializable {
     private final FetchKey fetchKey;
     private EmitKey emitKey;
     private final Metadata metadata;
+    private final ParseContext parseContext;
     private final ON_PARSE_EXCEPTION onParseException;
-    private HandlerConfig handlerConfig;
 
     private EmbeddedDocumentBytesConfig embeddedDocumentBytesConfig;
 
     public FetchEmitTuple(String id, FetchKey fetchKey, EmitKey emitKey) {
-        this(id, fetchKey, emitKey, new Metadata(), HandlerConfig.DEFAULT_HANDLER_CONFIG,
-                DEFAULT_ON_PARSE_EXCEPTION);
+        this(id, fetchKey, emitKey, new Metadata());
     }
-    public FetchEmitTuple(String id, FetchKey fetchKey, EmitKey emitKey, ON_PARSE_EXCEPTION onParseException) {
-        this(id, fetchKey, emitKey, new Metadata(), HandlerConfig.DEFAULT_HANDLER_CONFIG,
-                onParseException);
-    }
-
     public FetchEmitTuple(String id, FetchKey fetchKey, EmitKey emitKey, Metadata metadata) {
-        this(id, fetchKey, emitKey, metadata, HandlerConfig.DEFAULT_HANDLER_CONFIG,
-                DEFAULT_ON_PARSE_EXCEPTION);
+        this(id, fetchKey, emitKey, metadata, new ParseContext());
     }
 
-    public FetchEmitTuple(String id, FetchKey fetchKey, EmitKey emitKey, Metadata metadata,
-                          HandlerConfig handlerConfig, ON_PARSE_EXCEPTION onParseException) {
-        this(id, fetchKey, emitKey, metadata, handlerConfig, onParseException,
-                EmbeddedDocumentBytesConfig.SKIP);
+    public FetchEmitTuple(String id, FetchKey fetchKey, EmitKey emitKey, Metadata metadata, ParseContext parseContext) {
+        this(id, fetchKey, emitKey, metadata, parseContext, ON_PARSE_EXCEPTION.EMIT);
     }
 
-    public FetchEmitTuple(String id, FetchKey fetchKey, EmitKey emitKey, Metadata metadata,
-                          HandlerConfig handlerConfig, ON_PARSE_EXCEPTION onParseException,
-                          EmbeddedDocumentBytesConfig embeddedDocumentBytesConfig) {
+    public FetchEmitTuple(String id, FetchKey fetchKey, EmitKey emitKey, Metadata metadata, ParseContext parseContext,
+                          ON_PARSE_EXCEPTION onParseException) {
         this.id = id;
         this.fetchKey = fetchKey;
         this.emitKey = emitKey;
         this.metadata = metadata;
-        this.handlerConfig = handlerConfig;
+        this.parseContext = parseContext;
         this.onParseException = onParseException;
-        this.embeddedDocumentBytesConfig = embeddedDocumentBytesConfig;
     }
 
     public String getId() {
@@ -88,24 +78,15 @@ public class FetchEmitTuple implements Serializable {
         return metadata;
     }
 
-    public ON_PARSE_EXCEPTION getOnParseException() {
-        return onParseException;
+    public ParseContext getParseContext() {
+        return parseContext;
     }
-
     public void setEmitKey(EmitKey emitKey) {
         this.emitKey = emitKey;
     }
 
-    public void setHandlerConfig(HandlerConfig handlerConfig) {
-        this.handlerConfig = handlerConfig;
-    }
-
-    public HandlerConfig getHandlerConfig() {
-        return handlerConfig == null ? HandlerConfig.DEFAULT_HANDLER_CONFIG : handlerConfig;
-    }
-
-    public EmbeddedDocumentBytesConfig getEmbeddedDocumentBytesConfig() {
-        return embeddedDocumentBytesConfig;
+    public ON_PARSE_EXCEPTION getOnParseException() {
+        return onParseException;
     }
 
     @Override
@@ -118,46 +99,28 @@ public class FetchEmitTuple implements Serializable {
         }
 
         FetchEmitTuple that = (FetchEmitTuple) o;
-
-        if (!Objects.equals(id, that.id)) {
-            return false;
-        }
-        if (!Objects.equals(fetchKey, that.fetchKey)) {
-            return false;
-        }
-        if (!Objects.equals(emitKey, that.emitKey)) {
-            return false;
-        }
-        if (!Objects.equals(metadata, that.metadata)) {
-            return false;
-        }
-        if (onParseException != that.onParseException) {
-            return false;
-        }
-        if (!Objects.equals(handlerConfig, that.handlerConfig)) {
-            return false;
-        }
-        return Objects.equals(embeddedDocumentBytesConfig, that.embeddedDocumentBytesConfig);
+        return Objects.equals(id, that.id) && Objects.equals(fetchKey, that.fetchKey) && Objects.equals(emitKey, that.emitKey)
+                && Objects.equals(metadata, that.metadata) &&
+                Objects.equals(parseContext, that.parseContext) && onParseException == that.onParseException &&
+                Objects.equals(embeddedDocumentBytesConfig, that.embeddedDocumentBytesConfig);
     }
 
     @Override
     public int hashCode() {
-        int result = id != null ? id.hashCode() : 0;
-        result = 31 * result + (fetchKey != null ? fetchKey.hashCode() : 0);
-        result = 31 * result + (emitKey != null ? emitKey.hashCode() : 0);
-        result = 31 * result + (metadata != null ? metadata.hashCode() : 0);
-        result = 31 * result + (onParseException != null ? onParseException.hashCode() : 0);
-        result = 31 * result + (handlerConfig != null ? handlerConfig.hashCode() : 0);
-        result = 31 * result +
-                (embeddedDocumentBytesConfig != null ? embeddedDocumentBytesConfig.hashCode() : 0);
+        int result = Objects.hashCode(id);
+        result = 31 * result + Objects.hashCode(fetchKey);
+        result = 31 * result + Objects.hashCode(emitKey);
+        result = 31 * result + Objects.hashCode(metadata);
+        result = 31 * result + Objects.hashCode(parseContext);
+        result = 31 * result + Objects.hashCode(onParseException);
+        result = 31 * result + Objects.hashCode(embeddedDocumentBytesConfig);
         return result;
     }
 
     @Override
     public String toString() {
-        return "FetchEmitTuple{" + "id='" + id + '\'' + ", fetchKey=" + fetchKey + ", emitKey=" +
-                emitKey + ", metadata=" + metadata + ", onParseException=" + onParseException +
-                ", handlerConfig=" + handlerConfig + ", embeddedDocumentBytesConfig=" +
-                embeddedDocumentBytesConfig + '}';
+        return "FetchEmitTuple{" + "id='" + id + '\'' + ", fetchKey=" + fetchKey + ", emitKey=" + emitKey +
+                ", metadata=" + metadata + ", parseContext=" + parseContext +
+                ", onParseException=" + onParseException + ", embeddedDocumentBytesConfig=" + embeddedDocumentBytesConfig + '}';
     }
 }
diff --git a/tika-core/src/main/java/org/apache/tika/pipes/PipesServer.java b/tika-core/src/main/java/org/apache/tika/pipes/PipesServer.java
index 991694f88..ffa134aba 100644
--- a/tika-core/src/main/java/org/apache/tika/pipes/PipesServer.java
+++ b/tika-core/src/main/java/org/apache/tika/pipes/PipesServer.java
@@ -69,6 +69,7 @@ import org.apache.tika.pipes.emitter.Emitter;
 import org.apache.tika.pipes.emitter.EmitterManager;
 import org.apache.tika.pipes.emitter.StreamEmitter;
 import org.apache.tika.pipes.emitter.TikaEmitterException;
+import org.apache.tika.pipes.extractor.EmbeddedDocumentBytesConfig;
 import org.apache.tika.pipes.extractor.EmittingEmbeddedDocumentBytesHandler;
 import org.apache.tika.pipes.fetcher.FetchKey;
 import org.apache.tika.pipes.fetcher.Fetcher;
@@ -401,8 +402,11 @@ public class PipesServer implements Runnable {
         String stack = getContainerStacktrace(t, parseData.getMetadataList());
         //we need to apply this after we pull out the stacktrace
         filterMetadata(parseData.getMetadataList());
+        ParseContext parseContext = t.getParseContext();
+        FetchEmitTuple.ON_PARSE_EXCEPTION onParseException = t.getOnParseException();
+        EmbeddedDocumentBytesConfig embeddedDocumentBytesConfig = parseContext.get(EmbeddedDocumentBytesConfig.class);
         if (StringUtils.isBlank(stack) ||
-                t.getOnParseException() == FetchEmitTuple.ON_PARSE_EXCEPTION.EMIT) {
+                onParseException == FetchEmitTuple.ON_PARSE_EXCEPTION.EMIT) {
             injectUserMetadata(t.getMetadata(), parseData.getMetadataList());
             EmitKey emitKey = t.getEmitKey();
             if (StringUtils.isBlank(emitKey.getEmitKey())) {
@@ -410,13 +414,13 @@ public class PipesServer implements Runnable {
                 t.setEmitKey(emitKey);
             }
             EmitData emitData = new EmitData(t.getEmitKey(), parseData.getMetadataList(), stack);
-            if (t.getEmbeddedDocumentBytesConfig().isExtractEmbeddedDocumentBytes() &&
+            if (embeddedDocumentBytesConfig.isExtractEmbeddedDocumentBytes() &&
                     parseData.toBePackagedForStreamEmitter()) {
-                emit(t.getId(), emitKey, t.getEmbeddedDocumentBytesConfig().isExtractEmbeddedDocumentBytes(),
+                emit(t.getId(), emitKey, embeddedDocumentBytesConfig.isExtractEmbeddedDocumentBytes(),
                         parseData, stack);
             } else if (maxForEmitBatchBytes >= 0 &&
                     emitData.getEstimatedSizeBytes() >= maxForEmitBatchBytes) {
-                emit(t.getId(), emitKey, t.getEmbeddedDocumentBytesConfig().isExtractEmbeddedDocumentBytes(),
+                emit(t.getId(), emitKey, embeddedDocumentBytesConfig.isExtractEmbeddedDocumentBytes(),
                         parseData, stack);
             } else {
                 //send back to the client
@@ -464,7 +468,7 @@ public class PipesServer implements Runnable {
             }
             Metadata metadata = new Metadata();
             try (InputStream stream = ((RangeFetcher) fetcher).fetch(fetchKey.getFetchKey(),
-                    fetchKey.getRangeStart(), fetchKey.getRangeEnd(), metadata)) {
+                    fetchKey.getRangeStart(), fetchKey.getRangeEnd(), metadata, t.getParseContext())) {
                 return parseWithStream(t, stream, metadata);
             } catch (SecurityException e) {
                 LOG.error("security exception " + t.getId(), e);
@@ -475,7 +479,7 @@ public class PipesServer implements Runnable {
             }
         } else {
             Metadata metadata = new Metadata();
-            try (InputStream stream = fetcher.fetch(t.getFetchKey().getFetchKey(), metadata)) {
+            try (InputStream stream = fetcher.fetch(t.getFetchKey().getFetchKey(), metadata, t.getParseContext())) {
                 return parseWithStream(t, stream, metadata);
             } catch (SecurityException e) {
                 LOG.error("security exception " + t.getId(), e);
@@ -528,10 +532,11 @@ public class PipesServer implements Runnable {
     private MetadataListAndEmbeddedBytes parseWithStream(FetchEmitTuple fetchEmitTuple,
                                                          InputStream stream, Metadata metadata)
             throws TikaConfigException {
-        HandlerConfig handlerConfig = fetchEmitTuple.getHandlerConfig();
+
         List<Metadata> metadataList;
         //this adds the EmbeddedDocumentByteStore to the parsecontext
-        ParseContext parseContext = createParseContext(fetchEmitTuple);
+        ParseContext parseContext = setupParseContext(fetchEmitTuple);
+        HandlerConfig handlerConfig = parseContext.get(HandlerConfig.class);
         if (handlerConfig.getParseMode() == HandlerConfig.PARSE_MODE.RMETA) {
             metadataList =
                     parseRecursive(fetchEmitTuple, handlerConfig, stream, metadata, parseContext);
@@ -544,10 +549,16 @@ public class PipesServer implements Runnable {
                 parseContext.get(EmbeddedDocumentBytesHandler.class));
     }
 
-    private ParseContext createParseContext(FetchEmitTuple fetchEmitTuple)
+    private ParseContext setupParseContext(FetchEmitTuple fetchEmitTuple)
             throws TikaConfigException {
-        ParseContext parseContext = new ParseContext();
-        if (! fetchEmitTuple.getEmbeddedDocumentBytesConfig().isExtractEmbeddedDocumentBytes()) {
+        ParseContext parseContext = fetchEmitTuple.getParseContext();
+        if (parseContext.get(HandlerConfig.class) == null) {
+            parseContext.set(HandlerConfig.class, HandlerConfig.DEFAULT_HANDLER_CONFIG);
+        }
+        EmbeddedDocumentBytesConfig embeddedDocumentBytesConfig = parseContext.get(EmbeddedDocumentBytesConfig.class);
+        if (embeddedDocumentBytesConfig == null) {
+            //make sure there's one here -- or do we make this default in fetchemit tuple?
+            parseContext.set(EmbeddedDocumentBytesConfig.class, EmbeddedDocumentBytesConfig.SKIP);
             return parseContext;
         }
         EmbeddedDocumentExtractorFactory factory = ((AutoDetectParser)autoDetectParser)
@@ -561,18 +572,18 @@ public class PipesServer implements Runnable {
                         "instance of EmbeddedDocumentByteStoreExtractorFactory if you want" +
                         "to extract embedded bytes! I see this embedded doc factory: " +
                         factory.getClass() + "and a request: " +
-                        fetchEmitTuple.getEmbeddedDocumentBytesConfig());
+                        embeddedDocumentBytesConfig);
             }
         }
         //TODO: especially clean this up.
-        if (!StringUtils.isBlank(fetchEmitTuple.getEmbeddedDocumentBytesConfig().getEmitter())) {
+        if (!StringUtils.isBlank(embeddedDocumentBytesConfig.getEmitter())) {
             parseContext.set(EmbeddedDocumentBytesHandler.class,
                     new EmittingEmbeddedDocumentBytesHandler(fetchEmitTuple.getEmitKey(),
-                            fetchEmitTuple.getEmbeddedDocumentBytesConfig(), emitterManager));
+                            embeddedDocumentBytesConfig, emitterManager));
         } else {
             parseContext.set(EmbeddedDocumentBytesHandler.class,
                     new BasicEmbeddedDocumentBytesHandler(
-                    fetchEmitTuple.getEmbeddedDocumentBytesConfig()));
+                    embeddedDocumentBytesConfig));
         }
         return parseContext;
     }
@@ -693,9 +704,9 @@ public class PipesServer implements Runnable {
         } catch (IOException e) {
             LOG.warn("problem detecting: " + t.getId(), e);
         }
-
-        if (t.getEmbeddedDocumentBytesConfig() != null &&
-                t.getEmbeddedDocumentBytesConfig().isIncludeOriginal()) {
+        EmbeddedDocumentBytesConfig embeddedDocumentBytesConfig = parseContext.get(EmbeddedDocumentBytesConfig.class);
+        if (embeddedDocumentBytesConfig != null &&
+                embeddedDocumentBytesConfig.isIncludeOriginal()) {
             EmbeddedDocumentBytesHandler embeddedDocumentByteStore =
                     parseContext.get(EmbeddedDocumentBytesHandler.class);
             try (InputStream is = Files.newInputStream(tis.getPath())) {
diff --git a/tika-core/src/main/java/org/apache/tika/pipes/fetcher/EmptyFetcher.java b/tika-core/src/main/java/org/apache/tika/pipes/fetcher/EmptyFetcher.java
index 022d00a8c..d64f81524 100644
--- a/tika-core/src/main/java/org/apache/tika/pipes/fetcher/EmptyFetcher.java
+++ b/tika-core/src/main/java/org/apache/tika/pipes/fetcher/EmptyFetcher.java
@@ -21,6 +21,7 @@ import java.io.InputStream;
 
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.ParseContext;
 
 public class EmptyFetcher implements Fetcher {
 
@@ -30,7 +31,7 @@ public class EmptyFetcher implements Fetcher {
     }
 
     @Override
-    public InputStream fetch(String fetchKey, Metadata metadata) throws TikaException, IOException {
+    public InputStream fetch(String fetchKey, Metadata metadata, ParseContext parseContext) throws TikaException, IOException {
         return null;
     }
 }
diff --git a/tika-core/src/main/java/org/apache/tika/pipes/fetcher/Fetcher.java b/tika-core/src/main/java/org/apache/tika/pipes/fetcher/Fetcher.java
index 1b3fa2a24..8f7a186fd 100644
--- a/tika-core/src/main/java/org/apache/tika/pipes/fetcher/Fetcher.java
+++ b/tika-core/src/main/java/org/apache/tika/pipes/fetcher/Fetcher.java
@@ -21,6 +21,7 @@ import java.io.InputStream;
 
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.ParseContext;
 
 /**
  * Interface for an object that will fetch an InputStream given
@@ -33,5 +34,5 @@ public interface Fetcher {
 
     String getName();
 
-    InputStream fetch(String fetchKey, Metadata metadata) throws TikaException, IOException;
+    InputStream fetch(String fetchKey, Metadata metadata, ParseContext parseContext) throws TikaException, IOException;
 }
diff --git a/tika-core/src/main/java/org/apache/tika/pipes/fetcher/RangeFetcher.java b/tika-core/src/main/java/org/apache/tika/pipes/fetcher/RangeFetcher.java
index 0a3ceae7f..7754cb87c 100644
--- a/tika-core/src/main/java/org/apache/tika/pipes/fetcher/RangeFetcher.java
+++ b/tika-core/src/main/java/org/apache/tika/pipes/fetcher/RangeFetcher.java
@@ -21,6 +21,7 @@ import java.io.InputStream;
 
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.ParseContext;
 
 /**
  * This class extracts a range of bytes from a given fetch key.
@@ -28,7 +29,7 @@ import org.apache.tika.metadata.Metadata;
 public interface RangeFetcher extends Fetcher {
     //At some point, Tika 3.x?, we may want to add optional ranges to the fetchKey?
 
-    InputStream fetch(String fetchKey, long startOffset, long endOffset, Metadata metadata)
+    InputStream fetch(String fetchKey, long startOffset, long endOffset, Metadata metadata, ParseContext parseContext)
             throws TikaException, IOException;
 
 }
diff --git a/tika-core/src/main/java/org/apache/tika/pipes/fetcher/fs/FileSystemFetcher.java b/tika-core/src/main/java/org/apache/tika/pipes/fetcher/fs/FileSystemFetcher.java
index d926e3ca6..ce464dd14 100644
--- a/tika-core/src/main/java/org/apache/tika/pipes/fetcher/fs/FileSystemFetcher.java
+++ b/tika-core/src/main/java/org/apache/tika/pipes/fetcher/fs/FileSystemFetcher.java
@@ -41,6 +41,7 @@ import org.apache.tika.metadata.FileSystem;
 import org.apache.tika.metadata.Metadata;
 import org.apache.tika.metadata.Property;
 import org.apache.tika.metadata.TikaCoreProperties;
+import org.apache.tika.parser.ParseContext;
 import org.apache.tika.pipes.fetcher.AbstractFetcher;
 
 public class FileSystemFetcher extends AbstractFetcher implements Initializable {
@@ -58,10 +59,10 @@ public class FileSystemFetcher extends AbstractFetcher implements Initializable
     }
 
     @Override
-    public InputStream fetch(String fetchKey, Metadata metadata) throws IOException, TikaException {
+    public InputStream fetch(String fetchKey, Metadata metadata, ParseContext parseContext) throws IOException, TikaException {
 
         if (fetchKey.contains("\u0000")) {
-            throw new IllegalArgumentException("Path must not contain \u0000. " +
+            throw new IllegalArgumentException("Path must not contain 'u0000'. " +
                     "Please review the life decisions that led you to requesting " +
                     "a file name with this character in it.");
         }
diff --git a/tika-core/src/main/java/org/apache/tika/pipes/fetcher/url/UrlFetcher.java b/tika-core/src/main/java/org/apache/tika/pipes/fetcher/url/UrlFetcher.java
index f415a3560..7692516cd 100644
--- a/tika-core/src/main/java/org/apache/tika/pipes/fetcher/url/UrlFetcher.java
+++ b/tika-core/src/main/java/org/apache/tika/pipes/fetcher/url/UrlFetcher.java
@@ -24,6 +24,7 @@ import java.util.Locale;
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.io.TikaInputStream;
 import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.ParseContext;
 import org.apache.tika.pipes.fetcher.AbstractFetcher;
 
 /**
@@ -35,7 +36,7 @@ import org.apache.tika.pipes.fetcher.AbstractFetcher;
 public class UrlFetcher extends AbstractFetcher {
 
     @Override
-    public InputStream fetch(String fetchKey, Metadata metadata) throws IOException, TikaException {
+    public InputStream fetch(String fetchKey, Metadata metadata, ParseContext parseContext) throws IOException, TikaException {
         if (fetchKey.contains("\u0000")) {
             throw new IllegalArgumentException("URL must not contain \u0000. " +
                     "Please review the life decisions that led you to requesting " +
diff --git a/tika-core/src/main/java/org/apache/tika/pipes/pipesiterator/filelist/FileListPipesIterator.java b/tika-core/src/main/java/org/apache/tika/pipes/pipesiterator/filelist/FileListPipesIterator.java
index 90cabe881..75cb8390c 100644
--- a/tika-core/src/main/java/org/apache/tika/pipes/pipesiterator/filelist/FileListPipesIterator.java
+++ b/tika-core/src/main/java/org/apache/tika/pipes/pipesiterator/filelist/FileListPipesIterator.java
@@ -30,7 +30,9 @@ import org.apache.tika.config.InitializableProblemHandler;
 import org.apache.tika.config.TikaConfig;
 import org.apache.tika.exception.TikaConfigException;
 import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.ParseContext;
 import org.apache.tika.pipes.FetchEmitTuple;
+import org.apache.tika.pipes.HandlerConfig;
 import org.apache.tika.pipes.emitter.EmitKey;
 import org.apache.tika.pipes.fetcher.FetchKey;
 import org.apache.tika.pipes.pipesiterator.PipesIterator;
@@ -67,8 +69,10 @@ public class FileListPipesIterator extends PipesIterator implements Initializabl
                 if (! line.startsWith("#") && !StringUtils.isBlank(line)) {
                     FetchKey fetchKey = new FetchKey(getFetcherName(), line);
                     EmitKey emitKey = new EmitKey(getEmitterName(), line);
+                    ParseContext parseContext = new ParseContext();
+                    parseContext.set(HandlerConfig.class, getHandlerConfig());
                     tryToAdd(new FetchEmitTuple(line, fetchKey, emitKey,
-                            new Metadata(), getHandlerConfig(), getOnParseException()));
+                            new Metadata(), parseContext, getOnParseException()));
                 }
                 line = reader.readLine();
             }
diff --git a/tika-core/src/main/java/org/apache/tika/pipes/pipesiterator/fs/FileSystemPipesIterator.java b/tika-core/src/main/java/org/apache/tika/pipes/pipesiterator/fs/FileSystemPipesIterator.java
index 9e903fd8b..793ac27fb 100644
--- a/tika-core/src/main/java/org/apache/tika/pipes/pipesiterator/fs/FileSystemPipesIterator.java
+++ b/tika-core/src/main/java/org/apache/tika/pipes/pipesiterator/fs/FileSystemPipesIterator.java
@@ -38,7 +38,9 @@ import org.apache.tika.config.Param;
 import org.apache.tika.config.TikaConfig;
 import org.apache.tika.exception.TikaConfigException;
 import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.ParseContext;
 import org.apache.tika.pipes.FetchEmitTuple;
+import org.apache.tika.pipes.HandlerConfig;
 import org.apache.tika.pipes.async.AsyncProcessor;
 import org.apache.tika.pipes.emitter.EmitKey;
 import org.apache.tika.pipes.fetcher.FetchKey;
@@ -152,8 +154,10 @@ public class FileSystemPipesIterator extends PipesIterator
             String relPath = basePath.relativize(file).toString();
 
             try {
+                ParseContext parseContext = new ParseContext();
+                parseContext.set(HandlerConfig.class, getHandlerConfig());
                 tryToAdd(new FetchEmitTuple(relPath, new FetchKey(fetcherName, relPath),
-                        new EmitKey(emitterName, relPath), new Metadata(), getHandlerConfig(),
+                        new EmitKey(emitterName, relPath), new Metadata(), parseContext,
                         getOnParseException()));
             } catch (TimeoutException e) {
                 throw new IOException(e);
diff --git a/tika-core/src/test/java/org/apache/tika/pipes/PipesServerTest.java b/tika-core/src/test/java/org/apache/tika/pipes/PipesServerTest.java
index 4aca5207e..dd8ef4ff4 100644
--- a/tika-core/src/test/java/org/apache/tika/pipes/PipesServerTest.java
+++ b/tika-core/src/test/java/org/apache/tika/pipes/PipesServerTest.java
@@ -33,6 +33,7 @@ import org.junit.jupiter.api.io.TempDir;
 import org.apache.tika.TikaTest;
 import org.apache.tika.extractor.BasicEmbeddedDocumentBytesHandler;
 import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.ParseContext;
 import org.apache.tika.pipes.emitter.EmitKey;
 import org.apache.tika.pipes.extractor.EmbeddedDocumentBytesConfig;
 import org.apache.tika.pipes.fetcher.FetchKey;
@@ -104,12 +105,12 @@ public class PipesServerTest extends TikaTest {
         EmbeddedDocumentBytesConfig embeddedDocumentBytesConfig =
                 new EmbeddedDocumentBytesConfig(true);
         embeddedDocumentBytesConfig.setIncludeOriginal(true);
-
+        ParseContext parseContext = new ParseContext();
+        parseContext.set(HandlerConfig.class, HandlerConfig.DEFAULT_HANDLER_CONFIG);
+        parseContext.set(EmbeddedDocumentBytesConfig.class, embeddedDocumentBytesConfig);
         FetchEmitTuple fetchEmitTuple = new FetchEmitTuple("id",
                 new FetchKey("fs", "mock.xml"),
-                new EmitKey("", ""), new Metadata(),
-                HandlerConfig.DEFAULT_HANDLER_CONFIG, FetchEmitTuple.ON_PARSE_EXCEPTION.EMIT,
-                embeddedDocumentBytesConfig);
+                new EmitKey("", ""), new Metadata(), parseContext);
         Fetcher fetcher = FetcherManager.load(tikaConfig).getFetcher();
         PipesServer.MetadataListAndEmbeddedBytes
                 parseData = pipesServer.parseFromTuple(fetchEmitTuple, fetcher);
@@ -160,12 +161,13 @@ public class PipesServerTest extends TikaTest {
         EmbeddedDocumentBytesConfig embeddedDocumentBytesConfig =
                 new EmbeddedDocumentBytesConfig(true);
         embeddedDocumentBytesConfig.setIncludeOriginal(true);
-
+        ParseContext parseContext = new ParseContext();
+        parseContext.set(HandlerConfig.class, HandlerConfig.DEFAULT_HANDLER_CONFIG);
+        parseContext.set(EmbeddedDocumentBytesConfig.class, embeddedDocumentBytesConfig);
         FetchEmitTuple fetchEmitTuple = new FetchEmitTuple("id",
                 new FetchKey("fs", "mock.xml"),
-                new EmitKey("", ""), new Metadata(),
-                HandlerConfig.DEFAULT_HANDLER_CONFIG, FetchEmitTuple.ON_PARSE_EXCEPTION.EMIT,
-                embeddedDocumentBytesConfig);
+                new EmitKey("", ""), new Metadata(), parseContext);
+
         Fetcher fetcher = FetcherManager.load(tikaConfig).getFetcher();
         PipesServer.MetadataListAndEmbeddedBytes
                 parseData = pipesServer.parseFromTuple(fetchEmitTuple, fetcher);
diff --git a/tika-core/src/test/java/org/apache/tika/pipes/async/MockFetcher.java b/tika-core/src/test/java/org/apache/tika/pipes/async/MockFetcher.java
index 10af275e3..acb533ece 100644
--- a/tika-core/src/test/java/org/apache/tika/pipes/async/MockFetcher.java
+++ b/tika-core/src/test/java/org/apache/tika/pipes/async/MockFetcher.java
@@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets;
 
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.ParseContext;
 import org.apache.tika.pipes.fetcher.Fetcher;
 
 public class MockFetcher implements Fetcher {
@@ -37,7 +38,7 @@ public class MockFetcher implements Fetcher {
     }
 
     @Override
-    public InputStream fetch(String fetchKey, Metadata metadata) throws TikaException, IOException {
+    public InputStream fetch(String fetchKey, Metadata metadata, ParseContext parseContext) throws TikaException, IOException {
         return new ByteArrayInputStream(BYTES);
     }
 }
diff --git a/tika-core/src/test/java/org/apache/tika/pipes/fetcher/MockFetcher.java b/tika-core/src/test/java/org/apache/tika/pipes/fetcher/MockFetcher.java
index 060432724..e9104e0a8 100644
--- a/tika-core/src/test/java/org/apache/tika/pipes/fetcher/MockFetcher.java
+++ b/tika-core/src/test/java/org/apache/tika/pipes/fetcher/MockFetcher.java
@@ -29,6 +29,7 @@ import org.apache.tika.config.Param;
 import org.apache.tika.exception.TikaConfigException;
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.ParseContext;
 
 public class MockFetcher extends AbstractFetcher implements Initializable {
 
@@ -64,7 +65,7 @@ public class MockFetcher extends AbstractFetcher implements Initializable {
 
 
     @Override
-    public InputStream fetch(String fetchKey, Metadata metadata) throws TikaException, IOException {
+    public InputStream fetch(String fetchKey, Metadata metadata, ParseContext parseContext) throws TikaException, IOException {
         return byteString == null ? new ByteArrayInputStream(new byte[0]) :
                 new ByteArrayInputStream(byteString.getBytes(StandardCharsets.UTF_8));
     }