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

Croway pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 0b36851686dc (chore) Upgrade camel-tika to Apache Tika 4
0b36851686dc is described below

commit 0b36851686dc106d538671119df1b78f43751f56
Author: Federico Mariani <[email protected]>
AuthorDate: Fri Aug 28 16:40:30 2026 +0200

    (chore) Upgrade camel-tika to Apache Tika 4
---
 .../org/apache/camel/catalog/components/tika.json  |  4 +-
 components/camel-tika/pom.xml                      | 18 ++++---
 .../component/tika/TikaEndpointConfigurer.java     | 24 ++++-----
 .../component/tika/TikaEndpointUriFactory.java     |  4 +-
 .../org/apache/camel/component/tika/tika.json      |  4 +-
 .../apache/camel/component/tika/TikaComponent.java | 10 ++--
 .../camel/component/tika/TikaConfiguration.java    | 36 ++++++--------
 .../apache/camel/component/tika/TikaProducer.java  | 58 ++++++++++++++++------
 .../camel/component/tika/TikaEmptyConfig.java      | 33 ------------
 .../tika/TikaMetadataHeaderFilterTest.java         |  2 +-
 .../apache/camel/component/tika/TikaParseTest.java | 24 +++++----
 .../camel-tika/src/test/resources/tika-empty.json  | 19 +++++++
 .../camel-tika/src/test/resources/tika-empty.xml   | 24 ---------
 .../ROOT/pages/camel-4x-upgrade-guide-4_22.adoc    |  8 +++
 .../ROOT/pages/camel-4x-upgrade-guide-4_23.adoc    |  9 ++++
 .../endpoint/dsl/TikaEndpointBuilderFactory.java   | 33 ++++++------
 parent/pom.xml                                     |  2 +-
 17 files changed, 159 insertions(+), 153 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/tika.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/tika.json
