Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tika support #998

Merged
merged 1 commit into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/test-categories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ misc:
- qute
- stream
- tarfile
- tika
- vertx
networking:
- ftp
Expand Down
57 changes: 57 additions & 0 deletions docs/modules/ROOT/pages/extensions/tika.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Do not edit directly!
// This file was generated by camel-quarkus-package-maven-plugin:update-extension-doc-page

[[tika]]
= Tika

[.badges]
[.badge-key]##Since Camel Quarkus##[.badge-version]##1.0.0-CR3## [.badge-key]##JVM##[.badge-supported]##supported## [.badge-key]##Native##[.badge-supported]##supported##

Parse documents and extract metadata and text using Apache Tika.

== What's inside

* https://camel.apache.org/components/latest/tika-component.html[Tika component], URI syntax: `tika:operation`

Please refer to the above link for usage and configuration details.

== Maven coordinates

[source,xml]
----
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-tika</artifactId>
</dependency>
----

Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.

== Camel Quarkus limitations

Parameters `tikaConfig` and `tikaConfigUri` are not available in quarkus camel tika extension. Configuration
can be changed only via `application.properties`.

While you can use any of the available https://tika.apache.org/1.24.1/formats.html[Tika parsers] in JVM mode,
only some of those are supported in native mode - see the https://quarkus.io/guides/tika[Quarkus Tika guide].

Use of the Tika parser without any configuration will initialize all available parsers. Unfortunately as some of them
don't work in the native mode, the whole execution will fail.

In order to make the Tika parser work in the native mode, selection of parsers for initialization should be used.

* `quarkus.tika.parsers` Comma separated list of parsers (abbreviations). There are two predefined parsers:
`pdf` and `odf`.
* `quarkus.tika.parser.*` Adds new parser abbreviation to be used with previous property. Value is the full class of
the parser.

Example of `application.properties`:
[source,properties]
----
quarkus.tika.parsers = pdf,odf,office
quarkus.tika.parser.office = org.apache.tika.parser.microsoft.OfficeParser
----

For more information about selecting parsers see the https://quarkus.io/guides/tika[Quarkus Tika guide].


Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In case you are missing some Camel feature in the list:
== Camel Components

// components: START
Number of Camel components: 149 in 114 JAR artifacts (0 deprecated)
Number of Camel components: 150 in 115 JAR artifacts (0 deprecated)

[width="100%",cols="4,1,1,1,5",options="header"]
|===
Expand Down Expand Up @@ -306,6 +306,8 @@ Number of Camel components: 149 in 114 JAR artifacts (0 deprecated)

| xref:extensions/telegram.adoc[Telegram] | camel-quarkus-telegram | Native + Stable | 1.0.0-M4 | Send and receive messages acting as a Telegram Bot Telegram Bot API.

| xref:extensions/tika.adoc[Tika] | camel-quarkus-tika | Native + Stable | 1.0.0-CR3 | Parse documents and extract metadata and text using Apache Tika.

| xref:extensions/timer.adoc[Timer] | camel-quarkus-timer | Native + Stable | 0.2.0 | Generate messages in specified intervals using java.util.Timer.

| xref:extensions/twitter.adoc[Twitter Direct Message] | camel-quarkus-twitter | Native + Stable | 0.2.0 | Send and receive Twitter direct messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.URIResolver;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TemplatesHandler;
import javax.xml.transform.sax.TransformerHandler;

import org.xml.sax.XMLFilter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -32,13 +37,13 @@
* A {@link TransformerFactory} delegating to a {@link TransformerFactory} created via
* {@code TransformerFactory.newInstance("org.apache.xalan.xsltc.trax.TransformerFactoryImpl", Thread.currentThread().getContextClassLoader())}
*/
public final class XalanTransformerFactory extends TransformerFactory {
public final class XalanTransformerFactory extends SAXTransformerFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(XalanTransformerFactory.class);

private final TransformerFactory delegate;
private final SAXTransformerFactory delegate;

public XalanTransformerFactory() {
final TransformerFactory factory = TransformerFactory.newInstance(
final SAXTransformerFactory factory = (SAXTransformerFactory) TransformerFactory.newInstance(
"org.apache.xalan.xsltc.trax.TransformerFactoryImpl",
Thread.currentThread().getContextClassLoader());
try {
Expand Down Expand Up @@ -110,4 +115,35 @@ public void setErrorListener(ErrorListener listener) {
public ErrorListener getErrorListener() {
return delegate.getErrorListener();
}

@Override
public TransformerHandler newTransformerHandler(Source source) throws TransformerConfigurationException {
return delegate.newTransformerHandler(source);
}

@Override
public TransformerHandler newTransformerHandler(Templates templates) throws TransformerConfigurationException {
return delegate.newTransformerHandler(templates);
}

@Override
public TransformerHandler newTransformerHandler() throws TransformerConfigurationException {
return delegate.newTransformerHandler();
}

@Override
public TemplatesHandler newTemplatesHandler() throws TransformerConfigurationException {
return delegate.newTemplatesHandler();
}

@Override
public XMLFilter newXMLFilter(Source source) throws TransformerConfigurationException {
return delegate.newXMLFilter(source);
}

@Override
public XMLFilter newXMLFilter(Templates templates) throws TransformerConfigurationException {
return delegate.newXMLFilter(templates);
}

}
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<module>tagsoup</module>
<module>tarfile</module>
<module>telegram</module>
<module>tika</module>
<module>timer</module>
<module>twitter</module>
<module>validator</module>
Expand Down
83 changes: 83 additions & 0 deletions extensions/tika/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?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.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-tika-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-tika-deployment</artifactId>
<name>Camel Quarkus :: Tika :: Deployment</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bom-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-tika</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-tika-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-xalan-deployment</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.quarkus.component.tika.deployment;

import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import org.apache.camel.component.tika.TikaComponent;
import org.apache.camel.quarkus.component.tika.TikaRecorder;
import org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeBeanBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilter;
import org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilterBuildItem;
import org.jboss.logging.Logger;

class TikaProcessor {

private static final Logger LOG = Logger.getLogger(TikaProcessor.class);
private static final String FEATURE = "camel-tika";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

/*
* The tika component is programmatically configured by the extension thus
* we can safely prevent camel to instantiate a default instance.
*/
@BuildStep
CamelServiceFilterBuildItem serviceFilter() {
return new CamelServiceFilterBuildItem(CamelServiceFilter.forComponent("tika"));
}

@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelRuntimeBeanBuildItem tikaComponent(BeanContainerBuildItem beanContainer, TikaRecorder recorder) {
return new CamelRuntimeBeanBuildItem(
"tika",
TikaComponent.class.getName(),
recorder.createTikaComponent(beanContainer.getValue()));
}
}
39 changes: 39 additions & 0 deletions extensions/tika/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-build-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../../poms/build-parent/pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-tika-parent</artifactId>
<name>Camel Quarkus :: Tika</name>
<packaging>pom</packaging>

<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>