Skip to content

Commit

Permalink
[resolves wildfly-extras#1997] Add support for component fop
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Sep 20, 2017
1 parent e570584 commit 2807233
Show file tree
Hide file tree
Showing 19 changed files with 630 additions and 3 deletions.
2 changes: 1 addition & 1 deletion catalog/src/main/resources/component.roadmap
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ exec
facebook
file
flatpack
fop
freemarker
ftp
ftps
Expand Down Expand Up @@ -193,7 +194,6 @@ cometd #1990
cometds #1991
consul #1992
ehcache #1995
fop #1997
ganglia #1998
geocoder #1999
grape #2001
Expand Down
3 changes: 3 additions & 0 deletions docs/guide/components/camel-fop.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### camel-fop

The http://camel.apache.org/fop.html[FOP,window=_blank] component allows you to render a message into different output formats using http://xmlgraphics.apache.org/fop/index.html[Apache FOP,window=_blank].
2 changes: 2 additions & 0 deletions docs/guide/components/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ include::camel-facebook.adoc[]

include::camel-file2.adoc[]

include::camel-fop.adoc[]

include::camel-freemarker.adoc[]

include::camel-ftp.adoc[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<module name="org.apache.camel.component.exec" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.facebook" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.flatpack" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.fop" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.ftp" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.freemarker" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.git" export="true" services="export" optional="true" />
Expand Down
21 changes: 21 additions & 0 deletions feature/pack/etc/smartics/camel-modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,27 @@
</exports>
</module>

<module name="org.apache.camel.component.fop">
<include artifact="org.apache.camel:camel-fop" />
<apply-to-dependencies skip="true">
<include module="org.apache.camel.apt" />
<include module="org.springframework.boot" />
</apply-to-dependencies>
<dependencies>
<module name="javax.api"/>
<module name="org.apache.xmlgraphics" export="true">
<exports>
<exclude path="org/apache/batik**" />
<exclude path="org/apache/fop/servlet**" />
<exclude path="org/apache/fop/tools**" />
<exclude path="org/apache/xmlgraphics/image/writer/internal**" />
<exclude path="org/w3c**" />
</exports>
</module>
<module name="org.slf4j" />
</dependencies>
</module>

<module name="org.apache.camel.component.freemarker">
<include artifact="org.apache.camel:camel-freemarker" />
<include artifact="org.freemarker:freemarker" />
Expand Down
44 changes: 44 additions & 0 deletions feature/pack/etc/smartics/other-modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,20 @@
</dependencies>
</module>

<module name="org.apache.avalon.framework">
<properties>
<property name="jboss.api" value="private"/>
</properties>
<apply-to-dependencies skip="true">
<include module="org.apache.avalon.logkit" />
</apply-to-dependencies>
<include artifact="org.apache.avalon.framework:avalon-framework-api" />
<include artifact="org.apache.avalon.framework:avalon-framework-impl" />
<dependencies>
<module name="javax.api" />
</dependencies>
</module>

<module name="org.apache.commons.compress">
<properties>
<property name="jboss.api" value="private"/>
Expand Down Expand Up @@ -976,6 +990,36 @@
</dependencies>
</module>

<module name="org.apache.xmlgraphics">
<properties>
<property name="jboss.api" value="private"/>
</properties>
<apply-to-dependencies skip="true">
<include module="xml-apis" />
</apply-to-dependencies>
<include artifact="org.apache.xmlgraphics:batik-anim" />
<include artifact="org.apache.xmlgraphics:batik-awt-util" />
<include artifact="org.apache.xmlgraphics:batik-bridge" />
<include artifact="org.apache.xmlgraphics:batik-css" />
<include artifact="org.apache.xmlgraphics:batik-dom" />
<include artifact="org.apache.xmlgraphics:batik-ext" />
<include artifact="org.apache.xmlgraphics:batik-extension" />
<include artifact="org.apache.xmlgraphics:batik-gvt" />
<include artifact="org.apache.xmlgraphics:batik-parser" />
<include artifact="org.apache.xmlgraphics:batik-script" />
<include artifact="org.apache.xmlgraphics:batik-svg-dom" />
<include artifact="org.apache.xmlgraphics:batik-svggen" />
<include artifact="org.apache.xmlgraphics:batik-transcoder" />
<include artifact="org.apache.xmlgraphics:batik-util" />
<include artifact="org.apache.xmlgraphics:batik-xml" />
<include artifact="org.apache.xmlgraphics:fop" />
<include artifact="org.apache.xmlgraphics:xmlgraphics-commons" />
<dependencies>
<module name="javax.api" />
<module name="org.apache.avalon.framework" />
</dependencies>
</module>

<module name="org.apache.zookeeper">
<properties>
<property name="jboss.api" value="private"/>
Expand Down
12 changes: 10 additions & 2 deletions feature/pack/etc/smartics/skipped-modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@
<module name="org.apache.aries.blueprint" skip="true">
<include artifact="org.apache.aries.blueprint:(.*)" />
</module>


<module name="org.apache.avalon.logkit" skip="true">
<include artifact="org.apache.avalon.logkit:avalon-logkit" />
</module>

<module name="org.apache.avro.ipc" skip="true">
<include artifact="org.apache.avro:avro-ipc" />
</module>
Expand Down Expand Up @@ -378,5 +382,9 @@
<module name="software.amazon.ion.ion-java" skip="true">
<include artifact="software.amazon.ion:ion-java" />
</module>


<module name="xml-apis" skip="true">
<include artifact=":xml-apis-ext" />
</module>

</modules>
4 changes: 4 additions & 0 deletions feature/pack/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-flatpack</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-fop</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-freemarker</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.apache.avalon.framework">
<properties>
<property name="jboss.api" value="private" />
</properties>
<resources>
<artifact name="${org.apache.avalon.framework:avalon-framework-api}" />
<artifact name="${org.apache.avalon.framework:avalon-framework-impl}" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="org.apache.commons.logging" />
<module name="org.apache.log4j" />
</dependencies>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.apache.camel.component.fop">
<resources>
<artifact name="${org.apache.camel:camel-fop}" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="org.apache.xmlgraphics" export="true">
<exports>
<exclude path="org/apache/batik**" />
<exclude path="org/apache/fop/servlet**" />
<exclude path="org/apache/fop/tools**" />
<exclude path="org/apache/xmlgraphics/image/writer/internal**" />
<exclude path="org/w3c**" />
</exports>
</module>
<module name="org.slf4j" />
<module name="javax.xml.bind.api" />
<module name="org.apache.avalon.framework" />
<module name="org.apache.camel.core" />
</dependencies>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<module name="org.apache.camel.component.exec" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.facebook" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.flatpack" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.fop" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.ftp" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.freemarker" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.git" export="true" services="export" optional="true" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.apache.xmlgraphics">
<properties>
<property name="jboss.api" value="private" />
</properties>
<resources>
<artifact name="${org.apache.xmlgraphics:batik-anim}" />
<artifact name="${org.apache.xmlgraphics:batik-awt-util}" />
<artifact name="${org.apache.xmlgraphics:batik-bridge}" />
<artifact name="${org.apache.xmlgraphics:batik-css}" />
<artifact name="${org.apache.xmlgraphics:batik-dom}" />
<artifact name="${org.apache.xmlgraphics:batik-ext}" />
<artifact name="${org.apache.xmlgraphics:batik-extension}" />
<artifact name="${org.apache.xmlgraphics:batik-gvt}" />
<artifact name="${org.apache.xmlgraphics:batik-parser}" />
<artifact name="${org.apache.xmlgraphics:batik-script}" />
<artifact name="${org.apache.xmlgraphics:batik-svg-dom}" />
<artifact name="${org.apache.xmlgraphics:batik-svggen}" />
<artifact name="${org.apache.xmlgraphics:batik-transcoder}" />
<artifact name="${org.apache.xmlgraphics:batik-util}" />
<artifact name="${org.apache.xmlgraphics:batik-xml}" />
<artifact name="${org.apache.xmlgraphics:fop}" />
<artifact name="${org.apache.xmlgraphics:xmlgraphics-commons}" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="org.apache.avalon.framework" />
<module name="javax.servlet.api" />
<module name="org.apache.commons.io" />
<module name="org.apache.commons.logging" />
<module name="org.apache.xalan" />
<module name="org.apache.xerces" />
</dependencies>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* #%L
* Wildfly Camel :: Testsuite
* %%
* Copyright (C) 2013 - 2017 RedHat
* %%
* Licensed 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.
* #L%
*/
package org.wildfly.camel.test.fop;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.net.URI;
import java.nio.file.Paths;

import javax.naming.InitialContext;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.fop.apps.FopFactory;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.gravia.resource.ManifestBuilder;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.extension.camel.CamelAware;

@CamelAware
@RunWith(Arquillian.class)
public class FopIntegrationTest {

@ArquillianResource
private InitialContext initialContext;

@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class, "camel-fop-tests.jar")
.addAsResource("fop/data.xml", "data.xml")
.addAsResource("fop/template.xsl", "template.xsl")
.addAsResource("fop/factory.xml", "factory.xml")
.setManifest(() -> {
ManifestBuilder builder = new ManifestBuilder();
builder.addManifestHeader("Dependencies", "org.apache.pdfbox");
return builder.openStream();
});
}

@Test
public void testFopComponent() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.to("xslt:template.xsl")
.setHeader("foo", constant("bar"))
.to("fop:pdf")
.setHeader(Exchange.FILE_NAME, constant("resultA.pdf"))
.to("file:{{jboss.server.data.dir}}/fop")
.to("mock:result");
}
});

MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class);
mockEndpoint.expectedMessageCount(1);

camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
template.sendBody("direct:start", FopIntegrationTest.class.getResourceAsStream("/data.xml"));

mockEndpoint.assertIsSatisfied();

String dataDir = System.getProperty("jboss.server.data.dir");
PDDocument document = PDDocument.load(Paths.get(dataDir, "fop", "resultA.pdf").toFile());
String pdfText = extractTextFromDocument(document);
Assert.assertTrue(pdfText.contains("Project"));
Assert.assertTrue(pdfText.contains("John Doe"));
} finally {
camelctx.stop();
}
}

@Test
public void testFopComponentWithCustomFactory() throws Exception {
FopFactory fopFactory = FopFactory.newInstance(new URI("/"), FopIntegrationTest.class.getResourceAsStream("/factory.xml"));
initialContext.bind("fopFactory", fopFactory);

CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.to("xslt:template.xsl")
.setHeader("foo", constant("bar"))
.to("fop:pdf?fopFactory=#fopFactory")
.setHeader(Exchange.FILE_NAME, constant("resultB.pdf"))
.to("file:{{jboss.server.data.dir}}/fop")
.to("mock:result");
}
});

MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class);
mockEndpoint.expectedMessageCount(1);

camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
template.sendBody("direct:start", FopIntegrationTest.class.getResourceAsStream("/data.xml"));

mockEndpoint.assertIsSatisfied();

String dataDir = System.getProperty("jboss.server.data.dir");
PDDocument document = PDDocument.load(Paths.get(dataDir, "fop", "resultB.pdf").toFile());
String pdfText = extractTextFromDocument(document);
Assert.assertTrue(pdfText.contains("Project"));
Assert.assertTrue(pdfText.contains("John Doe"));
} finally {
camelctx.stop();
initialContext.unbind("fopFactory");
}
}

private String extractTextFromDocument(PDDocument document) throws IOException {
Writer output = new StringWriter();
PDFTextStripper stripper = new PDFTextStripper();
stripper.writeText(document, output);
return output.toString().trim();
}
}
Loading

0 comments on commit 2807233

Please sign in to comment.