You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/08/28 09:23:50 UTC
[camel] 01/03: Add Any23 dataformat example.
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 6c938273902ceec5aee2dcab47eeeac0acf1bcab
Author: Roberto Flores <be...@gmail.com>
AuthorDate: Thu Aug 22 17:24:51 2019 -0500
Add Any23 dataformat example.
---
examples/README.adoc | 4 +-
examples/camel-example-any23/README.adoc | 23 ++++++
examples/camel-example-any23/pom.xml | 66 ++++++++++++++++++
.../camel/example/any23/Any23RouteBuilder.java | 81 ++++++++++++++++++++++
.../camel/example/any23/Any23StartupMessage.java | 34 +++++++++
.../apache/camel/example/any23/Application.java | 35 ++++++++++
examples/pom.xml | 1 +
7 files changed, 243 insertions(+), 1 deletion(-)
diff --git a/examples/README.adoc b/examples/README.adoc
index 753a8e7..9e64415 100644
--- a/examples/README.adoc
+++ b/examples/README.adoc
@@ -11,7 +11,7 @@ View the individual example READMEs for details.
== Examples
// examples: START
-Number of Examples: 114 (0 deprecated)
+Number of Examples: 115 (0 deprecated)
[width="100%",cols="4,2,4",options="header"]
|===
@@ -19,6 +19,8 @@ Number of Examples: 114 (0 deprecated)
| link:camel-example-as2/README.md[As2] (camel-example-as2) | | An example which demonstrates the use of the Camel AS2 component
+| link:camel-example-any23/README.md[Any23] (camel-example-any23) | | An example which demonstrates the use of the Camel Any23 dataformat
+
| link:camel-example-bigxml-split/README.md[Bigxml Split] (camel-example-bigxml-split) | | How to deal with big XML files in Camel
| link:camel-example-jira/README.adoc[Jira] (camel-example-jira) | | An example that uses Jira Camel API
diff --git a/examples/camel-example-any23/README.adoc b/examples/camel-example-any23/README.adoc
new file mode 100644
index 0000000..2945073
--- /dev/null
+++ b/examples/camel-example-any23/README.adoc
@@ -0,0 +1,23 @@
+= Apache Any23 Example
+
+This example shows how to extract data from a page with RDF content using Apache Any23. In this example the Dbpedia webpage of a country (Ecuador) is processed with the camel-any23 dataformat as a RDF4J Model.
+The extracted information is filtered in order to select the URIS of the country's leaders through the Dbpedia property http://dbpedia.org/ontology/leader .
+Afterwards, the information of each leader is requested and presented in JSON-LD format.
+
+== How to run
+
+You can run this example using
+
+ mvn compile exec:java
+
+== More information about the camel-any23 Dataformat.
+
+You can find more information about camel-any23 at the website: https://github.com/apache/camel/blob/master/components/camel-any23/src/main/docs/any23-dataformat.adoc
+
+== More information about Apache Any23
+
+You can find more information about Apache Any23 at the website: https://any23.apache.org
+
+== More information about Apache Camel
+
+You can find more information about Apache Camel at the website: http://camel.apache.org/
diff --git a/examples/camel-example-any23/pom.xml b/examples/camel-example-any23/pom.xml
new file mode 100644
index 0000000..45f931e
--- /dev/null
+++ b/examples/camel-example-any23/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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.example</groupId>
+ <artifactId>examples</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-example-any23</artifactId>
+ <name>Camel :: Example :: Any23</name>
+ <description>An example that uses the Any23 dataformat</description>
+ <packaging>jar</packaging>
+
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <camel.version>3.0.0-SNAPSHOT</camel.version>
+ </properties>
+
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-http</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-management-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-any23</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jsonpath</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>${exec-maven-plugin-version}</version>
+ <configuration>
+ <mainClass>org.apache.camel.example.any23.Application</mainClass>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git a/examples/camel-example-any23/src/main/java/org/apache/camel/example/any23/Any23RouteBuilder.java b/examples/camel-example-any23/src/main/java/org/apache/camel/example/any23/Any23RouteBuilder.java
new file mode 100644
index 0000000..272164f
--- /dev/null
+++ b/examples/camel-example-any23/src/main/java/org/apache/camel/example/any23/Any23RouteBuilder.java
@@ -0,0 +1,81 @@
+/*
+ * 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.example.any23;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.dataformat.Any23Type;
+import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.Model;
+import org.eclipse.rdf4j.model.Value;
+import org.eclipse.rdf4j.model.ValueFactory;
+import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
+
+public class Any23RouteBuilder extends RouteBuilder {
+
+ private static final String BASEURI = "http://mock.foo/bar";
+
+ @Override
+ public void configure() {
+
+ from("direct:start")
+ .log("Querying dbpedia:Ecuador ")
+ .to("http://dbpedia.org/page/Ecuador")
+ .unmarshal()
+ .any23(BASEURI)
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ ValueFactory vf = SimpleValueFactory.getInstance();
+ Model model = (Model) exchange.getIn().getBody();
+
+ //Selecting the leaders of Ecuador
+ IRI propertyLeader = vf.createIRI("http://dbpedia.org/ontology/leader");
+ Set<Value> leadersResources = model.filter(null, propertyLeader, null).objects();
+ List<String> leadersList = new ArrayList<>();
+ for (Value leader : leadersResources) {
+ // Transform the leader resource (URI) into an broweable URL.
+ // For instance:
+ // http://dbpedia.org/resource/Oswaldo_Guayasam%C3%ADn --> http://dbpedia.org/page/Oswaldo_Guayasam%C3%ADn
+ String aLeader = leader.stringValue().replace("resource", "page");
+ leadersList.add(aLeader);
+ }
+ exchange.getIn().setBody(leadersList);
+
+ }
+ })
+ .log(" Content: ${body} ")
+ //Process each leader in a separate route.
+ //In order to extract more information.
+ .split(simple("${body}"))
+ .to("direct:extractMoreData");
+
+ from("direct:extractMoreData")
+ .log("Split ${body}")
+ .convertBodyTo(String.class)
+ .toD("${body}")
+ .unmarshal()
+ //Extract RDF data of the leaders as JSONLD
+ .any23(BASEURI, Any23Type.JSONLD)
+ .log(" Result : ${body} ")
+ .to("mock:result");
+ }
+
+}
diff --git a/examples/camel-example-any23/src/main/java/org/apache/camel/example/any23/Any23StartupMessage.java b/examples/camel-example-any23/src/main/java/org/apache/camel/example/any23/Any23StartupMessage.java
new file mode 100644
index 0000000..94cd012
--- /dev/null
+++ b/examples/camel-example-any23/src/main/java/org/apache/camel/example/any23/Any23StartupMessage.java
@@ -0,0 +1,34 @@
+/*
+ * 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.example.any23;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.StartupListener;
+
+public class Any23StartupMessage implements StartupListener {
+
+ public Any23StartupMessage() {
+ }
+
+ @Override
+ public void onCamelContextStarted(CamelContext context, boolean alreadyStarted) throws Exception {
+ ProducerTemplate template = context.createProducerTemplate();
+ template.sendBody("direct:start", "This is a test message to run the example");
+ }
+
+}
diff --git a/examples/camel-example-any23/src/main/java/org/apache/camel/example/any23/Application.java b/examples/camel-example-any23/src/main/java/org/apache/camel/example/any23/Application.java
new file mode 100644
index 0000000..2089f13
--- /dev/null
+++ b/examples/camel-example-any23/src/main/java/org/apache/camel/example/any23/Application.java
@@ -0,0 +1,35 @@
+/*
+ * 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.example.any23;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+
+public class Application {
+
+ public static void main(String[] args) throws Exception {
+ System.out.println("Camel is started. Ready to run Any23 example!");
+
+ CamelContext context = new DefaultCamelContext();
+ context.start();
+
+ context.addRoutes(new Any23RouteBuilder());
+ context.addStartupListener(new Any23StartupMessage());
+
+ }
+
+}
diff --git a/examples/pom.xml b/examples/pom.xml
index 428a001..8339cf3 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -38,6 +38,7 @@
<modules>
<module>camel-example-activemq-tomcat</module>
<module>camel-example-aggregate</module>
+ <module>camel-example-any23</module>
<module>camel-example-artemis</module>
<module>camel-example-artemis-amqp-blueprint</module>
<module>camel-example-artemis-large-messages</module>