index 06bdb919d9ca..25b7bcb392da 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/tika.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/tika.json
@@ -32,7 +32,7 @@
     "tikaParseOutputEncoding": { "index": 1, "kind": "parameter", 
"displayName": "Tika Parse Output Encoding", "group": "producer", "label": "", 
"required": false, "type": "string", "javaType": "java.lang.String", 
"deprecated": false, "autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.tika.TikaConfiguration", "configurationField": 
"tikaConfiguration", "description": "Tika Parse Output Encoding" },
     "tikaParseOutputFormat": { "index": 2, "kind": "parameter", "displayName": 
"Tika Parse Output Format", "group": "producer", "label": "", "required": 
false, "type": "enum", "javaType": 
"org.apache.camel.component.tika.TikaParseOutputFormat", "enum": [ "xml", 
"html", "text" ], "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": "xml", "configurationClass": 
"org.apache.camel.component.tika.TikaConfiguration", "configurationField": 
"tikaConfiguration", "description" [...]
     "lazyStartProducer": { "index": 3, "kind": "parameter", "displayName": 
"Lazy Start Producer", "group": "producer (advanced)", "label": 
"producer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the producer should be started 
lazy (on the first message). By starting lazy you can use this to allow 
CamelContext and routes to startup in situations where a produc [...]
-    "tikaConfig": { "index": 4, "kind": "parameter", "displayName": "Tika 
Config", "group": "advanced", "label": "advanced", "required": false, "type": 
"object", "javaType": "org.apache.tika.config.TikaConfig", "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.tika.TikaConfiguration", "configurationField": 
"tikaConfiguration", "description": "Tika Config" },
-    "tikaConfigUri": { "index": 5, "kind": "parameter", "displayName": "Tika 
Config Uri", "group": "advanced", "label": "advanced", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.tika.TikaConfiguration", "configurationField": 
"tikaConfiguration", "description": "Tika Config Url" }
+    "tikaConfigFile": { "index": 4, "kind": "parameter", "displayName": "Tika 
Config File", "group": "advanced", "label": "advanced", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.tika.TikaConfiguration", "configurationField": 
"tikaConfiguration", "description": "Path to a Tika JSON configuration file" },
+    "tikaLoader": { "index": 5, "kind": "parameter", "displayName": "Tika 
Loader", "group": "advanced", "label": "advanced", "required": false, "type": 
"object", "javaType": "org.apache.tika.config.loader.TikaLoader", "deprecated": 
false, "autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.tika.TikaConfiguration", "configurationField": 
"tikaConfiguration", "description": "Tika loader used to configure parsers and 
detectors" }
   }
 }
diff --git a/components/camel-tika/pom.xml b/components/camel-tika/pom.xml
index a9409bf1c66e..093f64bd6a8c 100644
--- a/components/camel-tika/pom.xml
+++ b/components/camel-tika/pom.xml
@@ -40,12 +40,16 @@
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-support</artifactId>
         </dependency>
-
         <dependency>
             <groupId>org.apache.tika</groupId>
             <artifactId>tika-core</artifactId>
             <version>${tika-version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.tika</groupId>
+            <artifactId>tika-serialization</artifactId>
+            <version>${tika-version}</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.tika</groupId>
             <artifactId>tika-parser-html-module</artifactId>
@@ -74,12 +78,6 @@
                 </exclusion>
             </exclusions>
         </dependency>
-        <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-            <version>${commons-io-version}</version>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>org.hamcrest</groupId>
             <artifactId>hamcrest</artifactId>
@@ -91,6 +89,12 @@
             <artifactId>assertj-core</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.tika</groupId>
+            <artifactId>tika-encoding-detector-universal</artifactId>
+            <version>${tika-version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 </project>
diff --git 
a/components/camel-tika/src/generated/java/org/apache/camel/component/tika/TikaEndpointConfigurer.java
 
b/components/camel-tika/src/generated/java/org/apache/camel/component/tika/TikaEndpointConfigurer.java
index 54aec470e9df..f7d1f9269d0f 100644
--- 
a/components/camel-tika/src/generated/java/org/apache/camel/component/tika/TikaEndpointConfigurer.java
+++ 
b/components/camel-tika/src/generated/java/org/apache/camel/component/tika/TikaEndpointConfigurer.java
@@ -25,10 +25,10 @@ public class TikaEndpointConfigurer extends 
PropertyConfigurerSupport implements
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "lazystartproducer":
         case "lazyStartProducer": 
target.setLazyStartProducer(property(camelContext, boolean.class, value)); 
return true;
-        case "tikaconfig":
-        case "tikaConfig": 
target.getTikaConfiguration().setTikaConfig(property(camelContext, 
org.apache.tika.config.TikaConfig.class, value)); return true;
-        case "tikaconfiguri":
-        case "tikaConfigUri": 
target.getTikaConfiguration().setTikaConfigUri(property(camelContext, 
java.lang.String.class, value)); return true;
+        case "tikaconfigfile":
+        case "tikaConfigFile": 
target.getTikaConfiguration().setTikaConfigFile(property(camelContext, 
java.lang.String.class, value)); return true;
+        case "tikaloader":
+        case "tikaLoader": 
target.getTikaConfiguration().setTikaLoader(property(camelContext, 
org.apache.tika.config.loader.TikaLoader.class, value)); return true;
         case "tikaparseoutputencoding":
         case "tikaParseOutputEncoding": 
target.getTikaConfiguration().setTikaParseOutputEncoding(property(camelContext, 
java.lang.String.class, value)); return true;
         case "tikaparseoutputformat":
@@ -42,10 +42,10 @@ public class TikaEndpointConfigurer extends 
PropertyConfigurerSupport implements
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "lazystartproducer":
         case "lazyStartProducer": return boolean.class;
-        case "tikaconfig":
-        case "tikaConfig": return org.apache.tika.config.TikaConfig.class;
-        case "tikaconfiguri":
-        case "tikaConfigUri": return java.lang.String.class;
+        case "tikaconfigfile":
+        case "tikaConfigFile": return java.lang.String.class;
+        case "tikaloader":
+        case "tikaLoader": return 
org.apache.tika.config.loader.TikaLoader.class;
         case "tikaparseoutputencoding":
         case "tikaParseOutputEncoding": return java.lang.String.class;
         case "tikaparseoutputformat":
@@ -60,10 +60,10 @@ public class TikaEndpointConfigurer extends 
PropertyConfigurerSupport implements
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "lazystartproducer":
         case "lazyStartProducer": return target.isLazyStartProducer();
-        case "tikaconfig":
-        case "tikaConfig": return 
target.getTikaConfiguration().getTikaConfig();
-        case "tikaconfiguri":
-        case "tikaConfigUri": return 
target.getTikaConfiguration().getTikaConfigUri();
+        case "tikaconfigfile":
+        case "tikaConfigFile": return 
target.getTikaConfiguration().getTikaConfigFile();
+        case "tikaloader":
+        case "tikaLoader": return 
target.getTikaConfiguration().getTikaLoader();
         case "tikaparseoutputencoding":
         case "tikaParseOutputEncoding": return 
target.getTikaConfiguration().getTikaParseOutputEncoding();
         case "tikaparseoutputformat":
diff --git 
a/components/camel-tika/src/generated/java/org/apache/camel/component/tika/TikaEndpointUriFactory.java
 
b/components/camel-tika/src/generated/java/org/apache/camel/component/tika/TikaEndpointUriFactory.java
index cf5642d1dbf4..9ab5d6f2eecf 100644
--- 
a/components/camel-tika/src/generated/java/org/apache/camel/component/tika/TikaEndpointUriFactory.java
+++ 
b/components/camel-tika/src/generated/java/org/apache/camel/component/tika/TikaEndpointUriFactory.java
@@ -27,8 +27,8 @@ public class TikaEndpointUriFactory extends 
org.apache.camel.support.component.E
         Set<String> props = new HashSet<>(6);
         props.add("lazyStartProducer");
         props.add("operation");
-        props.add("tikaConfig");
-        props.add("tikaConfigUri");
+        props.add("tikaConfigFile");
+        props.add("tikaLoader");
         props.add("tikaParseOutputEncoding");
         props.add("tikaParseOutputFormat");
         PROPERTY_NAMES = Collections.unmodifiableSet(props);
diff --git 
a/components/camel-tika/src/generated/resources/META-INF/org/apache/camel/component/tika/tika.json
 
b/components/camel-tika/src/generated/resources/META-INF/org/apache/camel/component/tika/tika.json
index 06bdb919d9ca..25b7bcb392da 100644
--- 
a/components/camel-tika/src/generated/resources/META-INF/org/apache/camel/component/tika/tika.json
+++ 
b/components/camel-tika/src/generated/resources/META-INF/org/apache/camel/component/tika/tika.json
@@ -32,7 +32,7 @@
     "tikaParseOutputEncoding": { "index": 1, "kind": "parameter", 
"displayName": "Tika Parse Output Encoding", "group": "producer", "label": "", 
"required": false, "type": "string", "javaType": "java.lang.String", 
"deprecated": false, "autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.tika.TikaConfiguration", "configurationField": 
"tikaConfiguration", "description": "Tika Parse Output Encoding" },
     "tikaParseOutputFormat": { "index": 2, "kind": "parameter", "displayName": 
"Tika Parse Output Format", "group": "producer", "label": "", "required": 
false, "type": "enum", "javaType": 
"org.apache.camel.component.tika.TikaParseOutputFormat", "enum": [ "xml", 
"html", "text" ], "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": "xml", "configurationClass": 
"org.apache.camel.component.tika.TikaConfiguration", "configurationField": 
"tikaConfiguration", "description" [...]
     "lazyStartProducer": { "index": 3, "kind": "parameter", "displayName": 
"Lazy Start Producer", "group": "producer (advanced)", "label": 
"producer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the producer should be started 
lazy (on the first message). By starting lazy you can use this to allow 
CamelContext and routes to startup in situations where a produc [...]
-    "tikaConfig": { "index": 4, "kind": "parameter", "displayName": "Tika 
Config", "group": "advanced", "label": "advanced", "required": false, "type": 
"object", "javaType": "org.apache.tika.config.TikaConfig", "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.tika.TikaConfiguration", "configurationField": 
"tikaConfiguration", "description": "Tika Config" },
-    "tikaConfigUri": { "index": 5, "kind": "parameter", "displayName": "Tika 
Config Uri", "group": "advanced", "label": "advanced", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.tika.TikaConfiguration", "configurationField": 
"tikaConfiguration", "description": "Tika Config Url" }
+    "tikaConfigFile": { "index": 4, "kind": "parameter", "displayName": "Tika 
Config File", "group": "advanced", "label": "advanced", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.tika.TikaConfiguration", "configurationField": 
"tikaConfiguration", "description": "Path to a Tika JSON configuration file" },
+    "tikaLoader": { "index": 5, "kind": "parameter", "displayName": "Tika 
Loader", "group": "advanced", "label": "advanced", "required": false, "type": 
"object", "javaType": "org.apache.tika.config.loader.TikaLoader", "deprecated": 
false, "autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.tika.TikaConfiguration", "configurationField": 
"tikaConfiguration", "description": "Tika loader used to configure parsers and 
detectors" }
   }
 }
diff --git 
a/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaComponent.java
 
b/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaComponent.java
index 480b6758273a..f59e36157822 100644
--- 
a/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaComponent.java
+++ 
b/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaComponent.java
@@ -22,20 +22,20 @@ import java.util.Map;
 import org.apache.camel.Endpoint;
 import org.apache.camel.spi.annotations.Component;
 import org.apache.camel.support.DefaultComponent;
-import org.apache.tika.config.TikaConfig;
+import org.apache.tika.config.loader.TikaLoader;
 
 @Component("tika")
 public class TikaComponent extends DefaultComponent {
 
-    private static final String TIKA_CONFIG = "tikaConfig";
+    private static final String TIKA_LOADER = "tikaLoader";
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
         TikaConfiguration tikaConfiguration = new TikaConfiguration();
 
-        TikaConfig config = resolveAndRemoveReferenceParameter(parameters, 
TIKA_CONFIG, TikaConfig.class);
-        if (config != null) {
-            tikaConfiguration.setTikaConfig(config);
+        TikaLoader loader = resolveAndRemoveReferenceParameter(parameters, 
TIKA_LOADER, TikaLoader.class);
+        if (loader != null) {
+            tikaConfiguration.setTikaLoader(loader);
         }
         tikaConfiguration.setOperation(new URI(uri).getHost());
         TikaEndpoint endpoint = createEndpoint(uri, tikaConfiguration);
diff --git 
a/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaConfiguration.java
 
b/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaConfiguration.java
index 93de5fc3a6f9..9f2dee1dd0ab 100644
--- 
a/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaConfiguration.java
+++ 
b/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaConfiguration.java
@@ -18,12 +18,11 @@ package org.apache.camel.component.tika;
 
 import java.nio.charset.Charset;
 
-import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
 import org.apache.camel.spi.UriPath;
-import org.apache.tika.config.TikaConfig;
+import org.apache.tika.config.loader.TikaLoader;
 
 @UriParams
 public class TikaConfiguration {
@@ -35,10 +34,10 @@ public class TikaConfiguration {
     private TikaParseOutputFormat tikaParseOutputFormat = 
TikaParseOutputFormat.xml;
     @UriParam(description = "Tika Parse Output Encoding")
     private String tikaParseOutputEncoding = Charset.defaultCharset().name();
-    @UriParam(label = "advanced", description = "Tika Config")
-    private TikaConfig tikaConfig = TikaConfig.getDefaultConfig();
-    @UriParam(label = "advanced", description = "Tika Config Url")
-    private String tikaConfigUri;
+    @UriParam(label = "advanced", description = "Tika loader used to configure 
parsers and detectors")
+    private TikaLoader tikaLoader;
+    @UriParam(label = "advanced", description = "Path to a Tika JSON 
configuration file")
+    private String tikaConfigFile;
 
     public TikaOperation getOperation() {
         return operation;
@@ -85,30 +84,25 @@ public class TikaConfiguration {
         this.tikaParseOutputEncoding = tikaParseOutputEncoding;
     }
 
-    public TikaConfig getTikaConfig() {
-        return tikaConfig;
+    public TikaLoader getTikaLoader() {
+        return tikaLoader;
     }
 
     /**
-     * To use a custom Tika config.
+     * To use a custom Tika loader.
      */
-    public void setTikaConfig(TikaConfig tikaConfig) {
-        this.tikaConfig = tikaConfig;
+    public void setTikaLoader(TikaLoader tikaLoader) {
+        this.tikaLoader = tikaLoader;
     }
 
-    public String getTikaConfigUri() {
-        return tikaConfigUri;
+    public String getTikaConfigFile() {
+        return tikaConfigFile;
     }
 
     /**
-     * Tika Config Uri: The URI of tika-config.xml file to use.
+     * Tika configuration file: The path of the Tika JSON configuration file 
to use.
      */
-    public void setTikaConfigUri(String tikaConfigUri) {
-        this.tikaConfigUri = tikaConfigUri;
-        try {
-            this.tikaConfig = new TikaConfig(tikaConfigUri);
-        } catch (Exception e) {
-            throw new RuntimeCamelException(e);
-        }
+    public void setTikaConfigFile(String tikaConfigFile) {
+        this.tikaConfigFile = tikaConfigFile;
     }
 }
diff --git 
a/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaProducer.java
 
b/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaProducer.java
index 6d8f2c2625c2..99cba8870398 100644
--- 
a/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaProducer.java
+++ 
b/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaProducer.java
@@ -22,6 +22,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
+import java.nio.file.Path;
 
 import javax.xml.XMLConstants;
 import javax.xml.transform.OutputKeys;
@@ -35,15 +36,17 @@ import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.support.DefaultHeaderFilterStrategy;
 import org.apache.camel.support.DefaultProducer;
-import org.apache.tika.config.TikaConfig;
+import org.apache.tika.config.loader.TikaLoader;
 import org.apache.tika.detect.Detector;
+import org.apache.tika.exception.TikaConfigException;
 import org.apache.tika.exception.TikaException;
+import org.apache.tika.io.TikaInputStream;
 import org.apache.tika.metadata.Metadata;
 import org.apache.tika.mime.MediaType;
-import org.apache.tika.parser.AutoDetectParser;
 import org.apache.tika.parser.ParseContext;
 import org.apache.tika.parser.Parser;
 import org.apache.tika.sax.BodyContentHandler;
@@ -59,6 +62,8 @@ public class TikaProducer extends DefaultProducer {
 
     private final TikaConfiguration tikaConfiguration;
 
+    private final TikaLoader tikaLoader;
+
     private final Parser parser;
 
     private final Detector detector;
@@ -73,13 +78,31 @@ public class TikaProducer extends DefaultProducer {
         super(endpoint);
         this.tikaConfiguration = endpoint.getTikaConfiguration();
         this.encoding = this.tikaConfiguration.getTikaParseOutputEncoding();
-        TikaConfig config = this.tikaConfiguration.getTikaConfig();
-        this.detector = config.getDetector();
-        if (parser == null) {
-            this.parser = new 
AutoDetectParser(this.tikaConfiguration.getTikaConfig());
-        } else {
-            this.parser = parser;
+        try {
+            this.tikaLoader = createTikaLoader(endpoint);
+            this.detector = tikaLoader.loadDetectors();
+            this.parser = parser == null ? tikaLoader.loadAutoDetectParser() : 
parser;
+        } catch (Exception e) {
+            throw new RuntimeCamelException(e);
+        }
+    }
+
+    private TikaLoader createTikaLoader(TikaEndpoint endpoint) throws 
TikaConfigException, IOException {
+        TikaLoader configuredLoader = tikaConfiguration.getTikaLoader();
+        if (configuredLoader != null) {
+            return configuredLoader;
         }
+
+        ClassLoader classLoader = 
endpoint.getCamelContext().getApplicationContextClassLoader();
+        if (classLoader == null) {
+            classLoader = Thread.currentThread().getContextClassLoader();
+        }
+        if (classLoader == null) {
+            classLoader = TikaProducer.class.getClassLoader();
+        }
+
+        String configFile = tikaConfiguration.getTikaConfigFile();
+        return configFile == null ? TikaLoader.loadDefault(classLoader) : 
TikaLoader.load(Path.of(configFile), classLoader);
     }
 
     @Override
@@ -102,25 +125,28 @@ public class TikaProducer extends DefaultProducer {
         exchange.getMessage().setBody(result);
     }
 
-    private Object doDetect(Exchange exchange) throws IOException {
+    private Object doDetect(Exchange exchange) throws IOException, 
TikaConfigException {
         MediaType result;
-        try (InputStream inputStream = 
exchange.getIn().getBody(InputStream.class)) {
-            Metadata metadata = new Metadata();
-            result = this.detector.detect(inputStream, metadata);
+        Metadata metadata = new Metadata();
+        ParseContext context = tikaLoader.loadParseContext();
+        try (InputStream stream = exchange.getIn().getBody(InputStream.class);
+             TikaInputStream inputStream = TikaInputStream.get(stream, 
metadata)) {
+            result = this.detector.detect(inputStream, metadata, context);
             convertMetadataToHeaders(metadata, exchange);
         }
         return result.toString();
     }
 
     private Object doParse(Exchange exchange)
-            throws TikaException, IOException, SAXException, 
TransformerConfigurationException {
+            throws TikaException, TikaConfigException, IOException, 
SAXException, TransformerConfigurationException {
 
         OutputStream result = new ByteArrayOutputStream();
-        try (InputStream inputStream = 
exchange.getIn().getBody(InputStream.class)) {
+        Metadata metadata = new Metadata();
+        try (InputStream stream = exchange.getIn().getBody(InputStream.class);
+             TikaInputStream inputStream = TikaInputStream.get(stream, 
metadata)) {
             ContentHandler contentHandler = 
getContentHandler(this.tikaConfiguration, result);
-            ParseContext context = new ParseContext();
+            ParseContext context = tikaLoader.loadParseContext();
             context.set(Parser.class, this.parser);
-            Metadata metadata = new Metadata();
             this.parser.parse(inputStream, contentHandler, metadata, context);
             convertMetadataToHeaders(metadata, exchange);
         }
diff --git 
a/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaEmptyConfig.java
 
b/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaEmptyConfig.java
deleted file mode 100644
index 2b1e5bb62999..000000000000
--- 
a/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaEmptyConfig.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.camel.component.tika;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.xml.sax.SAXException;
-
-import org.apache.tika.config.TikaConfig;
-import org.apache.tika.exception.TikaException;
-
-public class TikaEmptyConfig extends TikaConfig {
-
-    public TikaEmptyConfig() throws TikaException, IOException, SAXException {
-        super(new File("src/test/resources/tika-empty.xml"));
-    }
-
-}
diff --git 
a/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaMetadataHeaderFilterTest.java
 
b/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaMetadataHeaderFilterTest.java
index 0a8d1e0c8108..939a73207d6a 100644
--- 
a/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaMetadataHeaderFilterTest.java
+++ 
b/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaMetadataHeaderFilterTest.java
@@ -58,7 +58,7 @@ class TikaMetadataHeaderFilterTest extends CamelTestSupport {
         
assertThat(exchange.getIn().getHeader("org.apache.camel.internal")).isNull();
 
         // metadata outside the internal namespace is still mapped, so the 
filter has not simply dropped everything
-        assertThat(exchange.getIn().getHeader("author")).isEqualTo("kept");
+        assertThat(exchange.getIn().getHeader("dc:creator")).isEqualTo("kept");
         assertThat(exchange.getIn().getHeader("dc:title")).isEqualTo("t");
     }
 
diff --git 
a/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaParseTest.java
 
b/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaParseTest.java
index 500947de9087..4670aa529a4c 100644
--- 
a/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaParseTest.java
+++ 
b/components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaParseTest.java
@@ -19,7 +19,6 @@ package org.apache.camel.component.tika;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.util.Map;
@@ -31,8 +30,11 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.test.junit6.CamelTestSupport;
+import org.apache.tika.config.loader.TikaLoader;
+import org.apache.tika.detect.universal.UniversalEncodingDetector;
+import org.apache.tika.io.TikaInputStream;
 import org.apache.tika.metadata.Metadata;
-import org.apache.tika.parser.txt.UniversalEncodingDetector;
+import org.apache.tika.parser.ParseContext;
 import org.junit.jupiter.api.Test;
 
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -58,10 +60,9 @@ public class TikaParseTest extends CamelTestSupport {
                 assertThat(body, instanceOf(String.class));
 
                 Charset detectedCharset = null;
-                try {
-                    InputStream bodyIs = new 
ByteArrayInputStream(body.getBytes());
+                try (TikaInputStream bodyIs = TikaInputStream.get(new 
ByteArrayInputStream(body.getBytes()))) {
                     UniversalEncodingDetector encodingDetector = new 
UniversalEncodingDetector();
-                    detectedCharset = encodingDetector.detect(bodyIs, new 
Metadata());
+                    detectedCharset = encodingDetector.detect(bodyIs, new 
Metadata(), new ParseContext()).get(0).getCharset();
                 } catch (IOException e1) {
                     fail();
                 }
@@ -89,10 +90,11 @@ public class TikaParseTest extends CamelTestSupport {
                 assertThat(body, instanceOf(String.class));
 
                 Charset detectedCharset = null;
-                try {
-                    InputStream bodyIs = new ByteArrayInputStream(((String) 
body).getBytes(StandardCharsets.UTF_16));
+                try (TikaInputStream bodyIs
+                        = TikaInputStream.get(
+                                new ByteArrayInputStream(((String) 
body).getBytes(StandardCharsets.UTF_16)))) {
                     UniversalEncodingDetector encodingDetector = new 
UniversalEncodingDetector();
-                    detectedCharset = encodingDetector.detect(bodyIs, new 
Metadata());
+                    detectedCharset = encodingDetector.detect(bodyIs, new 
Metadata(), new ParseContext()).get(0).getCharset();
                 } catch (IOException e1) {
                     fail();
                 }
@@ -174,9 +176,9 @@ public class TikaParseTest extends CamelTestSupport {
             @Override
             public void configure() {
                 from("direct:start").to("tika:parse").to("mock:result");
-                
from("direct:start2").to("tika:parse?tikaConfigUri=src/test/resources/tika-empty.xml")
+                
from("direct:start2").to("tika:parse?tikaConfigFile=src/test/resources/tika-empty.json")
                         .to("mock:result");
-                
from("direct:start3").to("tika:parse?tikaConfig=#testConfig").to("mock:result");
+                
from("direct:start3").to("tika:parse?tikaLoader=#testLoader").to("mock:result");
                 from("direct:start4").to("tika:parse?tikaParseOutputEncoding=" 
+ StandardCharsets.UTF_16.name())
                         .to("mock:result");
             }
@@ -185,6 +187,6 @@ public class TikaParseTest extends CamelTestSupport {
 
     @Override
     protected void bindToRegistry(Registry registry) throws Exception {
-        registry.bind("testConfig", new TikaEmptyConfig());
+        registry.bind("testLoader", TikaLoader.load(new 
File("src/test/resources/tika-empty.json").toPath()));
     }
 }
diff --git a/components/camel-tika/src/test/resources/tika-empty.json 
b/components/camel-tika/src/test/resources/tika-empty.json
new file mode 100644
index 000000000000..4f2907f95562
--- /dev/null
+++ b/components/camel-tika/src/test/resources/tika-empty.json
@@ -0,0 +1,19 @@
+// 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.
+{
+  "parsers": [
+    "empty-parser"
+  ]
+}
diff --git a/components/camel-tika/src/test/resources/tika-empty.xml 
b/components/camel-tika/src/test/resources/tika-empty.xml
deleted file mode 100644
index 9902cf98d8e0..000000000000
--- a/components/camel-tika/src/test/resources/tika-empty.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
-    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.
-
--->
-<properties>
-  <parsers>
-    <parser class="org.apache.tika.parser.EmptyParser"/>
-  </parsers>
-</properties>
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc
index 30b7e92c0b8e..4eacfff6bdc3 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc
@@ -55,6 +55,14 @@ Camel then no longer controls how the payload is read.
 
 == Upgrading Camel 4.21 to 4.22
 
+=== camel-tika
+
+The `tikaConfig` and `tikaConfigUri` component options are deprecated for 
removal in Camel 4.23.
+Apache Tika 4 removes the `TikaConfig` class and XML configuration support; 
Camel 4.23 provides the
+replacement `tikaLoader` and `tikaConfigFile` options based on Tika's 
`TikaLoader` and JSON configuration.
+See the 
https://tika.apache.org/docs/4.0.x/migration-to-4x/migrating-to-4x.html[Tika 4 
migration guide]
+for migration details.
+
 === camel-reactive-executor-tomcat
 
 The `camel-reactive-executor-tomcat` component has been deprecated. Its 
cross-thread `ThreadLocal`
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
index 762d40c1acfc..1e59f43decfd 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
@@ -201,6 +201,15 @@ Documents carrying an internal DTD subset still parse: 
`disallow-doctype-decl` i
 set here, because that would reject input that parses today. Routes that 
genuinely need to resolve
 an external DTD or parameter entity through this converter must supply their 
own
 `SAXParserFactory`.
+=== camel-tika
+
+The Tika dependency has been upgraded from 3.x to 4.x. Tika 4 removed the 
`TikaConfig` class and XML
+configuration support in favor of `TikaLoader` and JSON configuration. 
Consequently, the deprecated
+`tikaConfig` and `tikaConfigUri` options have been removed. Use `tikaLoader` 
to provide an
+`org.apache.tika.config.loader.TikaLoader`, or `tikaConfigFile` to load a JSON 
configuration file.
+Applications using either removed option must migrate their Tika 
configuration; see the
+https://tika.apache.org/docs/4.0.x/migration-to-4x/migrating-to-4x.html[Tika 4 
migration guide] for
+the configuration and metadata-key changes.
 
 === camel-a2a - webhook URL address classification
 
diff --git 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/TikaEndpointBuilderFactory.java
 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/TikaEndpointBuilderFactory.java
index b1de6a481da4..45184959aa7e 100644
--- 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/TikaEndpointBuilderFactory.java
+++ 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/TikaEndpointBuilderFactory.java
@@ -157,46 +157,47 @@ public interface TikaEndpointBuilderFactory {
             return this;
         }
         /**
-         * Tika Config.
+         * Path to a Tika JSON configuration file.
          * 
-         * The option is a: <code>org.apache.tika.config.TikaConfig</code> 
type.
+         * The option is a: <code>java.lang.String</code> type.
          * 
          * Group: advanced
          * 
-         * @param tikaConfig the value to set
+         * @param tikaConfigFile the value to set
          * @return the dsl builder
          */
-        default AdvancedTikaEndpointBuilder 
tikaConfig(org.apache.tika.config.TikaConfig tikaConfig) {
-            doSetProperty("tikaConfig", tikaConfig);
+        default AdvancedTikaEndpointBuilder tikaConfigFile(String 
tikaConfigFile) {
+            doSetProperty("tikaConfigFile", tikaConfigFile);
             return this;
         }
         /**
-         * Tika Config.
+         * Tika loader used to configure parsers and detectors.
          * 
-         * The option will be converted to a
-         * <code>org.apache.tika.config.TikaConfig</code> type.
+         * The option is a:
+         * <code>org.apache.tika.config.loader.TikaLoader</code> type.
          * 
          * Group: advanced
          * 
-         * @param tikaConfig the value to set
+         * @param tikaLoader the value to set
          * @return the dsl builder
          */
-        default AdvancedTikaEndpointBuilder tikaConfig(String tikaConfig) {
-            doSetProperty("tikaConfig", tikaConfig);
+        default AdvancedTikaEndpointBuilder 
tikaLoader(org.apache.tika.config.loader.TikaLoader tikaLoader) {
+            doSetProperty("tikaLoader", tikaLoader);
             return this;
         }
         /**
-         * Tika Config Url.
+         * Tika loader used to configure parsers and detectors.
          * 
-         * The option is a: <code>java.lang.String</code> type.
+         * The option will be converted to a
+         * <code>org.apache.tika.config.loader.TikaLoader</code> type.
          * 
          * Group: advanced
          * 
-         * @param tikaConfigUri the value to set
+         * @param tikaLoader the value to set
          * @return the dsl builder
          */
-        default AdvancedTikaEndpointBuilder tikaConfigUri(String 
tikaConfigUri) {
-            doSetProperty("tikaConfigUri", tikaConfigUri);
+        default AdvancedTikaEndpointBuilder tikaLoader(String tikaLoader) {
+            doSetProperty("tikaLoader", tikaLoader);
             return this;
         }
     }
diff --git a/parent/pom.xml b/parent/pom.xml
index ce5629e84342..54f08f5fceef 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -521,7 +521,7 @@
         <tamboui-version>0.4.0</tamboui-version>
         <testcontainers-version>2.0.5</testcontainers-version>
         <thymeleaf-version>3.1.5.RELEASE</thymeleaf-version>
-        <tika-version>3.3.2</tika-version>
+        <tika-version>4.0.0</tika-version>
         <twilio-version>12.1.1</twilio-version>
         <twitter4j-version>4.1.2</twitter4j-version>
         <undertow-servlet-version>2.3.26.Final</undertow-servlet-version>

Reply via email to