From 998e2e821b0d7fda84df0e3e8edb15546f4bbd09 Mon Sep 17 00:00:00 2001 From: Wim Verreydt Date: Tue, 9 Apr 2013 10:40:36 +0200 Subject: [PATCH] Add camel-sql-derby example and update maven bundle plugin version --- .../src/main/filtered-resources/features.xml | 8 + examples/camel/camel-sql-derby/README.txt | 195 ++++++++++++++++++ .../camel-sql-derby-datasource/pom.xml | 59 ++++++ .../examples/camel/sql/DatabaseBean.java | 51 +++++ .../OSGI-INF/blueprint/blueprint.xml | 44 ++++ .../camel-sql-derby-orders/pom.xml | 51 +++++ .../examples/camel/sql/OrderBean.java | 66 ++++++ .../OSGI-INF/blueprint/blueprint.xml | 56 +++++ .../src/main/resources/sql.properties | 29 +++ examples/camel/camel-sql-derby/pom.xml | 37 ++++ examples/camel/pom.xml | 1 + pom.xml | 4 +- 12 files changed, 600 insertions(+), 1 deletion(-) create mode 100644 examples/camel/camel-sql-derby/README.txt create mode 100644 examples/camel/camel-sql-derby/camel-sql-derby-datasource/pom.xml create mode 100644 examples/camel/camel-sql-derby/camel-sql-derby-datasource/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBean.java create mode 100644 examples/camel/camel-sql-derby/camel-sql-derby-datasource/src/main/resources/OSGI-INF/blueprint/blueprint.xml create mode 100644 examples/camel/camel-sql-derby/camel-sql-derby-orders/pom.xml create mode 100644 examples/camel/camel-sql-derby/camel-sql-derby-orders/src/main/java/org/apache/servicemix/examples/camel/sql/OrderBean.java create mode 100644 examples/camel/camel-sql-derby/camel-sql-derby-orders/src/main/resources/OSGI-INF/blueprint/blueprint.xml create mode 100644 examples/camel/camel-sql-derby/camel-sql-derby-orders/src/main/resources/sql.properties create mode 100644 examples/camel/camel-sql-derby/pom.xml diff --git a/assemblies/apache-servicemix/src/main/filtered-resources/features.xml b/assemblies/apache-servicemix/src/main/filtered-resources/features.xml index b09e73a..53ca061 100644 --- a/assemblies/apache-servicemix/src/main/filtered-resources/features.xml +++ b/assemblies/apache-servicemix/src/main/filtered-resources/features.xml @@ -72,6 +72,14 @@ mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient/${commons-httpclient.bundle.version} mvn:org.apache.servicemix.examples/cxf-jaxws-blueprint/${version} + + camel-sql + camel-jms + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/${commons-dbcp.bundle.version} + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.derby/${derby.bundle.version} + mvn:org.apache.servicemix.examples/camel-sql-derby-datasource/${version} + mvn:org.apache.servicemix.examples/camel-sql-derby-orders/${version} + camel mvn:org.apache.servicemix.examples/camel-osgi/${version} diff --git a/examples/camel/camel-sql-derby/README.txt b/examples/camel/camel-sql-derby/README.txt new file mode 100644 index 0000000..08754e1 --- /dev/null +++ b/examples/camel/camel-sql-derby/README.txt @@ -0,0 +1,195 @@ +/* + * 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. + */ + +CAMEL SQL EXAMPLE +================= + +Purpose +------- +Deploys a Camel EIP route that uses a database to store messages after +receiving. A second route illustrates how to read messages from the database +in order to process them. + + +Explanation +----------- +The example exists of two modules: + +- Camel-Sql-Derby-Datasource + + This module creates an in-memory Derby database utilizing a + BasicDataSource bean. The Database bean takes care of the table + creation and the graceful shutdown of the database connection. + + The datasource is exposed as a OSGI service so it can be referenced + in other OSGI bundles. + +- Camel-Sql-Derby-Orders + + The Orders module has two Camel routes defined in a Blueprint XML + file. Both routes use the camel-sql feature and some predefined queries + which are located in the sql.properties file. The datasource is referenced + from the service we exposed in the first module. + + The first route periodically creates a random order using the OrderBean + and submits it to the database. The route also logs every oder to the + Servicemix log. It displays the item-name from the order, for example: + + | Inserted new order of Gummi bears + + The second route consumes the unconsumed orders from the database + and processes them using the OrderBean. The result is logged to the + Servicemix log. For example: + + | {ID=10, ITEM=Gummi bears, AMOUNT=46, CONSUMED=false, + description=The red ones are the cutest [PROCESSED], processed=true} + +Both modules are deployed in an OSGi bundle. + + +Prerequisites for Running the Example +------------------------------------- +1. You must have the following installed on your machine: + + - JDK 1.6 or higher + + - Maven 2.2.1 or higher (for building) + + For more information, see the README in the top-level examples + directory. + +2. This example requires some additional configuration to allow + the JVM to use more PermGen memory: + + export JAVA_MAX_PERM_MEM=128m (on UNIX) + set JAVA_MAX_PERM_MEM=128m (on Windows) + +3. Start ServiceMix by running the following command: + + /bin/servicemix (on UNIX) + \bin\servicemix (on Windows) + + +Running the Example +------------------- +You can run the example in two ways: + +- A. Using a Prebuilt Deployment Bundle: Quick and Easy + This option is useful if you want to see the example up and + running quickly. + +- B. Building the Example Bundle Yourself + This option is useful if you want to change the example in any way. + It tells you how to build and deploy the example. This option might + be slower than option A because, if you do not already have the + required bundles in your local Maven repository, Maven will have to + download the bundles it needs. + + +A. Using a Prebuilt Deployment Bundle: Quick and Easy +----------------------------------------------------- +To install and run a prebuilt version of this example, enter the +following command in the ServiceMix console: + + features:install examples-camel-sql-derby + +This command makes use of the ServiceMix features facility. For more +information about the features facility, see the README.txt file in the +examples parent directory. + +Once the example is running, periodic events are routed to the +generateOrder-route which crates routes en sends them to the database. +The processOrder-route picks those orders from the database and +processes them. You should see a similar log output: + + | Inserted a new order of Cookies + | {ID=8, ITEM=Cookies, AMOUNT=35, CONSUMED=false, + description=Grandma's recipe and fresh from the bakery! [PROCESSED], processed=true} + + +B. Building the Example Bundle Yourself +--------------------------------------- +To install and run the example where you build the example bundle +yourself, complete the following steps: + +1. If you have already run the example using the prebuilt version as + described above, you must first uninstall the examples-camel-sql-derby + feature by entering the following command in the ServiceMix console: + + features:uninstall examples-camel-sql-derby + +2. Build the example by opening a command prompt, changing directory to + examples/camel/camel-sql-derby (this example) and entering the following Maven + command: + + mvn install + + If all of the required OSGi bundles are available in your local Maven + repository, the example will build very quickly. Otherwise it may + take some time for Maven to download everything it needs. + + The mvn install command builds the example deployment bundle and + copies it to your local Maven repository and to the target directory + of this example. + +3. Install the example by entering the following command in + the ServiceMix console: + + features:install examples-camel-sql-derby + + It makes use of the ServiceMix features facility. For more information + about the features facility, see the README.txt file in the examples + parent directory. + +Once the example is running, periodic events are routed to the +generateOrder-route which crates routes en sends them to the database. +The processOrder-route picks those orders from the database and +processes them. You should see a similar log output: + + | Inserted a new order of Cookies + | {ID=8, ITEM=Cookies, AMOUNT=35, CONSUMED=false, + description=Grandma's recipe and fresh from the bakery! [PROCESSED], processed=true} + + +Stopping and Uninstalling the Example +------------------------------------- +To stop the example, enter the following command in the ServiceMix +console: + + osgi:stop + +For information on how to find the bundle_id assigned to the example, +see step 3 in the "Updating and Redeploying the Properties File +from the Console" section above. + +To uninstall the example, enter one of the following commands in +the ServiceMix console: + + features:uninstall examples-camel-sql-derby + +or + + osgi:uninstall + + +Viewing the Log Entries +----------------------- +You can view the entries in the log file in the data/log +directory of your ServiceMix installation, or by typing +the following command in the ServiceMix console: + + log:display diff --git a/examples/camel/camel-sql-derby/camel-sql-derby-datasource/pom.xml b/examples/camel/camel-sql-derby/camel-sql-derby-datasource/pom.xml new file mode 100644 index 0000000..4110395 --- /dev/null +++ b/examples/camel/camel-sql-derby/camel-sql-derby-datasource/pom.xml @@ -0,0 +1,59 @@ + + + + + + + camel-sql-derby + org.apache.servicemix.examples + 5.0.0-SNAPSHOT + + 4.0.0 + + camel-sql-derby-datasource + bundle + Apache ServiceMix :: Examples :: Camel Sql Derby :: Datasource + Camel Example using sql + + + + + org.apache.felix + maven-bundle-plugin + + + ${project.artifactId} + ${project.description} + * + org.apache.servicemix.examples.camel.sql + + + + + + + + org.slf4j + slf4j-api + 1.6.6 + + + + + \ No newline at end of file diff --git a/examples/camel/camel-sql-derby/camel-sql-derby-datasource/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBean.java b/examples/camel/camel-sql-derby/camel-sql-derby-datasource/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBean.java new file mode 100644 index 0000000..b29259b --- /dev/null +++ b/examples/camel/camel-sql-derby/camel-sql-derby-datasource/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBean.java @@ -0,0 +1,51 @@ +/** + * 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.servicemix.examples.camel.sql; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.sql.DataSource; +import java.sql.SQLException; +import java.sql.Statement; + +public class DatabaseBean { + + private DataSource dataSource; + private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseBean.class); + + public DatabaseBean(){} + + public void setDataSource(DataSource dataSource) { + this.dataSource = dataSource; + } + + public void create() throws SQLException{ + Statement sta = dataSource.getConnection().createStatement(); + try { + sta.executeUpdate( + "CREATE TABLE orders (id INT generated by default as identity, item VARCHAR(50), amount INT, description VARCHAR(300), processed BOOLEAN, consumed BOOLEAN)"); + } catch (SQLException e) { + LOGGER.info("Table orders already exists"); + } + } + + public void destroy() throws SQLException { + dataSource.getConnection().close(); + } + + +} diff --git a/examples/camel/camel-sql-derby/camel-sql-derby-datasource/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/examples/camel/camel-sql-derby/camel-sql-derby-datasource/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 0000000..66a75cc --- /dev/null +++ b/examples/camel/camel-sql-derby/camel-sql-derby-datasource/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/camel/camel-sql-derby/camel-sql-derby-orders/pom.xml b/examples/camel/camel-sql-derby/camel-sql-derby-orders/pom.xml new file mode 100644 index 0000000..5303d51 --- /dev/null +++ b/examples/camel/camel-sql-derby/camel-sql-derby-orders/pom.xml @@ -0,0 +1,51 @@ + + + + + + + camel-sql-derby + org.apache.servicemix.examples + 5.0.0-SNAPSHOT + + 4.0.0 + + camel-sql-derby-orders + bundle + Apache ServiceMix :: Examples :: Camel Sql Derby:: Orders + Camel Example using sql + + + + + org.apache.felix + maven-bundle-plugin + + + ${project.artifactId} + ${project.description} + * + org.apache.servicemix.examples.camel.sql + + + + + + + \ No newline at end of file diff --git a/examples/camel/camel-sql-derby/camel-sql-derby-orders/src/main/java/org/apache/servicemix/examples/camel/sql/OrderBean.java b/examples/camel/camel-sql-derby/camel-sql-derby-orders/src/main/java/org/apache/servicemix/examples/camel/sql/OrderBean.java new file mode 100644 index 0000000..558aebe --- /dev/null +++ b/examples/camel/camel-sql-derby/camel-sql-derby-orders/src/main/java/org/apache/servicemix/examples/camel/sql/OrderBean.java @@ -0,0 +1,66 @@ +/** + * 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.servicemix.examples.camel.sql; + +import java.util.*; + +public class OrderBean { + + private Random random; + private static int itemnumber = 0; + private List> orders; + + + public OrderBean() { + random = new Random(); + } + + + public Map generateRandomOrder(){ + return orders.get(random.nextInt(orders.size()-1)); + } + + private static int getNextItemNumber(){ + return OrderBean.itemnumber++; + } + + public void processOrder(Map order){ + order.put("description",order.get("description")+" [PROCESSED]"); + order.put("processed",true); + + } + + + public void init(){ + orders = new ArrayList>(); + orders.add(createOrder("Cookies","Grandma's recipe and fresh from the bakery!",random.nextInt(50))); + orders.add(createOrder("Lollipops","Mix of different colors and flavours",random.nextInt(10))); + orders.add(createOrder("Gummi bears","The red ones are the cutest",random.nextInt(100))); + orders.add(createOrder("Skittles","Everybody loves rainbows",random.nextInt(800))); + } + + private Map createOrder(String item, String description, int amount){ + Map order = new HashMap(); + order.put("item",item); + order.put("description",description); + order.put("amount",amount); + return order; + } + + + +} diff --git a/examples/camel/camel-sql-derby/camel-sql-derby-orders/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/examples/camel/camel-sql-derby/camel-sql-derby-orders/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 0000000..b3e998c --- /dev/null +++ b/examples/camel/camel-sql-derby/camel-sql-derby-orders/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/camel/camel-sql-derby/camel-sql-derby-orders/src/main/resources/sql.properties b/examples/camel/camel-sql-derby/camel-sql-derby-orders/src/main/resources/sql.properties new file mode 100644 index 0000000..43fa0aa --- /dev/null +++ b/examples/camel/camel-sql-derby/camel-sql-derby-orders/src/main/resources/sql.properties @@ -0,0 +1,29 @@ +# +# 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. +# +# + +## notice we use named parameters in the queries, eg :#name. A named query parameter must start with :# +## sql that insert new orders +sql.insertOrder=insert into orders (item, amount, description, processed, consumed) values (:#item, :#amount, :#description, false, false) + +## sql that select all unprocessed orders +sql.selectOrder=select * from orders where consumed = false + +## sql that update the order as being processed +sql.markOrder=update orders set consumed = true where id = :#id \ No newline at end of file diff --git a/examples/camel/camel-sql-derby/pom.xml b/examples/camel/camel-sql-derby/pom.xml new file mode 100644 index 0000000..9fd3dc5 --- /dev/null +++ b/examples/camel/camel-sql-derby/pom.xml @@ -0,0 +1,37 @@ + + + + + + + camel-examples + org.apache.servicemix.examples + 5.0.0-SNAPSHOT + + 4.0.0 + + camel-sql-derby + pom + + camel-sql-derby-datasource + camel-sql-derby-orders + + + + \ No newline at end of file diff --git a/examples/camel/pom.xml b/examples/camel/pom.xml index f2d5dee..04b8027 100644 --- a/examples/camel/pom.xml +++ b/examples/camel/pom.xml @@ -36,6 +36,7 @@ camel-blueprint camel-osgi camel-drools + camel-sql-derby diff --git a/pom.xml b/pom.xml index cbf5afb..3e6f96a 100644 --- a/pom.xml +++ b/pom.xml @@ -158,12 +158,14 @@ 5.2_3 1.8.2_1 1.4 + 1.4_3 3.1_6 2.4_4 2.2 1.6 2.4 1.0_5 + 10.9.1.0_1 1.6.1_5 ${drools.version}_1-SNAPSHOT 1.2.7_3 @@ -203,7 +205,7 @@ 1.2 1.6 2.2.1 - 2.1.0 + 2.3.7 1.2.12