You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ks...@apache.org on 2015/05/27 00:14:06 UTC

[1/3] servicemix git commit: SM-2543: Provide Spring example for Drools 6 (closes #26)

Repository: servicemix
Updated Branches:
  refs/heads/master ae8a50de5 -> 8ae570000


SM-2543: Provide Spring example for Drools 6 (closes #26)

Thanks to Grzegorz Halajko for the pull request!!!


Project: http://git-wip-us.apache.org/repos/asf/servicemix/repo
Commit: http://git-wip-us.apache.org/repos/asf/servicemix/commit/c928d62f
Tree: http://git-wip-us.apache.org/repos/asf/servicemix/tree/c928d62f
Diff: http://git-wip-us.apache.org/repos/asf/servicemix/diff/c928d62f

Branch: refs/heads/master
Commit: c928d62f03a36441f7be364f4ff81adb15ee156b
Parents: ae8a50d
Author: Grzegorz Halajko <gh...@linuxpolska.pl>
Authored: Tue May 26 21:06:32 2015 +0200
Committer: Krzysztof Sobkowiak <kr...@gmail.com>
Committed: Tue May 26 23:19:04 2015 +0200

----------------------------------------------------------------------
 .../src/main/filtered-resources/examples.xml    |   5 +
 examples/drools/drools-spring/README.txt        | 106 +++++++++++++++
 examples/drools/drools-spring/pom.xml           |  73 ++++++++++
 .../examples/drools/spring/model/Customer.java  |  80 +++++++++++
 .../drools/spring/model/CustomerType.java       |  22 ++++
 .../spring/osgi/DebugAgendaEventListener.java   | 132 +++++++++++++++++++
 .../osgi/DebugRuleRuntimeEventListener.java     |  61 +++++++++
 .../drools/spring/osgi/SimpleRuleBean.java      |  83 ++++++++++++
 .../examples/drools/spring/osgi/Utils.java      |  37 ++++++
 .../resources/META-INF/spring/simple-spring.xml |  55 ++++++++
 .../src/main/resources/rule/customer-score.drl  |  48 +++++++
 examples/drools/pom.xml                         |   1 +
 .../itests/Drools6IntegrationTests.scala        |  16 +++
 13 files changed, 719 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/servicemix/blob/c928d62f/assembly/src/main/filtered-resources/examples.xml
----------------------------------------------------------------------
diff --git a/assembly/src/main/filtered-resources/examples.xml b/assembly/src/main/filtered-resources/examples.xml
index fe9ad22..8bfe111 100644
--- a/assembly/src/main/filtered-resources/examples.xml
+++ b/assembly/src/main/filtered-resources/examples.xml
@@ -172,4 +172,9 @@
         <bundle>mvn:org.apache.servicemix.examples/drools-camel-blueprint/${version}</bundle>
     </feature>
 
+    <feature name="examples-drools-spring" version="${version}" resolver="(obr)">
+        <feature version="${drools6.version}">kie-spring</feature>
+        <bundle>mvn:org.apache.servicemix.examples/drools-spring/${version}</bundle>
+    </feature>
+
 </features>

http://git-wip-us.apache.org/repos/asf/servicemix/blob/c928d62f/examples/drools/drools-spring/README.txt
----------------------------------------------------------------------
diff --git a/examples/drools/drools-spring/README.txt b/examples/drools/drools-spring/README.txt
new file mode 100644
index 0000000..f425fde
--- /dev/null
+++ b/examples/drools/drools-spring/README.txt
@@ -0,0 +1,106 @@
+/*
+ * 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.
+ */
+
+Drools 6 Simple Example
+==========================
+
+Purpose
+-------
+This example will show you how to use Drools 6 inside Apache ServiceMix and how to
+use rule engine with spring.
+
+
+Prerequisites for Running the Example
+-------------------------------------
+1. You must have the following installed on your machine:
+
+   - JDK 1.6 or higher
+
+   - Maven 3.0.2 or higher (for building)
+   
+  For more information, see the README in the top-level examples
+  directory.
+
+2. Start ServiceMix by running the following command:
+
+    <servicemix_home>/bin/servicemix          (on UNIX)
+    <servicemix_home>\bin\servicemix          (on Windows)
+
+
+Running the Example
+-------------------
+To install and run the example where you build the example bundle
+yourself, complete the following steps:
+
+1. Before being able to run this example, you have to install some additional
+   features into the container first to add spring support for the Drools 6.
+
+     feature:install kie-spring
+
+2. Build the example by opening a command prompt, changing directory to
+   examples/drools/drools-simple (this example) and entering the following Maven
+   command:
+
+     mvn clean 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:
+   
+     bundle:install -s mvn:org.apache.servicemix.examples/drools-spring/${project.version}
+       
+4. Once the bundle has been started, you will see on console logs from rule engine.
+
+	| ------------------- START ------------------
+ 	KieSession fireAllRules. Customer [salary=978, type=null]
+	DebugRuleRuntimeEventListener    | 286 - drools-spring - 6.0.0.SNAPSHOT | objectInserted ==>[ObjectInsertedEventImpl:
+	getFactHandle()=[fact 0:1:1887740067:18877 40067:1:DEFAULT:NON_TRAIT:Customer [salary=978, type=null]],
+	getObject()=Customer [salary=978, type=null], ......
+
+
+
+Stopping and Uninstalling the Example
+-------------------------------------
+First, find the bundle id for the deployed example bundle by doing
+
+  osgi:list
+
+and looking for a line that looks like this one
+
+229 | Active   |  80 | 	| Apache ServiceMix :: Examples :: Drools :: Spring 
+
+In the above case, the bundle id would be 229
+
+
+To stop the example, enter the following command in the ServiceMix
+console:
+
+  bundle:stop <bundle_id>
+
+
+To uninstall the example, enter one of the following commands in
+the ServiceMix console:
+
+  bundle:uninstall <bundle_id>
+ 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/servicemix/blob/c928d62f/examples/drools/drools-spring/pom.xml
----------------------------------------------------------------------
diff --git a/examples/drools/drools-spring/pom.xml b/examples/drools/drools-spring/pom.xml
new file mode 100644
index 0000000..e922827
--- /dev/null
+++ b/examples/drools/drools-spring/pom.xml
@@ -0,0 +1,73 @@
+<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">
+    <!--
+        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.
+    -->
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.servicemix.examples</groupId>
+        <artifactId>drools</artifactId>
+        <version>6.0.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>drools-spring</artifactId>
+    <name>Apache ServiceMix :: Examples :: Drools :: Spring</name>
+    <packaging>bundle</packaging>
+    <properties>
+        <osgi.private.package>
+            org.apache.servicemix.examples.drools.spring.osgi,
+            org.apache.servicemix.examples.drools.spring.model
+        </osgi.private.package>
+        <osgi.import.package>
+            org.slf4j;version="[1.6,2)",
+            org.kie.api.*;version="[6.0,7)",
+            org.kie.spring;version="[6.0,7)",
+            org.kie.internal.command;version="[6.0,7)",
+            org.drools.osgi.spring;version="[6.0,7)",
+        </osgi.import.package>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.kie</groupId>
+            <artifactId>kie-api</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.drools</groupId>
+            <artifactId>drools-core</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.drools</groupId>
+            <artifactId>drools-osgi-integration</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/servicemix/blob/c928d62f/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/model/Customer.java
----------------------------------------------------------------------
diff --git a/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/model/Customer.java b/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/model/Customer.java
new file mode 100644
index 0000000..8fbc587
--- /dev/null
+++ b/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/model/Customer.java
@@ -0,0 +1,80 @@
+/*
+ * 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.drools.spring.model;
+
+
+public class Customer {
+
+    /**
+     * Salary
+     */
+    private int salary;
+
+    /**
+     * IS VIP.
+     */
+    private CustomerType type;
+
+    /**
+     * Create customer with salary.
+     *
+     * @param salary
+     */
+    public Customer(int salary) {
+        this.salary = salary;
+    }
+
+    /**
+     * @return the salary
+     */
+    public int getSalary() {
+        return salary;
+    }
+
+    /**
+     * @return the type
+     */
+    public CustomerType getType() {
+        return type;
+    }
+
+    /**
+     * @param salary the salary to set
+     */
+    public void setSalary(int salary) {
+        this.salary = salary;
+    }
+
+    /**
+     * @param type the type to set
+     */
+    public void setType(CustomerType type) {
+        this.type = type;
+    }
+
+    /**
+     * @see Object#toString()
+     */
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("Customer [salary=").append(salary).append(", type=")
+                .append(type).append("]");
+        return builder.toString();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/servicemix/blob/c928d62f/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/model/CustomerType.java
----------------------------------------------------------------------
diff --git a/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/model/CustomerType.java b/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/model/CustomerType.java
new file mode 100644
index 0000000..c989fbf
--- /dev/null
+++ b/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/model/CustomerType.java
@@ -0,0 +1,22 @@
+/*
+ * 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.drools.spring.model;
+
+
+public enum CustomerType {
+    POOR, NORMAL, VIP;
+}

http://git-wip-us.apache.org/repos/asf/servicemix/blob/c928d62f/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/DebugAgendaEventListener.java
----------------------------------------------------------------------
diff --git a/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/DebugAgendaEventListener.java b/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/DebugAgendaEventListener.java
new file mode 100644
index 0000000..159b683
--- /dev/null
+++ b/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/DebugAgendaEventListener.java
@@ -0,0 +1,132 @@
+/*
+ * 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.drools.spring.osgi;
+
+import org.kie.api.event.rule.AfterMatchFiredEvent;
+import org.kie.api.event.rule.AgendaEventListener;
+import org.kie.api.event.rule.AgendaGroupPoppedEvent;
+import org.kie.api.event.rule.AgendaGroupPushedEvent;
+import org.kie.api.event.rule.BeforeMatchFiredEvent;
+import org.kie.api.event.rule.MatchCancelledEvent;
+import org.kie.api.event.rule.MatchCreatedEvent;
+import org.kie.api.event.rule.RuleFlowGroupActivatedEvent;
+import org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Drools 6 Rule Engine events logger.
+ */
+public class DebugAgendaEventListener implements AgendaEventListener {
+    /**
+     * Logger.
+     */
+    private static final Logger log = LoggerFactory
+            .getLogger(DebugAgendaEventListener.class);
+
+    /**
+     * @see AgendaEventListener#matchCreated(org.kie.api.event.rule.MatchCreatedEvent)
+     */
+    @Override
+    public void matchCreated(MatchCreatedEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#matchCancelled(org.kie.api.event.rule.MatchCancelledEvent)
+     */
+    @Override
+    public void matchCancelled(MatchCancelledEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#beforeMatchFired(org.kie.api.event.rule.BeforeMatchFiredEvent)
+     */
+    @Override
+    public void beforeMatchFired(BeforeMatchFiredEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#afterMatchFired(org.kie.api.event.rule.AfterMatchFiredEvent)
+     */
+    @Override
+    public void afterMatchFired(AfterMatchFiredEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#agendaGroupPopped(org.kie.api.event.rule.AgendaGroupPoppedEvent)
+     */
+    @Override
+    public void agendaGroupPopped(AgendaGroupPoppedEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#agendaGroupPushed(org.kie.api.event.rule.AgendaGroupPushedEvent)
+     */
+    @Override
+    public void agendaGroupPushed(AgendaGroupPushedEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#beforeRuleFlowGroupActivated(org.kie.api.event.rule.RuleFlowGroupActivatedEvent)
+     */
+    @Override
+    public void beforeRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#afterRuleFlowGroupActivated(org.kie.api.event.rule.RuleFlowGroupActivatedEvent)
+     */
+    @Override
+    public void afterRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#beforeRuleFlowGroupDeactivated(org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent)
+     */
+    @Override
+    public void beforeRuleFlowGroupDeactivated(
+            RuleFlowGroupDeactivatedEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#beforeRuleFlowGroupDeactivated(org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent)
+     */
+    @Override
+    public void afterRuleFlowGroupDeactivated(
+            RuleFlowGroupDeactivatedEvent event) {
+        log.info("{}", event);
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/servicemix/blob/c928d62f/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/DebugRuleRuntimeEventListener.java
----------------------------------------------------------------------
diff --git a/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/DebugRuleRuntimeEventListener.java b/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/DebugRuleRuntimeEventListener.java
new file mode 100644
index 0000000..ce79a47
--- /dev/null
+++ b/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/DebugRuleRuntimeEventListener.java
@@ -0,0 +1,61 @@
+/*
+ * 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.drools.spring.osgi;
+
+import org.kie.api.event.rule.ObjectDeletedEvent;
+import org.kie.api.event.rule.ObjectInsertedEvent;
+import org.kie.api.event.rule.ObjectUpdatedEvent;
+import org.kie.api.event.rule.RuleRuntimeEventListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Drools 6 Working memory events.
+ */
+public class DebugRuleRuntimeEventListener implements RuleRuntimeEventListener {
+    /**
+     * Logger.
+     */
+    private static final Logger log = LoggerFactory
+            .getLogger(DebugRuleRuntimeEventListener.class);
+
+    /**
+     * @see RuleRuntimeEventListener#objectInserted(ObjectInsertedEvent)
+     */
+    @Override
+    public void objectInserted(ObjectInsertedEvent event) {
+        log.info("objectInserted {}", event);
+    }
+
+    /**
+     * @see RuleRuntimeEventListener#objectUpdated(org.kie.api.event.rule.ObjectUpdatedEvent)
+     */
+    @Override
+    public void objectUpdated(ObjectUpdatedEvent event) {
+        log.info("objectUpdated {}", event);
+
+    }
+
+    /**
+     * @see RuleRuntimeEventListener#objectDeleted(org.kie.api.event.rule.ObjectDeletedEvent)
+     */
+    @Override
+    public void objectDeleted(ObjectDeletedEvent event) {
+        log.info("objectDeleted {}", event);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/servicemix/blob/c928d62f/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/SimpleRuleBean.java
----------------------------------------------------------------------
diff --git a/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/SimpleRuleBean.java b/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/SimpleRuleBean.java
new file mode 100644
index 0000000..41f76ea
--- /dev/null
+++ b/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/SimpleRuleBean.java
@@ -0,0 +1,83 @@
+/*
+ * 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.drools.spring.osgi;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.servicemix.examples.drools.spring.model.Customer;
+import org.kie.api.command.Command;
+import org.kie.api.runtime.ExecutionResults;
+import org.kie.api.runtime.StatelessKieSession;
+import org.kie.internal.command.CommandFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.servicemix.examples.drools.spring.osgi.Utils.customer;
+
+/**
+ * Simple spring bean.
+ */
+public class SimpleRuleBean {
+    /**
+     * LOGGER.
+     */
+    protected static final transient Logger logger = LoggerFactory
+            .getLogger(SimpleRuleBean.class);
+
+    /**
+     * StatelessKieSession
+     */
+    private StatelessKieSession ksession;
+
+    /**
+     *
+     */
+    public void start() throws Exception {
+
+        for (int i = 0; i < 10; i++) {
+            Customer customer = customer();
+            logger.info("------------------- START ------------------\n"
+                    + " KieSession fireAllRules. {}", customer);
+
+            List<Command<?>> commands = new ArrayList<Command<?>>();
+
+            commands.add(CommandFactory.newInsert(customer, "customer"));
+            commands.add(CommandFactory.newFireAllRules("num-rules-fired"));
+
+            ExecutionResults results = ksession.execute(CommandFactory
+                    .newBatchExecution(commands));
+
+            int fired = Integer.parseInt(results.getValue("num-rules-fired")
+                    .toString());
+
+            customer = (Customer)results.getValue("customer");
+
+            logger.info("After rule rules-fired={} {} \n"
+                            + "------------------- STOP ---------------------", fired,
+                    customer);
+        }
+    }
+
+    /**
+     * @param ksession the ksession to set
+     */
+    public void setKsession(StatelessKieSession ksession) {
+        this.ksession = ksession;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/servicemix/blob/c928d62f/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/Utils.java
----------------------------------------------------------------------
diff --git a/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/Utils.java b/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/Utils.java
new file mode 100644
index 0000000..82ebe1d
--- /dev/null
+++ b/examples/drools/drools-spring/src/main/java/org/apache/servicemix/examples/drools/spring/osgi/Utils.java
@@ -0,0 +1,37 @@
+/*
+ * 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.drools.spring.osgi;
+
+import java.util.Random;
+
+import org.apache.servicemix.examples.drools.spring.model.Customer;
+
+
+public class Utils {
+
+    /**
+     *
+     */
+    private static final Random rand = new Random(12345);
+
+    /**
+     * @return
+     */
+    public static Customer customer() {
+        return new Customer(rand.nextInt(9999));
+    }
+}

http://git-wip-us.apache.org/repos/asf/servicemix/blob/c928d62f/examples/drools/drools-spring/src/main/resources/META-INF/spring/simple-spring.xml
----------------------------------------------------------------------
diff --git a/examples/drools/drools-spring/src/main/resources/META-INF/spring/simple-spring.xml b/examples/drools/drools-spring/src/main/resources/META-INF/spring/simple-spring.xml
new file mode 100644
index 0000000..43877f4
--- /dev/null
+++ b/examples/drools/drools-spring/src/main/resources/META-INF/spring/simple-spring.xml
@@ -0,0 +1,55 @@
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:kie="http://drools.org/schema/kie-spring"
+    xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd">
+
+    <bean id="kiePostProcessor"
+        class="org.drools.osgi.spring.OsgiKModuleBeanFactoryPostProcessor" />
+
+    <kie:kmodule id="id-kmodule">
+        <kie:kbase name="SimpleRuleKBase" default="true"
+            packages="rule">
+            <kie:ksession name="simpleRuleKSession" type="stateless"
+                default="true" listeners-ref="debugListeners">
+            </kie:ksession>
+        </kie:kbase>
+    </kie:kmodule>
+
+
+    <bean id="DebugAgendaEventListener"
+        class="org.apache.servicemix.examples.drools.spring.osgi.DebugAgendaEventListener" />
+    <bean id="DebugRuleRuntimeEventListener"
+        class="org.apache.servicemix.examples.drools.spring.osgi.DebugRuleRuntimeEventListener" />
+
+    <kie:eventListeners id="debugListeners">
+        <kie:agendaEventListener ref="DebugAgendaEventListener" />
+        <kie:ruleRuntimeEventListener ref="DebugRuleRuntimeEventListener" />
+        <kie:processEventListener />
+    </kie:eventListeners>
+
+    <!--  Bean create facts and rune drools engine -->
+    <bean
+        class="org.apache.servicemix.examples.drools.spring.osgi.SimpleRuleBean"
+        init-method="start">
+        <property name="ksession" ref="simpleRuleKSession" />
+    </bean>
+
+</beans>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/servicemix/blob/c928d62f/examples/drools/drools-spring/src/main/resources/rule/customer-score.drl
----------------------------------------------------------------------
diff --git a/examples/drools/drools-spring/src/main/resources/rule/customer-score.drl b/examples/drools/drools-spring/src/main/resources/rule/customer-score.drl
new file mode 100644
index 0000000..b2f276c
--- /dev/null
+++ b/examples/drools/drools-spring/src/main/resources/rule/customer-score.drl
@@ -0,0 +1,48 @@
+/*
+ * 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 rule;
+import org.apache.servicemix.examples.drools.spring.model.Customer;
+import org.apache.servicemix.examples.drools.spring.model.CustomerType;
+
+rule "Customer poor"
+when
+    $c : Customer( salary <= 1000, type == null)
+then
+    modify( $c ) {
+        setType(CustomerType.POOR)
+    };
+end
+
+
+rule "Customer NORMAL"
+when
+    $c : Customer( salary > 1000, salary <= 9000, type == null )
+then
+    modify( $c ) {
+        setType(CustomerType.NORMAL)
+    };
+end
+
+
+rule "Customer VIP"
+when
+    $c : Customer( salary > 9000, type == null)
+then
+    modify( $c ) {
+        setType(CustomerType.VIP)
+    };
+end
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/servicemix/blob/c928d62f/examples/drools/pom.xml
----------------------------------------------------------------------
diff --git a/examples/drools/pom.xml b/examples/drools/pom.xml
index 1cd4778..97291cd 100644
--- a/examples/drools/pom.xml
+++ b/examples/drools/pom.xml
@@ -76,5 +76,6 @@
     <modules>
         <module>drools-simple</module>
         <module>drools-camel-blueprint</module>
+        <module>drools-spring</module>
     </modules>
 </project>

http://git-wip-us.apache.org/repos/asf/servicemix/blob/c928d62f/itests/src/test/scala/org/apache/servicemix/itests/Drools6IntegrationTests.scala
----------------------------------------------------------------------
diff --git a/itests/src/test/scala/org/apache/servicemix/itests/Drools6IntegrationTests.scala b/itests/src/test/scala/org/apache/servicemix/itests/Drools6IntegrationTests.scala
index ddaf439..371e138 100644
--- a/itests/src/test/scala/org/apache/servicemix/itests/Drools6IntegrationTests.scala
+++ b/itests/src/test/scala/org/apache/servicemix/itests/Drools6IntegrationTests.scala
@@ -101,3 +101,19 @@ class Drools6ExamplesTest extends Drools6IntegrationTests {
     }
   }
 }
+
+/**
+ * Tests for the Drools with spring
+ */
+class Drools6SpringExamplesTest extends Drools6IntegrationTests {
+
+  /**
+   * Test installation Spring with drools example.
+   */
+  @Test
+  def testDroolsSpringExample = testWithFeature("examples-drools-spring") {
+    expect {
+      logging.containsMessage(line => line.contains("KieModule was added: org.drools.osgi.compiler.OsgiKieModule"))
+    }
+  }
+}


[3/3] servicemix git commit: SM-2548: Provide CXF Rest Service example for Drools 6 (closes #28)

Posted by ks...@apache.org.
SM-2548: Provide CXF Rest Service example for Drools 6 (closes #28)

Thanks to Grzegorz Halajko for the pull request!!!


Project: http://git-wip-us.apache.org/repos/asf/servicemix/repo
Commit: http://git-wip-us.apache.org/repos/asf/servicemix/commit/8ae57000
Tree: http://git-wip-us.apache.org/repos/asf/servicemix/tree/8ae57000
Diff: http://git-wip-us.apache.org/repos/asf/servicemix/diff/8ae57000

Branch: refs/heads/master
Commit: 8ae57000027797d0ca2ab4cef7b78b90a2023db4
Parents: f644027
Author: Grzegorz Halajko <gh...@linuxpolska.pl>
Authored: Tue May 26 23:26:32 2015 +0200
Committer: Krzysztof Sobkowiak <kr...@gmail.com>
Committed: Wed May 27 00:03:34 2015 +0200

----------------------------------------------------------------------
 .../src/main/filtered-resources/examples.xml    |   7 +
 .../drools/drools-camel-cxf-server/README.txt   | 136 +++++++++++++++++++
 examples/drools/drools-camel-cxf-server/pom.xml | 104 ++++++++++++++
 .../drools/camel/cxf/server/model/Customer.java |  79 +++++++++++
 .../camel/cxf/server/model/CustomerType.java    |  22 +++
 .../cxf/server/osgi/CommandMessageBodyRW.java   |  74 ++++++++++
 .../server/osgi/DebugAgendaEventListener.java   | 132 ++++++++++++++++++
 .../osgi/DebugRuleRuntimeEventListener.java     |  61 +++++++++
 .../drools/camel/cxf/server/osgi/Utils.java     |  59 ++++++++
 .../OSGI-INF/blueprint/camel-client.xml         |  78 +++++++++++
 .../OSGI-INF/blueprint/camel-server.xml         |  58 ++++++++
 .../OSGI-INF/blueprint/kmodule-blueprint.xml    |  44 ++++++
 .../src/main/resources/rule/customer-score.drl  |  48 +++++++
 .../src/test/resources/batch-test-request.xml   |  14 ++
 .../src/test/resources/test-request.xml         |   6 +
 examples/drools/pom.xml                         |   1 +
 .../itests/Drools6IntegrationTests.scala        |  13 ++
 17 files changed, 936 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/assembly/src/main/filtered-resources/examples.xml
----------------------------------------------------------------------
diff --git a/assembly/src/main/filtered-resources/examples.xml b/assembly/src/main/filtered-resources/examples.xml
index 8bfe111..4cbd587 100644
--- a/assembly/src/main/filtered-resources/examples.xml
+++ b/assembly/src/main/filtered-resources/examples.xml
@@ -177,4 +177,11 @@
         <bundle>mvn:org.apache.servicemix.examples/drools-spring/${version}</bundle>
     </feature>
 
+    <feature name="examples-drools-camel-cxf-server" version="${version}" resolver="(obr)">
+        <feature version="${drools6.version}">kie-aries-blueprint</feature>
+        <feature version="${drools6.version}">kie-camel</feature>
+        <feature version="${camel.version}">camel-xstream</feature>
+        <bundle>mvn:org.apache.servicemix.examples/drools-camel-cxf-server/${version}</bundle>
+    </feature>
+
 </features>

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/drools-camel-cxf-server/README.txt
----------------------------------------------------------------------
diff --git a/examples/drools/drools-camel-cxf-server/README.txt b/examples/drools/drools-camel-cxf-server/README.txt
new file mode 100644
index 0000000..aeb6cae
--- /dev/null
+++ b/examples/drools/drools-camel-cxf-server/README.txt
@@ -0,0 +1,136 @@
+/*
+ * 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.
+ */
+
+Drools 6 Simple Example
+==========================
+
+Purpose
+-------
+This example will show you how to use Drools 6 inside Apache ServiceMix and how to
+use rule engine in low level.
+
+
+
+Prerequisites for Running the Example
+-------------------------------------
+1. You must have the following installed on your machine:
+
+   - JDK 1.6 or higher
+
+   - Maven 3.0.2 or higher (for building)
+   
+  For more information, see the README in the top-level examples
+  directory.
+
+2. Start ServiceMix by running the following command:
+
+    <servicemix_home>/bin/servicemix          (on UNIX)
+    <servicemix_home>\bin\servicemix          (on Windows)
+
+
+Running the Example
+-------------------
+To install and run the example where you build the example bundle
+yourself, complete the following steps:
+
+1. Before being able to run this example, you have to install some additional
+   features into the container first to add support for the Drools 6.
+
+     feature:install kie-aries-blueprint
+     feature:install kie-camel
+     feature:install camel-xstream
+
+2. Build the example by opening a command prompt, changing directory to
+   examples/drools/drools-simple (this example) and entering the following Maven
+   command:
+
+     mvn clean 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:
+   
+     bundle:install -s mvn:org.apache.servicemix.examples/drools-camel-cxf-server/${project.version}
+       
+4. Once the bundle has been started, you will see on console logs from rule engine.
+
+drools-camel-cxf-server - 6.0.0.SNAPSHOT | objectInserted ==>[ObjectInsertedEventImpl: 
+getFactHandle()=[fact 0:1:109283499:109283499:1:DEFAULT:NON_TRAIT:
+Customer [salary=3955, type=null]], getObject()=Customer [salary=3955, type=null],
+getKnowledgeRuntime()=org.drools.core.impl.StatefulKnowledgeSessionImpl@45a5e94a, getPropagationContext()=PhreakPropagationContext
+[entryPoint=EntryPoint::DEFAULT, factHandle=[fact 0:1:109283499:109283499:1:DEFAULT:NON_TRAIT:Customer
+[salary=3955, type=null]], leftTuple=null, originOffset=-1, propagationNumber=2, rule=null, type=0]]
+
+DroolsRestResult Exchange[ExchangePattern: InOut, BodyType: String, 
+Body: <?xml version='1.0' encoding='UTF-8'?>
+        <execution-results>
+            <result identifier="customer">
+                <org.apache.servicemix.examples.drools.simple.model.Customer>
+                    <salary>3955</salary>
+                    <type>NORMAL</type>
+                </org.apache.servicemix.examples.drools.simple.model.Customer>
+            </result>
+            <fact-handle identifier="customer" external-form="0:1:878677865:878677865:2:DEFAULT:NON_TRAIT"/>
+        </execution-results>]
+
+   Timer on camel route call rest client procedure. Via rest service facts it's inserted to work memory 
+   and in logs you can saw drools engine activity
+
+5. You can use a command-line utility, such as curl or Wget, to make the invocations.
+   For example, try using curl as follows:
+
+    #
+    # Single fact execution:
+    #
+    curl -X POST -T src/test/resources/test-request.xml -H "Content-Type: text/plain" http://localhost:8181/cxf/rest/execute
+
+    #
+    # Batch execution (multi facts insert):
+    #
+    curl -X POST -T src/test/resources/batch-test-request.xml -H "Content-Type: text/plain" http://localhost:8181/cxf/rest/execute
+
+Stopping and Uninstalling the Example
+-------------------------------------
+First, find the bundle id for the deployed example bundle by doing
+
+  osgi:list
+
+and looking for a line that looks like this one
+
+229 | Active   |  80 | 	| Apache ServiceMix :: Examples :: Drools :: Camel CXF Server
+
+In the above case, the bundle id would be 229
+
+
+To stop the example, enter the following command in the ServiceMix
+console:
+
+  bundle:stop <bundle_id>
+
+
+To uninstall the example, enter one of the following commands in
+the ServiceMix console:
+
+  bundle:uninstall <bundle_id>
+ 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/drools-camel-cxf-server/pom.xml
----------------------------------------------------------------------
diff --git a/examples/drools/drools-camel-cxf-server/pom.xml b/examples/drools/drools-camel-cxf-server/pom.xml
new file mode 100644
index 0000000..adf2d19
--- /dev/null
+++ b/examples/drools/drools-camel-cxf-server/pom.xml
@@ -0,0 +1,104 @@
+<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">
+    <!--
+
+        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.
+    -->
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.servicemix.examples</groupId>
+        <artifactId>drools</artifactId>
+        <version>6.0.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>drools-camel-cxf-server</artifactId>
+    <name>Apache ServiceMix :: Examples :: Drools :: Camel CXF Server</name>
+    <packaging>bundle</packaging>
+
+    <properties>
+        <osgi.private.package>
+            org.apache.servicemix.examples.drools.camel.cxf.server.osgi,
+            org.apache.servicemix.examples.drools.camel.cxf.server.model</osgi.private.package>
+        <osgi.import.package>
+            org.osgi.service.blueprint,
+            org.slf4j;version="[1.6,2)",
+            org.kie.jax.rs;version="[6.0,7.0)",
+            org.kie.camel.component;version="[6.0,7.0)",
+            org.kie.api.event.rule;version="[6.0,7.0)",
+            org.kie.api.command;version="[6.0,7.0)",
+            org.kie.aries.blueprint.factorybeans;version="[6.0,7.0)",
+            org.apache.camel;version="[2.15,2.16)",
+
+            org.kie.internal.command;version="[6.0,7)",
+            
+            org.kie.internal.runtime.helper;version="[6.0,7)",
+            org.drools.core.runtime.impl;version="[6.0,7)",
+            org.drools.core.runtime.rule.impl;version="[6.0,7)",
+            org.drools.core.command.runtime.process;version="[6.0,7)",
+            org.drools.core.common;version="[6.0,7)",
+            org.drools.core.command.runtime;version="[6.0,7)",
+            org.drools.core.command.runtime.rule;version="[6.0,7)",
+            org.drools.core.impl;version="[6.0,7)",
+            org.drools.core.runtime.help.impl;version="[6.0,7)",
+            com.thoughtworks.xstream;version="1.4",
+            javax.ws.rs.ext,
+            javax.ws.rs.core,
+            javax.ws.rs
+        </osgi.import.package>
+    </properties>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.kie</groupId>
+            <artifactId>kie-api</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.kie</groupId>
+            <artifactId>kie-camel</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.drools</groupId>
+            <artifactId>drools-compiler</artifactId>
+        </dependency>
+
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-cxf</artifactId>
+        </dependency>
+
+    </dependencies>
+
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/model/Customer.java
----------------------------------------------------------------------
diff --git a/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/model/Customer.java b/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/model/Customer.java
new file mode 100644
index 0000000..98e2b5d
--- /dev/null
+++ b/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/model/Customer.java
@@ -0,0 +1,79 @@
+/*
+ * 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.drools.camel.cxf.server.model;
+
+public class Customer {
+
+    /**
+     * Salary
+     */
+    private int salary;
+
+    /**
+     * IS VIP.
+     */
+    private CustomerType type;
+
+    /**
+     * Create customer with salary.
+     *
+     * @param salary
+     */
+    public Customer(int salary) {
+        this.salary = salary;
+    }
+
+    /**
+     * @return the salary
+     */
+    public int getSalary() {
+        return salary;
+    }
+
+    /**
+     * @return the type
+     */
+    public CustomerType getType() {
+        return type;
+    }
+
+    /**
+     * @param salary the salary to set
+     */
+    public void setSalary(int salary) {
+        this.salary = salary;
+    }
+
+    /**
+     * @param type the type to set
+     */
+    public void setType(CustomerType type) {
+        this.type = type;
+    }
+
+    /**
+     * @see Object#toString()
+     */
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("Customer [salary=").append(salary).append(", type=")
+                .append(type).append("]");
+        return builder.toString();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/model/CustomerType.java
----------------------------------------------------------------------
diff --git a/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/model/CustomerType.java b/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/model/CustomerType.java
new file mode 100644
index 0000000..b969c67
--- /dev/null
+++ b/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/model/CustomerType.java
@@ -0,0 +1,22 @@
+/*
+ * 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.drools.camel.cxf.server.model;
+
+
+public enum CustomerType {
+    POOR, NORMAL, VIP;
+}

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/CommandMessageBodyRW.java
----------------------------------------------------------------------
diff --git a/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/CommandMessageBodyRW.java b/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/CommandMessageBodyRW.java
new file mode 100644
index 0000000..6889982
--- /dev/null
+++ b/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/CommandMessageBodyRW.java
@@ -0,0 +1,74 @@
+/*
+ * 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.drools.camel.cxf.server.osgi;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.drools.core.runtime.help.impl.BatchExecutionHelperProviderImpl;
+import org.kie.api.command.Command;
+import org.kie.internal.runtime.helper.BatchExecutionHelperProvider;
+
+
+@Consumes("text/plain")
+@Provider
+public class CommandMessageBodyRW implements MessageBodyWriter<Command<?>> {
+
+    /**
+     * provider
+     */
+    private BatchExecutionHelperProvider provider = new BatchExecutionHelperProviderImpl();
+
+    /**
+     * getSize
+     */
+    @Override
+    public long getSize(Command<?> arg0, Class<?> arg1, Type arg2,
+                        Annotation[] arg3, MediaType arg4) {
+        return -1;
+    }
+
+    /**
+     * isWriteable
+     */
+    @Override
+    public boolean isWriteable(Class<?> type, Type genericType,
+                               Annotation[] arg2, MediaType arg3) {
+        return Command.class.isAssignableFrom(type);
+
+    }
+
+    /**
+     * writeTo
+     */
+    @Override
+    public void writeTo(Command<?> obj, Class<?> arg1, Type arg2,
+                        Annotation[] arg3, MediaType arg4,
+                        MultivaluedMap<String, Object> arg5, OutputStream out)
+            throws IOException, WebApplicationException {
+        provider.newXStreamMarshaller().toXML(obj, out);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/DebugAgendaEventListener.java
----------------------------------------------------------------------
diff --git a/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/DebugAgendaEventListener.java b/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/DebugAgendaEventListener.java
new file mode 100644
index 0000000..bad7479
--- /dev/null
+++ b/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/DebugAgendaEventListener.java
@@ -0,0 +1,132 @@
+/*
+ * 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.drools.camel.cxf.server.osgi;
+
+import org.kie.api.event.rule.AfterMatchFiredEvent;
+import org.kie.api.event.rule.AgendaEventListener;
+import org.kie.api.event.rule.AgendaGroupPoppedEvent;
+import org.kie.api.event.rule.AgendaGroupPushedEvent;
+import org.kie.api.event.rule.BeforeMatchFiredEvent;
+import org.kie.api.event.rule.MatchCancelledEvent;
+import org.kie.api.event.rule.MatchCreatedEvent;
+import org.kie.api.event.rule.RuleFlowGroupActivatedEvent;
+import org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Drools 6 Rule Engine events logger.
+ */
+public class DebugAgendaEventListener implements AgendaEventListener {
+    /**
+     * Logger.
+     */
+    private static final Logger log = LoggerFactory
+            .getLogger(DebugAgendaEventListener.class);
+
+    /**
+     * @see AgendaEventListener#matchCreated(org.kie.api.event.rule.MatchCreatedEvent)
+     */
+    @Override
+    public void matchCreated(MatchCreatedEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#matchCancelled(org.kie.api.event.rule.MatchCancelledEvent)
+     */
+    @Override
+    public void matchCancelled(MatchCancelledEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#beforeMatchFired(org.kie.api.event.rule.BeforeMatchFiredEvent)
+     */
+    @Override
+    public void beforeMatchFired(BeforeMatchFiredEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#afterMatchFired(org.kie.api.event.rule.AfterMatchFiredEvent)
+     */
+    @Override
+    public void afterMatchFired(AfterMatchFiredEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#agendaGroupPopped(org.kie.api.event.rule.AgendaGroupPoppedEvent)
+     */
+    @Override
+    public void agendaGroupPopped(AgendaGroupPoppedEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#agendaGroupPushed(org.kie.api.event.rule.AgendaGroupPushedEvent)
+     */
+    @Override
+    public void agendaGroupPushed(AgendaGroupPushedEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#beforeRuleFlowGroupActivated(org.kie.api.event.rule.RuleFlowGroupActivatedEvent)
+     */
+    @Override
+    public void beforeRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#afterRuleFlowGroupActivated(org.kie.api.event.rule.RuleFlowGroupActivatedEvent)
+     */
+    @Override
+    public void afterRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#beforeRuleFlowGroupDeactivated(org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent)
+     */
+    @Override
+    public void beforeRuleFlowGroupDeactivated(
+            RuleFlowGroupDeactivatedEvent event) {
+        log.info("{}", event);
+
+    }
+
+    /**
+     * @see AgendaEventListener#beforeRuleFlowGroupDeactivated(org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent)
+     */
+    @Override
+    public void afterRuleFlowGroupDeactivated(
+            RuleFlowGroupDeactivatedEvent event) {
+        log.info("{}", event);
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/DebugRuleRuntimeEventListener.java
----------------------------------------------------------------------
diff --git a/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/DebugRuleRuntimeEventListener.java b/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/DebugRuleRuntimeEventListener.java
new file mode 100644
index 0000000..71a8229
--- /dev/null
+++ b/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/DebugRuleRuntimeEventListener.java
@@ -0,0 +1,61 @@
+/*
+ * 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.drools.camel.cxf.server.osgi;
+
+import org.kie.api.event.rule.ObjectDeletedEvent;
+import org.kie.api.event.rule.ObjectInsertedEvent;
+import org.kie.api.event.rule.ObjectUpdatedEvent;
+import org.kie.api.event.rule.RuleRuntimeEventListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Drools 6 Working memory events.
+ */
+public class DebugRuleRuntimeEventListener implements RuleRuntimeEventListener {
+    /**
+     * Logger.
+     */
+    private static final Logger log = LoggerFactory
+            .getLogger(DebugRuleRuntimeEventListener.class);
+
+    /**
+     * @see RuleRuntimeEventListener#objectInserted(ObjectInsertedEvent)
+     */
+    @Override
+    public void objectInserted(ObjectInsertedEvent event) {
+        log.info("objectInserted {}", event);
+    }
+
+    /**
+     * @see RuleRuntimeEventListener#objectUpdated(org.kie.api.event.rule.ObjectUpdatedEvent)
+     */
+    @Override
+    public void objectUpdated(ObjectUpdatedEvent event) {
+        log.info("objectUpdated {}", event);
+
+    }
+
+    /**
+     * @see RuleRuntimeEventListener#objectDeleted(org.kie.api.event.rule.ObjectDeletedEvent)
+     */
+    @Override
+    public void objectDeleted(ObjectDeletedEvent event) {
+        log.info("objectDeleted {}", event);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/Utils.java
----------------------------------------------------------------------
diff --git a/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/Utils.java b/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/Utils.java
new file mode 100644
index 0000000..104a69e
--- /dev/null
+++ b/examples/drools/drools-camel-cxf-server/src/main/java/org/apache/servicemix/examples/drools/camel/cxf/server/osgi/Utils.java
@@ -0,0 +1,59 @@
+/*
+ * 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.drools.camel.cxf.server.osgi;
+
+import java.util.Arrays;
+import java.util.Random;
+
+import org.apache.servicemix.examples.drools.camel.cxf.server.model.Customer;
+import org.kie.api.command.Command;
+import org.kie.api.runtime.ExecutionResults;
+import org.kie.internal.command.CommandFactory;
+
+
+public class Utils {
+    /**
+     * Random
+     */
+    private static Random rand = new Random(12345);
+
+    /**
+     * Generate random customer
+     *
+     * @return
+     */
+    public Customer customer() {
+        return new Customer(rand.nextInt(9999));
+    }
+
+    /**
+     * Create commands for Drools engine.
+     *
+     * @param body {@link org.apache.camel.Exchange}
+     */
+    public Command<ExecutionResults> insertAndFireAll(final Customer body) {
+
+        Command<?> insert = CommandFactory.newInsert(body, "customer");
+
+        @SuppressWarnings("unchecked")
+        Command<ExecutionResults> batch = CommandFactory
+                .newBatchExecution(Arrays.asList(insert));
+
+        return batch;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/drools-camel-cxf-server/src/main/resources/OSGI-INF/blueprint/camel-client.xml
----------------------------------------------------------------------
diff --git a/examples/drools/drools-camel-cxf-server/src/main/resources/OSGI-INF/blueprint/camel-client.xml b/examples/drools/drools-camel-cxf-server/src/main/resources/OSGI-INF/blueprint/camel-client.xml
new file mode 100644
index 0000000..69f6d7b
--- /dev/null
+++ b/examples/drools/drools-camel-cxf-server/src/main/resources/OSGI-INF/blueprint/camel-client.xml
@@ -0,0 +1,78 @@
+<?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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
+    xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
+    xmlns:cxf-core="http://cxf.apache.org/blueprint/core"
+    xsi:schemaLocation="
+http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
+http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
+http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/cxf/camel-cxf-blueprint.xsd
+http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
+http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
+
+    <!-- Rest Converter. Convert object extends by org.kie.api.command.Command 
+        to string -->
+    <bean id="resultMessageProvider"
+        class="org.apache.servicemix.examples.drools.camel.cxf.server.osgi.CommandMessageBodyRW" />
+
+    <!-- Camel REST Client -->
+    <cxf:rsClient id="droolsRestClient" address="http://localhost:8181/cxf/rest"
+        serviceClass="org.kie.jax.rs.CommandExecutorImpl">
+        <cxf:providers>
+            <ref component-id="resultMessageProvider" />
+        </cxf:providers>
+    </cxf:rsClient>
+
+    <!-- Utils. -->
+    <bean id="customerUtil"
+        class="org.apache.servicemix.examples.drools.camel.cxf.server.osgi.Utils" />
+
+    <!-- Bean insert to Camel message configuration parameters
+        for cxf camel component -->
+    <bean id="preCxfrs" class="org.kie.camel.component.PreCxfrs" />
+
+    <!-- Bean trim response and convert request from InputStream to String -->
+    <bean id="postCxfrs" class="org.kie.camel.component.PostCxfrs" />
+
+    <!-- CAMEL -->
+    <camelContext id="camel-client"
+        xmlns="http://camel.apache.org/schema/blueprint">
+
+        <route id="route-to-rest">
+            <!-- Self-Timer -->
+            <from
+                uri="timer:restClientMock?fixedRate=true&amp;period=30s&amp;delay=5000" />
+            <process ref="preCxfrs" />
+            <!-- Create Customer with random salary -->
+            <bean method="customer" ref="customerUtil" />
+            <!-- Create KIE Commands -->
+            <bean method="insertAndFireAll" ref="customerUtil" />
+            <!-- Run CXF Rest client -->
+            <to uri="cxfrs:bean:droolsRestClient" />
+            <process ref="postCxfrs" />
+            <!-- The result it's printed in the logs. -->
+            <to uri="log:DroolsRestResult" />
+        </route>
+
+
+    </camelContext>
+
+</blueprint>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/drools-camel-cxf-server/src/main/resources/OSGI-INF/blueprint/camel-server.xml
----------------------------------------------------------------------
diff --git a/examples/drools/drools-camel-cxf-server/src/main/resources/OSGI-INF/blueprint/camel-server.xml b/examples/drools/drools-camel-cxf-server/src/main/resources/OSGI-INF/blueprint/camel-server.xml
new file mode 100644
index 0000000..263096e
--- /dev/null
+++ b/examples/drools/drools-camel-cxf-server/src/main/resources/OSGI-INF/blueprint/camel-server.xml
@@ -0,0 +1,58 @@
+<?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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
+    xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
+    xmlns:cxf-core="http://cxf.apache.org/blueprint/core"
+    xsi:schemaLocation="
+http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
+http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
+http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
+http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd">
+    
+    <!-- Bean trim request string -->
+    <bean id="messageBodyReader" class="org.kie.jax.rs.CommandMessageBodyReader" />
+    <!-- Bean add support drools, catch rest request and run KIE Commands-->
+    <bean id="kiePolicy" class="org.kie.camel.component.KiePolicy" />
+
+    <!-- Apache Camel Rest Server -->
+    <cxf:rsServer id="restKieServer" address="/rest"
+        serviceClass="org.kie.jax.rs.CommandExecutorImpl">
+        <cxf:providers>
+            <ref component-id="messageBodyReader" />
+        </cxf:providers>
+    </cxf:rsServer>
+
+    <!-- CAMEL -->
+    <camelContext id="camel"
+        xmlns="http://camel.apache.org/schema/blueprint">
+        <!-- Route catch REST request and forward request to Kie Policy Bean-->
+        <route>
+            <from uri="cxfrs:bean:restKieServer" />
+            <policy ref="kiePolicy">
+                <unmarshal ref="xstream" />
+                <to uri="kie:simpleRuleKSession" />
+                <marshal ref="xstream" />
+            </policy>
+        </route>
+
+    </camelContext>
+
+</blueprint>

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/drools-camel-cxf-server/src/main/resources/OSGI-INF/blueprint/kmodule-blueprint.xml
----------------------------------------------------------------------
diff --git a/examples/drools/drools-camel-cxf-server/src/main/resources/OSGI-INF/blueprint/kmodule-blueprint.xml b/examples/drools/drools-camel-cxf-server/src/main/resources/OSGI-INF/blueprint/kmodule-blueprint.xml
new file mode 100644
index 0000000..b299caa
--- /dev/null
+++ b/examples/drools/drools-camel-cxf-server/src/main/resources/OSGI-INF/blueprint/kmodule-blueprint.xml
@@ -0,0 +1,44 @@
+<?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.
+-->
+<blueprint default-timeout="1000"
+    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xmlns:kie="http://drools.org/schema/kie-aries-blueprint/1.0.0"
+    xsi:schemaLocation="
+           http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0
+           http://drools.org/schema/kie-aries-blueprint/1.0.0 http://drools.org/schema/kie-aries-blueprint/1.0.0">
+
+    <bean id="DebugAgendaEventListener"
+        class="org.apache.servicemix.examples.drools.camel.cxf.server.osgi.DebugAgendaEventListener" />
+    <bean id="DebugRuleRuntimeEventListener"
+        class="org.apache.servicemix.examples.drools.camel.cxf.server.osgi.DebugRuleRuntimeEventListener" />
+
+    <kie:eventListeners id="debugListeners">
+        <kie:agendaEventListener ref="DebugAgendaEventListener" />
+        <kie:ruleRuntimeEventListener ref="DebugRuleRuntimeEventListener" />
+    </kie:eventListeners>
+
+    <kie:kmodule id="id-kmodule">
+        <kie:kbase name="SimpleRuleKBase" default="true"
+            packages="rule">
+            <kie:ksession name="simpleRuleKSession" type="stateless"
+                listeners-ref="debugListeners" default="true">
+            </kie:ksession>
+        </kie:kbase>
+    </kie:kmodule>
+
+</blueprint>

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/drools-camel-cxf-server/src/main/resources/rule/customer-score.drl
----------------------------------------------------------------------
diff --git a/examples/drools/drools-camel-cxf-server/src/main/resources/rule/customer-score.drl b/examples/drools/drools-camel-cxf-server/src/main/resources/rule/customer-score.drl
new file mode 100644
index 0000000..bc1e3d7
--- /dev/null
+++ b/examples/drools/drools-camel-cxf-server/src/main/resources/rule/customer-score.drl
@@ -0,0 +1,48 @@
+/*
+ * 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 rule;
+import org.apache.servicemix.examples.drools.camel.cxf.server.model.Customer;
+import org.apache.servicemix.examples.drools.camel.cxf.server.model.CustomerType;
+
+rule "Customer poor"
+when
+    $c : Customer( salary <= 1000, type == null)
+then
+    modify( $c ) {
+        setType(CustomerType.POOR)
+    };
+end
+
+
+rule "Customer NORMAL"
+when
+    $c : Customer( salary > 1000, salary <= 9000, type == null )
+then
+    modify( $c ) {
+        setType(CustomerType.NORMAL)
+    };
+end
+
+
+rule "Customer VIP"
+when
+    $c : Customer( salary > 9000, type == null)
+then
+    modify( $c ) {
+        setType(CustomerType.VIP)
+    };
+end
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/drools-camel-cxf-server/src/test/resources/batch-test-request.xml
----------------------------------------------------------------------
diff --git a/examples/drools/drools-camel-cxf-server/src/test/resources/batch-test-request.xml b/examples/drools/drools-camel-cxf-server/src/test/resources/batch-test-request.xml
new file mode 100644
index 0000000..2824888
--- /dev/null
+++ b/examples/drools/drools-camel-cxf-server/src/test/resources/batch-test-request.xml
@@ -0,0 +1,14 @@
+<batch-execution lookup="rule-num">
+    <insert out-identifier="cusomer1" return-object="true"
+        entry-point="DEFAULT">
+        <org.apache.servicemix.examples.drools.camel.cxf.server.model.Customer>
+            <salary>9000</salary>
+        </org.apache.servicemix.examples.drools.camel.cxf.server.model.Customer>
+    </insert>
+    <insert out-identifier="cusomer2" return-object="true"
+        entry-point="DEFAULT">
+        <org.apache.servicemix.examples.drools.camel.cxf.server.model.Customer>
+            <salary>1000</salary>
+        </org.apache.servicemix.examples.drools.camel.cxf.server.model.Customer>
+    </insert>
+</batch-execution>

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/drools-camel-cxf-server/src/test/resources/test-request.xml
----------------------------------------------------------------------
diff --git a/examples/drools/drools-camel-cxf-server/src/test/resources/test-request.xml b/examples/drools/drools-camel-cxf-server/src/test/resources/test-request.xml
new file mode 100644
index 0000000..0359247
--- /dev/null
+++ b/examples/drools/drools-camel-cxf-server/src/test/resources/test-request.xml
@@ -0,0 +1,6 @@
+<insert out-identifier="cusomer1" return-object="true"
+    entry-point="DEFAULT">
+    <org.apache.servicemix.examples.drools.camel.cxf.server.model.Customer>
+        <salary>9000</salary>
+    </org.apache.servicemix.examples.drools.camel.cxf.server.model.Customer>
+</insert>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/examples/drools/pom.xml
----------------------------------------------------------------------
diff --git a/examples/drools/pom.xml b/examples/drools/pom.xml
index 97291cd..564c37f 100644
--- a/examples/drools/pom.xml
+++ b/examples/drools/pom.xml
@@ -76,6 +76,7 @@
     <modules>
         <module>drools-simple</module>
         <module>drools-camel-blueprint</module>
+        <module>drools-camel-cxf-server</module>
         <module>drools-spring</module>
     </modules>
 </project>

http://git-wip-us.apache.org/repos/asf/servicemix/blob/8ae57000/itests/src/test/scala/org/apache/servicemix/itests/Drools6IntegrationTests.scala
----------------------------------------------------------------------
diff --git a/itests/src/test/scala/org/apache/servicemix/itests/Drools6IntegrationTests.scala b/itests/src/test/scala/org/apache/servicemix/itests/Drools6IntegrationTests.scala
index 371e138..a197c37 100644
--- a/itests/src/test/scala/org/apache/servicemix/itests/Drools6IntegrationTests.scala
+++ b/itests/src/test/scala/org/apache/servicemix/itests/Drools6IntegrationTests.scala
@@ -117,3 +117,16 @@ class Drools6SpringExamplesTest extends Drools6IntegrationTests {
     }
   }
 }
+
+/**
+ * Tests for the Camel Rest Server examples
+ */
+class Drools6CamelServiceExamplesTest extends Drools6IntegrationTests {
+
+  @Test
+  def testDroolsCamelServerExample = testWithFeature("examples-drools-camel-cxf-server") {
+    expect {
+      logging.containsMessage(line => line.contains("<execution-results><result identifier=\"customer\">"))
+    }
+  }
+}


[2/3] servicemix git commit: M-2497: Add features for Drools 6.2 (closes #27)

Posted by ks...@apache.org.
M-2497: Add features for Drools 6.2 (closes #27)

Thanks to Grzegorz Halajko for the pull request!!!


Project: http://git-wip-us.apache.org/repos/asf/servicemix/repo
Commit: http://git-wip-us.apache.org/repos/asf/servicemix/commit/f644027a
Tree: http://git-wip-us.apache.org/repos/asf/servicemix/tree/f644027a
Diff: http://git-wip-us.apache.org/repos/asf/servicemix/diff/f644027a

Branch: refs/heads/master
Commit: f644027aa779cb390459160e541181ee3d8d76db
Parents: c928d62
Author: Grzegorz Halajko <gh...@linuxpolska.pl>
Authored: Tue May 26 22:16:32 2015 +0200
Committer: Krzysztof Sobkowiak <kr...@gmail.com>
Committed: Tue May 26 23:21:08 2015 +0200

----------------------------------------------------------------------
 drools/src/main/resources/features.xml | 83 +++++++++++------------------
 1 file changed, 30 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/servicemix/blob/f644027a/drools/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/drools/src/main/resources/features.xml b/drools/src/main/resources/features.xml
index e99be6c..06b931d 100644
--- a/drools/src/main/resources/features.xml
+++ b/drools/src/main/resources/features.xml
@@ -1,11 +1,11 @@
 <?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
+    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
+    the License. You may obtain a copy of the License at
 
     http://www.apache.org/licenses/LICENSE-2.0
 
@@ -19,53 +19,43 @@
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
 
-    <feature name="kie" version="${drools6.version}" description="KIE API"
-             start-level="50">
-        <bundle>mvn:org.kie/kie-api/${drools6.version}</bundle>
-        <bundle>mvn:org.kie/kie-internal/${drools6.version}</bundle>
-    </feature>
+    <repository>mvn:org.apache.servicemix/apache-servicemix/${version}/xml/internal</repository>
 
-    <feature name="drools6-commons" version="${drools6.version}"
-             description="Drools 6 Commons" start-level="50">
+    <feature name="drools6-module" version="${drools6.version}"
+             description="Drools 6 core" start-level="50" resolver="(obr)">
         <feature>pax-cdi</feature>
         <bundle dependency="true">mvn:org.mvel/mvel2/2.2.4.Final</bundle>
         <bundle dependency="true">mvn:com.google.protobuf/protobuf-java/2.5.0</bundle>
-        <bundle dependency="true">
-            mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/3.5_1
-        </bundle>
-    </feature>
+        <bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/3.5_1</bundle>
 
-    <feature name="drools6-module" version="${drools6.version}"
-             description="Drools 6 core" start-level="50">
-        <feature version="${drools6.version}">drools6-commons</feature>
-        <feature version="${drools6.version}">kie</feature>
+        <bundle>mvn:org.kie/kie-api/${drools6.version}</bundle>
+        <bundle>mvn:org.kie/kie-internal/${drools6.version}</bundle>
         <bundle>mvn:org.drools/drools-core/${drools6.version}</bundle>
         <bundle>mvn:org.drools/drools-compiler/${drools6.version}</bundle>
         <bundle>mvn:org.drools/drools-osgi-integration/${drools6.version}</bundle>
     </feature>
 
-    <feature name="kie-aries-blueprint" version="${drools6.version}"
-             description="Drools 6 KIE Blueprint support" start-level="50">
-        <feature version="${drools6.version}">kie</feature>
-        <feature version="${drools6.version}">drools6-jpa</feature>
-        <feature version="${drools6.version}">jbpm</feature>
-        <feature version="${drools6.version}">jbpm-human-task</feature>
-        <bundle>mvn:org.kie/kie-aries-blueprint/${drools6.version}</bundle>
-    </feature>
-
     <feature name="drools6-jpa" version="${drools6.version}"
-             description="Drools 6 JPA support" start-level="50">
+             description="Drools 6 JPA support" start-level="50" resolver="(obr)">
         <feature version="${drools6.version}">drools6-module</feature>
         <feature version="[2.0,3.0)">jpa</feature>
         <bundle>mvn:org.drools/drools-persistence-jpa/${drools6.version}</bundle>
     </feature>
 
-    <feature name="jbpm" version="${drools6.version}" description="jBPM Engine support"
-             start-level="50">
+    <feature name="jbpm" version="${drools6.version}"
+             description="jBPM Engine support" start-level="50" resolver="(obr)">
         <feature version="${drools6.version}">drools6-module</feature>
         <feature version="${drools6.version}">drools6-jpa</feature>
-        <feature version="${drools6.version}">jbpm-commons</feature>
-        <feature version="${drools6.version}">jbpm-human-task</feature>
+        <!-- commons libs for jbpm -->
+        <bundle dependency="true">mvn:org.jboss.spec.javax.security.jacc/jboss-jacc-api_1.5_spec/1.0.0.Final</bundle>
+        <bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.quartz/1.8.6_1</bundle>
+        <bundle dependency="true">mvn:org.codehaus.jackson/jackson-core-asl/1.9.13</bundle>
+        <!-- jbpm-human -->
+        <bundle>mvn:org.jbpm/jbpm-human-task-core/${drools6.version}</bundle>
+        <bundle>mvn:org.jbpm/jbpm-human-task-workitems/${drools6.version}</bundle>
+        <bundle>mvn:org.jbpm/jbpm-human-task-jpa/${drools6.version}</bundle>
+        <bundle>mvn:org.jbpm/jbpm-human-task-audit/${drools6.version}</bundle>
+        <!-- jbpm engine -->
         <bundle>mvn:org.jbpm/jbpm-flow-builder/${drools6.version}</bundle>
         <bundle>mvn:org.jbpm/jbpm-flow/${drools6.version}</bundle>
         <bundle>mvn:org.jbpm/jbpm-bpmn2/${drools6.version}</bundle>
@@ -74,39 +64,26 @@
         <bundle>mvn:org.jbpm/jbpm-persistence-jpa/${drools6.version}</bundle>
     </feature>
 
-    <feature name="jbpm-human-task" version="${drools6.version}"
-             description="jBPM human task support" start-level="50">
-        <feature version="${drools6.version}">jbpm-commons</feature>
-        <bundle dependency="true">mvn:org.codehaus.jackson/jackson-core-asl/1.9.13</bundle>
-        <bundle>mvn:org.jbpm/jbpm-human-task-core/${drools6.version}</bundle>
-        <bundle>mvn:org.jbpm/jbpm-human-task-workitems/${drools6.version}</bundle>
-        <bundle>mvn:org.jbpm/jbpm-human-task-jpa/${drools6.version}</bundle>
-        <bundle>mvn:org.jbpm/jbpm-human-task-audit/${drools6.version}</bundle>
-    </feature>
-
-    <feature name="jbpm-commons" version="${drools6.version}"
-             description="jBPM Commons" start-level="50">
-        <feature version="[4.2,5.0)">hibernate</feature>
-        <bundle dependency="true">
-            mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.quartz/1.8.6_1
-        </bundle>
+    <feature name="kie-aries-blueprint" version="${drools6.version}"
+             description="Drools 6 KIE Blueprint support" start-level="50"
+             resolver="(obr)">
+        <feature version="${drools6.version}">jbpm</feature>
+        <bundle>mvn:org.kie/kie-aries-blueprint/${drools6.version}</bundle>
     </feature>
 
     <feature name="kie-spring" version="${drools6.version}"
-             description="KIE Spring support" start-level="50">
-        <feature version="${drools6.version}">kie</feature>
-        <feature version="${drools6.version}">drools6-jpa</feature>
+             description="KIE Spring support" start-level="50" resolver="(obr)">
         <feature version="${drools6.version}">jbpm</feature>
-        <feature version="${drools6.version}">jbpm-human-task</feature>
         <feature version="[3.1,4.0)">spring</feature>
         <feature version="[3.1,4.0)">spring-orm</feature>
         <bundle>mvn:org.kie/kie-spring/${drools6.version}</bundle>
     </feature>
 
     <feature name="kie-camel" version="${drools6.version}"
-             description="KIE Camel support" start-level="50">
+             description="KIE Camel support" start-level="50" resolver="(obr)">
         <feature version="${drools6.version}">kie-spring</feature>
         <feature version="${drools6.version}">jbpm</feature>
+
         <feature version="${camel.version}">camel-core</feature>
         <feature version="${camel.version}">camel-spring</feature>
         <feature version="${camel.version}">camel-cxf</feature>
@@ -117,4 +94,4 @@
 
         <bundle>mvn:org.kie/kie-camel/${drools6.version}</bundle>
     </feature>
-</features>
+</features>
\ No newline at end of file