You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pp...@apache.org on 2020/09/16 08:55:42 UTC
[camel-quarkus] branch master updated: FOP native support #1642
This is an automated email from the ASF dual-hosted git repository.
ppalaga pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push:
new a96274a FOP native support #1642
a96274a is described below
commit a96274af3e248f1a1639e2347de5033b703899c3
Author: JiriOndrusek <on...@gmail.com>
AuthorDate: Tue Sep 15 10:30:17 2020 +0200
FOP native support #1642
---
.../ROOT/pages/reference/components/fop.adoc | 6 +-
.../ROOT/pages/reference/extensions/fop.adoc | 24 ++++-
.../component/fop/deployment/FopProcessor.java | 46 ----------
extensions-jvm/pom.xml | 1 -
.../fop/deployment/pom.xml | 4 +
.../component/fop/deployment/FopProcessor.java | 90 +++++++++++++++++++
{extensions-jvm => extensions}/fop/pom.xml | 1 -
{extensions-jvm => extensions}/fop/runtime/pom.xml | 16 ++++
.../fop/runtime/src/main/doc/limitations.adoc | 12 +++
.../fop/PDFRendererOptionsConfigSubstitution.java | 23 +++--
.../main/resources/META-INF/quarkus-extension.yaml | 3 +-
extensions/pom.xml | 1 +
.../fop}/pom.xml | 69 ++++++++++++---
.../quarkus/component/fop/it/FopResource.java | 42 ++++++---
.../camel/quarkus/component/fop/it/FopIT.java | 16 +---
.../camel/quarkus/component/fop/it/FopTest.java | 98 +++++++++++++++++++++
.../fop/src/test/resources/Freedom-10eM.ttf | Bin 0 -> 17064 bytes
integration-tests/fop/src/test/resources/mycfg.xml | 33 +++++++
integration-tests/pom.xml | 1 +
pom.xml | 1 +
poms/bom-test/pom.xml | 5 ++
tooling/scripts/test-categories.yaml | 1 +
22 files changed, 382 insertions(+), 111 deletions(-)
diff --git a/docs/modules/ROOT/pages/reference/components/fop.adoc b/docs/modules/ROOT/pages/reference/components/fop.adoc
index 98b54a0..d2d72d0 100644
--- a/docs/modules/ROOT/pages/reference/components/fop.adoc
+++ b/docs/modules/ROOT/pages/reference/components/fop.adoc
@@ -4,11 +4,11 @@
= FOP
:cq-artifact-id: camel-quarkus-fop
:cq-artifact-id-base: fop
-:cq-native-supported: false
-:cq-status: Preview
+:cq-native-supported: true
+:cq-status: Stable
:cq-deprecated: false
:cq-jvm-since: 1.1.0
-:cq-native-since: n/a
+:cq-native-since: 1.2.0
:cq-camel-part-name: fop
:cq-camel-part-title: FOP
:cq-camel-part-description: Render messages into PDF and other output formats supported by Apache FOP.
diff --git a/docs/modules/ROOT/pages/reference/extensions/fop.adoc b/docs/modules/ROOT/pages/reference/extensions/fop.adoc
index 6cd11fd..b035afa 100644
--- a/docs/modules/ROOT/pages/reference/extensions/fop.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/fop.adoc
@@ -3,15 +3,15 @@
= FOP
:cq-artifact-id: camel-quarkus-fop
-:cq-native-supported: false
-:cq-status: Preview
+:cq-native-supported: true
+:cq-status: Stable
:cq-description: Render messages into PDF and other output formats supported by Apache FOP.
:cq-deprecated: false
:cq-jvm-since: 1.1.0
-:cq-native-since: n/a
+:cq-native-since: 1.2.0
[.badges]
-[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##
+[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native since##[.badge-supported]##1.2.0##
Render messages into PDF and other output formats supported by Apache FOP.
@@ -32,3 +32,19 @@ Please refer to the above link for usage and configuration details.
----
Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
+
+== Camel Quarkus limitations
+
+While you can use any of the available output types in JVM mode, only PDF output type is supported
+in native mode. PDF output type in native mode has several limitations:
+
+* Default sRGB color space is always disabled because of https://github.com/oracle/graal/issues/2850[Graal VM issue #2850]
+and `disable-srgb-colorspace` https://xmlgraphics.apache.org/fop/2.1/configuration.html[FOP configuration property] is
+ignored.
+
+* If custom fonts are used, font cache has to be disabled because of https://github.com/oracle/graal/issues/460[Graal VM issue #460].
+Please set the https://xmlgraphics.apache.org/fop/2.1/configuration.html[FOP configuration property] `use-cache` to `false`.
+
+Please file an https://github.com/apache/camel-quarkus/issues/new[issue] if you are missing some specific output format
+in native mode.
+
diff --git a/extensions-jvm/fop/deployment/src/main/java/org/apache/camel/quarkus/component/fop/deployment/FopProcessor.java b/extensions-jvm/fop/deployment/src/main/java/org/apache/camel/quarkus/component/fop/deployment/FopProcessor.java
deleted file mode 100644
index 090f818..0000000
--- a/extensions-jvm/fop/deployment/src/main/java/org/apache/camel/quarkus/component/fop/deployment/FopProcessor.java
+++ /dev/null
@@ -1,46 +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.quarkus.component.fop.deployment;
-
-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 io.quarkus.deployment.pkg.steps.NativeBuild;
-import org.apache.camel.quarkus.core.JvmOnlyRecorder;
-import org.jboss.logging.Logger;
-
-class FopProcessor {
-
- private static final Logger LOG = Logger.getLogger(FopProcessor.class);
- private static final String FEATURE = "camel-fop";
-
- @BuildStep
- FeatureBuildItem feature() {
- return new FeatureBuildItem(FEATURE);
- }
-
- /**
- * Remove this once this extension starts supporting the native mode.
- */
- @BuildStep(onlyIf = NativeBuild.class)
- @Record(value = ExecutionTime.RUNTIME_INIT)
- void warnJvmInNative(JvmOnlyRecorder recorder) {
- JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time
- recorder.warnJvmInNative(FEATURE); // warn at runtime
- }
-}
diff --git a/extensions-jvm/pom.xml b/extensions-jvm/pom.xml
index f31e5a1..aa22e70 100644
--- a/extensions-jvm/pom.xml
+++ b/extensions-jvm/pom.xml
@@ -71,7 +71,6 @@
<module>facebook</module>
<module>fastjson</module>
<module>flink</module>
- <module>fop</module>
<module>freemarker</module>
<module>ganglia</module>
<module>geocoder</module>
diff --git a/extensions-jvm/fop/deployment/pom.xml b/extensions/fop/deployment/pom.xml
similarity index 94%
rename from extensions-jvm/fop/deployment/pom.xml
rename to extensions/fop/deployment/pom.xml
index 8bc853e..693085a 100644
--- a/extensions-jvm/fop/deployment/pom.xml
+++ b/extensions/fop/deployment/pom.xml
@@ -42,6 +42,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-xml-jaxp-deployment</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-fop</artifactId>
</dependency>
</dependencies>
diff --git a/extensions/fop/deployment/src/main/java/org/apache/camel/quarkus/component/fop/deployment/FopProcessor.java b/extensions/fop/deployment/src/main/java/org/apache/camel/quarkus/component/fop/deployment/FopProcessor.java
new file mode 100644
index 0000000..d7cf3bd
--- /dev/null
+++ b/extensions/fop/deployment/src/main/java/org/apache/camel/quarkus/component/fop/deployment/FopProcessor.java
@@ -0,0 +1,90 @@
+/*
+ * 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.fop.deployment;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
+import org.apache.fop.render.RendererEventProducer;
+import org.apache.fop.render.pdf.PDFDocumentHandlerMaker;
+import org.apache.fop.render.pdf.extensions.PDFExtensionHandlerFactory;
+import org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry;
+import org.jboss.jandex.IndexView;
+
+class FopProcessor {
+
+ private static final String FEATURE = "camel-fop";
+
+ @BuildStep
+ FeatureBuildItem feature() {
+ return new FeatureBuildItem(FEATURE);
+ }
+
+ @BuildStep
+ ReflectiveClassBuildItem registerForReflection(CombinedIndexBuildItem combinedIndex) {
+ IndexView index = combinedIndex.getIndex();
+
+ List<String> dtos = index.getKnownClasses().stream()
+ .map(ci -> ci.name().toString())
+ .filter(n -> n.endsWith("ElementMapping"))
+ .sorted()
+ .collect(Collectors.toList());
+
+ dtos.add(PDFExtensionHandlerFactory.class.getName());
+ dtos.add(PDFDocumentHandlerMaker.class.getName());
+ dtos.add(RendererEventProducer.class.getName());
+ dtos.add(IOException.class.getName());
+ dtos.add(Integer.class.getName());
+
+ return new ReflectiveClassBuildItem(false, false, dtos.toArray(new String[dtos.size()]));
+ }
+
+ @BuildStep
+ void addDependencies(BuildProducer<IndexDependencyBuildItem> indexDependency) {
+ indexDependency.produce(new IndexDependencyBuildItem("org.apache.xmlgraphics", "fop"));
+ }
+
+ @BuildStep
+ NativeImageResourceBuildItem initResources() {
+ return new NativeImageResourceBuildItem(
+ "META-INF/services/org.apache.fop.fo.ElementMapping",
+ "META-INF/services/org.apache.fop.render.intermediate.IFDocumentHandler",
+ "org/apache/fop/render/event-model.xml");
+ }
+
+ @BuildStep
+ NativeImageProxyDefinitionBuildItem initProxies() {
+ return new NativeImageProxyDefinitionBuildItem(
+ "org.apache.fop.render.RendererEventProducer");
+ }
+
+ @BuildStep
+ public void registerRuntimeInitializedClasses(BuildProducer<RuntimeInitializedClassBuildItem> resource) {
+ resource.produce(new RuntimeInitializedClassBuildItem(ImageImplRegistry.class.getName()));
+ }
+
+}
diff --git a/extensions-jvm/fop/pom.xml b/extensions/fop/pom.xml
similarity index 97%
rename from extensions-jvm/fop/pom.xml
rename to extensions/fop/pom.xml
index a67341b..4660a43 100644
--- a/extensions-jvm/fop/pom.xml
+++ b/extensions/fop/pom.xml
@@ -35,6 +35,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
- <module>integration-test</module>
</modules>
</project>
diff --git a/extensions-jvm/fop/runtime/pom.xml b/extensions/fop/runtime/pom.xml
similarity index 86%
rename from extensions-jvm/fop/runtime/pom.xml
rename to extensions/fop/runtime/pom.xml
index 653e2e1..2dc62ff 100644
--- a/extensions-jvm/fop/runtime/pom.xml
+++ b/extensions/fop/runtime/pom.xml
@@ -34,6 +34,7 @@
<properties>
<camel.quarkus.jvmSince>1.1.0</camel.quarkus.jvmSince>
+ <camel.quarkus.nativeSince>1.2.0</camel.quarkus.nativeSince>
</properties>
<dependencyManagement>
@@ -58,8 +59,23 @@
<artifactId>camel-quarkus-support-commons-logging</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-xml-jaxp</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-fop</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.graalvm.nativeimage</groupId>
+ <artifactId>svm</artifactId>
+ <scope>provided</scope>
</dependency>
</dependencies>
diff --git a/extensions/fop/runtime/src/main/doc/limitations.adoc b/extensions/fop/runtime/src/main/doc/limitations.adoc
new file mode 100644
index 0000000..8a2fbf9
--- /dev/null
+++ b/extensions/fop/runtime/src/main/doc/limitations.adoc
@@ -0,0 +1,12 @@
+While you can use any of the available output types in JVM mode, only PDF output type is supported
+in native mode. PDF output type in native mode has several limitations:
+
+* Default sRGB color space is always disabled because of https://github.com/oracle/graal/issues/2850[Graal VM issue #2850]
+and `disable-srgb-colorspace` https://xmlgraphics.apache.org/fop/2.1/configuration.html[FOP configuration property] is
+ignored.
+
+* If custom fonts are used, font cache has to be disabled because of https://github.com/oracle/graal/issues/460[Graal VM issue #460].
+Please set the https://xmlgraphics.apache.org/fop/2.1/configuration.html[FOP configuration property] `use-cache` to `false`.
+
+Please file an https://github.com/apache/camel-quarkus/issues/new[issue] if you are missing some specific output format
+in native mode.
diff --git a/extensions-jvm/fop/integration-test/src/test/java/org/apache/camel/quarkus/component/fop/it/FopTest.java b/extensions/fop/runtime/src/main/java/org/apache/camel/quarkus/component/fop/PDFRendererOptionsConfigSubstitution.java
similarity index 62%
copy from extensions-jvm/fop/integration-test/src/test/java/org/apache/camel/quarkus/component/fop/it/FopTest.java
copy to extensions/fop/runtime/src/main/java/org/apache/camel/quarkus/component/fop/PDFRendererOptionsConfigSubstitution.java
index b8ed067..4275d9e 100644
--- a/extensions-jvm/fop/integration-test/src/test/java/org/apache/camel/quarkus/component/fop/it/FopTest.java
+++ b/extensions/fop/runtime/src/main/java/org/apache/camel/quarkus/component/fop/PDFRendererOptionsConfigSubstitution.java
@@ -14,21 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.quarkus.component.fop.it;
+package org.apache.camel.quarkus.component.fop;
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
+import com.oracle.svm.core.annotate.Substitute;
+import com.oracle.svm.core.annotate.TargetClass;
+import org.apache.fop.render.pdf.PDFRendererOptionsConfig;
-@QuarkusTest
-class FopTest {
+@TargetClass(value = PDFRendererOptionsConfig.class)
+final class PDFRendererOptionsConfigSubstitution {
- @Test
- public void loadComponentFop() {
- /* A simple autogenerated test */
- RestAssured.get("/fop/load/component/fop")
- .then()
- .statusCode(200);
+ @Substitute
+ public Boolean getDisableSRGBColorSpace() {
+ //sRGB color space has to be disabled because of https://github.com/oracle/graal/issues/2850
+ return true;
}
-
}
diff --git a/extensions-jvm/fop/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/fop/runtime/src/main/resources/META-INF/quarkus-extension.yaml
similarity index 97%
rename from extensions-jvm/fop/runtime/src/main/resources/META-INF/quarkus-extension.yaml
rename to extensions/fop/runtime/src/main/resources/META-INF/quarkus-extension.yaml
index 749eccc..c44999d 100644
--- a/extensions-jvm/fop/runtime/src/main/resources/META-INF/quarkus-extension.yaml
+++ b/extensions/fop/runtime/src/main/resources/META-INF/quarkus-extension.yaml
@@ -24,9 +24,8 @@
name: "Camel FOP"
description: "Render messages into PDF and other output formats supported by Apache FOP"
metadata:
- unlisted: true
guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/fop.html"
categories:
- "integration"
status:
- - "preview"
+ - "stable"
diff --git a/extensions/pom.xml b/extensions/pom.xml
index 2540be7..35b00d3 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -100,6 +100,7 @@
<module>file</module>
<module>file-watch</module>
<module>flatpack</module>
+ <module>fop</module>
<module>ftp</module>
<module>git</module>
<module>github</module>
diff --git a/extensions-jvm/fop/integration-test/pom.xml b/integration-tests/fop/pom.xml
similarity index 58%
rename from extensions-jvm/fop/integration-test/pom.xml
rename to integration-tests/fop/pom.xml
index fc28851..4c51ee2 100644
--- a/extensions-jvm/fop/integration-test/pom.xml
+++ b/integration-tests/fop/pom.xml
@@ -23,25 +23,15 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
- <artifactId>camel-quarkus-build-parent-it</artifactId>
+ <artifactId>camel-quarkus-integration-tests</artifactId>
<version>1.2.0-SNAPSHOT</version>
- <relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
+ <relativePath>../pom.xml</relativePath>
</parent>
- <artifactId>camel-quarkus-fop-integration-test</artifactId>
- <name>Camel Quarkus :: FOP :: Integration Test</name>
+ <artifactId>camel-quarkus-integration-test-fop</artifactId>
+ <name>Camel Quarkus :: Integration Tests :: FOP</name>
<description>Integration tests for Camel Quarkus FOP extension</description>
- <properties>
- <!-- mvnd, a.k.a. Maven Daemon: https://github.com/mvndaemon/mvnd -->
- <!-- The following rule tells mvnd to build the listed deployment modules before this module. -->
- <!-- This is important because mvnd builds modules in parallel by default. The deployment modules are not -->
- <!-- explicit dependencies of this module in the Maven sense, although they are required by the Quarkus Maven plugin. -->
- <!-- Please update the rule whenever you change the dependencies of this module by running -->
- <!-- mvn process-resources -Pformat from the root directory -->
- <mvnd.builder.rule>camel-quarkus-fop-deployment,camel-quarkus-support-policy-deployment</mvnd.builder.rule>
- </properties>
-
<dependencyManagement>
<dependencies>
<dependency>
@@ -75,6 +65,26 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.pdfbox</groupId>
+ <artifactId>pdfbox</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-fop-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
<build>
@@ -92,4 +102,35 @@
</plugin>
</plugins>
</build>
+
+ <profiles>
+ <profile>
+ <id>native</id>
+ <activation>
+ <property>
+ <name>native</name>
+ </property>
+ </activation>
+ <properties>
+ <quarkus.package.type>native</quarkus.package.type>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
</project>
diff --git a/extensions-jvm/fop/integration-test/src/main/java/org/apache/camel/quarkus/component/fop/it/FopResource.java b/integration-tests/fop/src/main/java/org/apache/camel/quarkus/component/fop/it/FopResource.java
similarity index 54%
rename from extensions-jvm/fop/integration-test/src/main/java/org/apache/camel/quarkus/component/fop/it/FopResource.java
rename to integration-tests/fop/src/main/java/org/apache/camel/quarkus/component/fop/it/FopResource.java
index 81e8a6a..54319ee 100644
--- a/extensions-jvm/fop/integration-test/src/main/java/org/apache/camel/quarkus/component/fop/it/FopResource.java
+++ b/integration-tests/fop/src/main/java/org/apache/camel/quarkus/component/fop/it/FopResource.java
@@ -16,15 +16,21 @@
*/
package org.apache.camel.quarkus.component.fop.it;
+import java.io.InputStream;
+import java.net.URI;
+
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
-import javax.ws.rs.GET;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import org.apache.camel.CamelContext;
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.ProducerTemplate;
import org.jboss.logging.Logger;
@Path("/fop")
@@ -33,19 +39,27 @@ public class FopResource {
private static final Logger LOG = Logger.getLogger(FopResource.class);
- private static final String COMPONENT_FOP = "fop";
@Inject
- CamelContext context;
-
- @Path("/load/component/fop")
- @GET
- @Produces(MediaType.TEXT_PLAIN)
- public Response loadComponentFop() throws Exception {
- /* This is an autogenerated test */
- if (context.getComponent(COMPONENT_FOP) != null) {
- return Response.ok().build();
+ ProducerTemplate producerTemplate;
+
+ @Inject
+ ConsumerTemplate consumerTemplate;
+
+ @Path("/post")
+ @POST
+ @Consumes(MediaType.APPLICATION_XML)
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ public Response post(String message, @QueryParam("userConfigURL") String userConfigURL) throws Exception {
+ LOG.infof("Sending to fop: %s", message);
+ String endpointUri = userConfigURL == null ? "fop:pdf" : "fop:application/pdf?userConfigURL=" + userConfigURL;
+ try (InputStream response = producerTemplate.requestBody(
+ endpointUri, message, InputStream.class)) {
+ LOG.info("Got response from fop.");
+ return Response
+ .created(new URI("https://camel.apache.org/"))
+ .entity(response)
+ .build();
}
- LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_FOP);
- return Response.status(500, COMPONENT_FOP + " could not be loaded from the Camel context").build();
+
}
}
diff --git a/extensions-jvm/fop/integration-test/src/test/java/org/apache/camel/quarkus/component/fop/it/FopTest.java b/integration-tests/fop/src/test/java/org/apache/camel/quarkus/component/fop/it/FopIT.java
similarity index 71%
rename from extensions-jvm/fop/integration-test/src/test/java/org/apache/camel/quarkus/component/fop/it/FopTest.java
rename to integration-tests/fop/src/test/java/org/apache/camel/quarkus/component/fop/it/FopIT.java
index b8ed067..94dce28 100644
--- a/extensions-jvm/fop/integration-test/src/test/java/org/apache/camel/quarkus/component/fop/it/FopTest.java
+++ b/integration-tests/fop/src/test/java/org/apache/camel/quarkus/component/fop/it/FopIT.java
@@ -16,19 +16,9 @@
*/
package org.apache.camel.quarkus.component.fop.it;
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
+import io.quarkus.test.junit.NativeImageTest;
-@QuarkusTest
-class FopTest {
-
- @Test
- public void loadComponentFop() {
- /* A simple autogenerated test */
- RestAssured.get("/fop/load/component/fop")
- .then()
- .statusCode(200);
- }
+@NativeImageTest
+class FopIT extends FopTest {
}
diff --git a/integration-tests/fop/src/test/java/org/apache/camel/quarkus/component/fop/it/FopTest.java b/integration-tests/fop/src/test/java/org/apache/camel/quarkus/component/fop/it/FopTest.java
new file mode 100644
index 0000000..25827be
--- /dev/null
+++ b/integration-tests/fop/src/test/java/org/apache/camel/quarkus/component/fop/it/FopTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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.fop.it;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.function.Function;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import io.restassured.response.ExtractableResponse;
+import io.restassured.specification.RequestSpecification;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.text.PDFTextStripper;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+@QuarkusTest
+class FopTest {
+
+ public static final String MSG = "hello";
+
+ @Test
+ public void convertToPdf() throws IOException {
+ convertToPdf(msg -> decorateTextWithXSLFO(msg, null), null);
+ }
+
+ @Test
+ public void convertToPdfWithCustomFont() throws IOException {
+ convertToPdf(msg -> decorateTextWithXSLFO(msg, "Freedom"), "/mycfg.xml");
+ }
+
+ private void convertToPdf(Function<String, String> msgCreator, String userConfigFile) throws IOException {
+ RequestSpecification requestSpecification = RestAssured.given()
+ .contentType(ContentType.XML);
+ if (userConfigFile != null) {
+ requestSpecification.queryParam("userConfigURL", "file:" + getClass().getResource(userConfigFile).getFile());
+ }
+ ExtractableResponse response = requestSpecification
+ .body(msgCreator.apply(MSG))
+ .post("/fop/post") //
+ .then()
+ .statusCode(201)
+ .extract();
+
+ PDDocument document = getDocumentFrom(response.asInputStream());
+ String content = extractTextFrom(document);
+ assertEquals(MSG, content);
+ }
+
+ public static String decorateTextWithXSLFO(String text, String font) {
+ String foBlock = font == null ? " <fo:block>" + text + "</fo:block>\n"
+ : " <fo:block font-family=\"" + font + "\">" + text + "</fo:block>\n";
+ return "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">\n"
+ + " <fo:layout-master-set>\n"
+ + " <fo:simple-page-master master-name=\"only\">\n"
+ + " <fo:region-body region-name=\"xsl-region-body\" margin=\"0.7in\" padding=\"0\" />\n"
+ + " <fo:region-before region-name=\"xsl-region-before\" extent=\"0.7in\" />\n"
+ + " <fo:region-after region-name=\"xsl-region-after\" extent=\"0.7in\" />\n"
+ + " </fo:simple-page-master>\n"
+ + " </fo:layout-master-set>\n"
+ + " <fo:page-sequence master-reference=\"only\">\n"
+ + " <fo:flow flow-name=\"xsl-region-body\">\n"
+ + foBlock
+ + " </fo:flow>\n"
+ + " </fo:page-sequence>\n"
+ + "</fo:root>";
+ }
+
+ private PDDocument getDocumentFrom(InputStream inputStream) throws IOException {
+ return PDDocument.load(inputStream);
+ }
+
+ private String extractTextFrom(PDDocument document) throws IOException {
+ Writer output = new StringWriter();
+ PDFTextStripper stripper = new PDFTextStripper();
+ stripper.writeText(document, output);
+ return output.toString().trim();
+ }
+}
diff --git a/integration-tests/fop/src/test/resources/Freedom-10eM.ttf b/integration-tests/fop/src/test/resources/Freedom-10eM.ttf
new file mode 100644
index 0000000..39b6f40
Binary files /dev/null and b/integration-tests/fop/src/test/resources/Freedom-10eM.ttf differ
diff --git a/integration-tests/fop/src/test/resources/mycfg.xml b/integration-tests/fop/src/test/resources/mycfg.xml
new file mode 100644
index 0000000..49586ef
--- /dev/null
+++ b/integration-tests/fop/src/test/resources/mycfg.xml
@@ -0,0 +1,33 @@
+<!--
+
+ 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.
+
+-->
+<fop version="1.0">
+ <use-cache>false</use-cache>
+ <renderers>
+ <renderer mime="application/pdf">
+ <fonts>
+ <font
+ kerning="yes"
+ embed-url="Freedom-10eM.ttf">
+ <font-triplet name="Freedom" style="normal" weight="normal" />
+ </font>
+ </fonts>
+ </renderer>
+ </renderers>
+
+</fop>
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 722472e..ac739e5 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -89,6 +89,7 @@
<module>fhir</module>
<module>file</module>
<module>flatpack</module>
+ <module>fop</module>
<module>ftp</module>
<module>git</module>
<module>github</module>
diff --git a/pom.xml b/pom.xml
index 61699b3..fad2cc6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -100,6 +100,7 @@
<istack-commons-runtime.version>3.0.10</istack-commons-runtime.version>
<jakarta.mail.version>1.6.5</jakarta.mail.version>
<mock-javamail.version>1.9</mock-javamail.version>
+ <pdfbox.version>2.0.21</pdfbox.version>
<sshd.version>2.3.0</sshd.version>
<stax2.version>4.2</stax2.version>
<testcontainers.version>1.14.3</testcontainers.version>
diff --git a/poms/bom-test/pom.xml b/poms/bom-test/pom.xml
index d519781..9a9b830 100644
--- a/poms/bom-test/pom.xml
+++ b/poms/bom-test/pom.xml
@@ -105,6 +105,11 @@
<version>${ftpserver.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.pdfbox</groupId>
+ <artifactId>pdfbox</artifactId>
+ <version>${pdfbox.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-sftp</artifactId>
<version>${sshd.version}</version>
diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml
index cbcef00..dc7a041 100644
--- a/tooling/scripts/test-categories.yaml
+++ b/tooling/scripts/test-categories.yaml
@@ -97,6 +97,7 @@ messaging-networking1:
- vertx-websocket
misc:
- braintree
+ - fop
- jolt
- mustache
- pdf