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 2021/08/17 15:20:58 UTC
[tika] 01/02: TIKA-3527 -- add a simple UrlFetcher
This is an automated email from the ASF dual-hosted git repository.
tallison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git
commit 7077e9b822adb798efa260f587ab0a2babcfb746
Author: tallison <ta...@apache.org>
AuthorDate: Tue Aug 17 09:18:53 2021 -0400
TIKA-3527 -- add a simple UrlFetcher
---
CHANGES.txt | 4 ++
.../apache/tika/pipes/fetcher/url/UrlFetcher.java | 52 ++++++++++++++++++++++
.../resources/config/tika-config-url-fetcher.xml | 4 +-
3 files changed, 58 insertions(+), 2 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 4edc510..414253c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -11,6 +11,10 @@ Release 2.1.0 - ???
* Change the default rendering strategy for PDFs from NO_TEXT to ALL (TIKA-3520).
Other changes:
+
+ * Add a simple UrlFetcher in tika-core as a basic alternative
+ to tika-fetcher-http (TIKA-3527).
+
* Add tika-pipes support for Google Cloud Storage (TIKA-3524).
* Fix markup ordering errors in xhtml output for ODT files (TIKA-2242).
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
new file mode 100644
index 0000000..ec4954f
--- /dev/null
+++ b/tika-core/src/main/java/org/apache/tika/pipes/fetcher/url/UrlFetcher.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.pipes.fetcher.url;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+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.pipes.fetcher.AbstractFetcher;
+
+/**
+ * Simple fetcher for URLs. This simply calls {@link TikaInputStream#get(URL)}.
+ * This intentionally does not support fetching for files.
+ * Please use the FileSystemFetcher for that. If you need more advanced control (passwords,
+ * timeouts, proxies, etc), please use the tika-fetcher-http module.
+ */
+public class UrlFetcher extends AbstractFetcher {
+
+ @Override
+ public InputStream fetch(String fetchKey, Metadata metadata) 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 " +
+ "a URL with this character in it.");
+ }
+ if (fetchKey.toLowerCase(Locale.US).startsWith("file:")) {
+ throw new IllegalArgumentException(
+ "The UrlFetcher does not fetch from file shares; " +
+ "please use the FileSystemFetcher");
+ }
+ return TikaInputStream.get(new URL(fetchKey), metadata);
+ }
+
+}
diff --git a/tika-server/tika-server-standard/src/test/resources/config/tika-config-url-fetcher.xml b/tika-server/tika-server-standard/src/test/resources/config/tika-config-url-fetcher.xml
index d3aaff0..d8a4321 100644
--- a/tika-server/tika-server-standard/src/test/resources/config/tika-config-url-fetcher.xml
+++ b/tika-server/tika-server-standard/src/test/resources/config/tika-config-url-fetcher.xml
@@ -22,9 +22,9 @@
<parser class="org.apache.tika.parser.DefaultParser"/>
</parsers>
<fetchers>
- <fetcher class="org.apache.tika.pipes.fetcher.SimpleUrlFetcher">
+ <fetcher class="org.apache.tika.pipes.fetcher.url.UrlFetcher">
<params>
- <param name="name" type="string">url</param>
+ <name>url</name>
</params>
</fetcher>
</fetchers>