| Commit in servicemix/base/src on MAIN | |||
| main/java/org/servicemix/components/drools/dsl/ForwardConsequenceFactory.java | +82 | added 1.1 | |
| /InvokeConsequenceFactory.java | +4 | -1 | 1.1 -> 1.2 |
| /JbiConsequence.java | +2 | -2 | 1.1 -> 1.2 |
| main/resources/META-INF/drools-servicemix.conf | +1 | 1.1 -> 1.2 | |
| test/java/org/servicemix/components/drools/DroolsWithJbiRulesForwardTest.java | +41 | added 1.1 | |
| test/resources/org/servicemix/components/drools/jbi-example-forward.xml | +21 | added 1.1 | |
| /jbi-rules-forward.xml | +21 | added 1.1 | |
| +172 | -3 | ||
Add a drools consequence to allow forwarding to several services
servicemix/base/src/main/java/org/servicemix/components/drools/dsl
ForwardConsequenceFactory.java added at 1.1
diff -N ForwardConsequenceFactory.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ForwardConsequenceFactory.java 29 Sep 2005 14:14:51 -0000 1.1 @@ -0,0 +1,82 @@
+/**
+ *
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ **/
+package org.servicemix.components.drools.dsl;
+
+import org.drools.rule.Rule;
+import org.drools.smf.Configuration;
+import org.drools.smf.ConsequenceFactory;
+import org.drools.smf.FactoryException;
+import org.drools.spi.Consequence;
+import org.drools.spi.RuleBaseContext;
+import org.drools.spi.Tuple;
+import org.servicemix.components.drools.JbiHelper;
+
+import javax.jbi.messaging.MessagingException;
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class ForwardConsequenceFactory implements ConsequenceFactory {
+ public Consequence newConsequence(Rule rule, RuleBaseContext ruleBaseContext, final Configuration configuration) throws FactoryException {
+ final String[] services = configuration.getAttribute("service").split(",");
+ return new JbiConsequence() {
+ protected void invokeJbiOperation(JbiHelper helper, Tuple tuple) throws MessagingException {
+ for (int i = 0; i < services.length; i++) {
+ QName service = toQName(configuration, services[i]);
+ helper.forwardToService(service, null, null);
+ }
+ }
+ };
+ }
+
+ /**
+ * Converts the String into a QName
+ */
+ protected QName toQName(Configuration configuration, String text) {
+ if (text == null) {
+ return null;
+ }
+ String[] names = configuration.getAttributeNames();
+ String localPart = text;
+ String prefix = null;
+ int idx = text.indexOf(':');
+ if (idx >= 0) {
+ prefix = "xmlns:" + text.substring(0, idx);
+ localPart = text.substring(idx + 1);
+ }
+ String uri = "";
+ for (int i = 0; i < names.length; i++) {
+ String name = names[i];
+ if (prefix == null) {
+ if ("xmlns".equals(name)) {
+ uri = configuration.getAttribute(name);
+ break;
+ }
+ }
+ else {
+ if (name.equals(prefix)) {
+ uri = configuration.getAttribute(name);
+ break;
+ }
+ }
+ }
+ System.out.println("Creating QName with uri: " + uri + " name: " + localPart);
+ return new QName(uri, localPart);
+ }
+}
servicemix/base/src/main/java/org/servicemix/components/drools/dsl
diff -u -r1.1 -r1.2 --- InvokeConsequenceFactory.java 26 Jul 2005 18:58:44 -0000 1.1 +++ InvokeConsequenceFactory.java 29 Sep 2005 14:14:51 -0000 1.2 @@ -30,7 +30,7 @@
import javax.xml.namespace.QName; /**
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class InvokeConsequenceFactory implements ConsequenceFactory {
public Consequence newConsequence(Rule rule, RuleBaseContext ruleBaseContext, Configuration configuration) throws FactoryException {
@@ -40,6 +40,9 @@
return new JbiConsequence() {
protected void invokeJbiOperation(JbiHelper helper, Tuple tuple) throws MessagingException {
helper.invoke(service, operation, interfaceName);
+ }
+ protected void forwardJbiOperation(JbiHelper helper, Tuple tuple) throws MessagingException {
+ helper.forwardToService(service, operation, interfaceName);
}
};
}
servicemix/base/src/main/java/org/servicemix/components/drools/dsl
diff -u -r1.1 -r1.2 --- JbiConsequence.java 26 Jul 2005 18:58:44 -0000 1.1 +++ JbiConsequence.java 29 Sep 2005 14:14:51 -0000 1.2 @@ -25,7 +25,7 @@
import javax.jbi.messaging.MessagingException; /**
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public abstract class JbiConsequence implements Consequence {
@@ -41,6 +41,6 @@
throw new ConsequenceException(e);
}
}
-
+
protected abstract void invokeJbiOperation(JbiHelper helper, Tuple tuple) throws MessagingException; }
servicemix/base/src/main/resources/META-INF
diff -u -r1.1 -r1.2 --- drools-servicemix.conf 26 Jul 2005 18:58:44 -0000 1.1 +++ drools-servicemix.conf 29 Sep 2005 14:14:51 -0000 1.2 @@ -4,3 +4,4 @@
ObjectType(class) : org.drools.semantics.base.ClassObjectTypeFactory Condition(condition) : org.servicemix.components.drools.dsl.JaxenConditionFactory Consequence(invoke) : org.servicemix.components.drools.dsl.InvokeConsequenceFactory
+Consequence(forward) : org.servicemix.components.drools.dsl.ForwardConsequenceFactory
servicemix/base/src/test/java/org/servicemix/components/drools
DroolsWithJbiRulesForwardTest.java added at 1.1
diff -N DroolsWithJbiRulesForwardTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ DroolsWithJbiRulesForwardTest.java 29 Sep 2005 14:14:51 -0000 1.1 @@ -0,0 +1,41 @@
+/**
+ *
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ **/
+package org.servicemix.components.drools;
+
+import org.servicemix.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class DroolsWithJbiRulesForwardTest extends DroolsTest {
+
+ public void testFiringRules() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "droolsRouter");
+
+ sendMessages(service, 3);
+ assertMessagesReceived(4);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/servicemix/components/drools/jbi-example-forward.xml");
+ }
+}
servicemix/base/src/test/resources/org/servicemix/components/drools
jbi-example-forward.xml added at 1.1
diff -N jbi-example-forward.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ jbi-example-forward.xml 29 Sep 2005 14:14:51 -0000 1.1 @@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns:foo="http://servicemix.org/cheese/"> + + <!-- the JBI container --> + <container id="jbi"> + <components> + + <!-- START SNIPPET: drools --> + <component id="droolsRouter" service="foo:droolsRouter" class="org.servicemix.components.drools.DroolsComponent"> + <property name="ruleBaseResource" value="classpath:org/servicemix/components/drools/jbi-rules-forward.xml" /> + </component> + <!-- END SNIPPET: drools --> + + <component id="receiver" service="foo:receiver" class="org.servicemix.examples.ReceiverComponent"/> + </components> + </container> + + <bean id="client" class="org.servicemix.client.DefaultServiceMixClient"> + <constructor-arg ref="jbi"/> + </bean> +</beans>
servicemix/base/src/test/resources/org/servicemix/components/drools
jbi-rules-forward.xml added at 1.1
diff -N jbi-rules-forward.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ jbi-rules-forward.xml 29 Sep 2005 14:14:51 -0000 1.1 @@ -0,0 +1,21 @@
+<!-- START SNIPPET: drools --> +<rule-set name="cheese rules" + xmlns="http://drools.org/rules" + xmlns:jbi="http://drools.org/semantics/servicemix" + xmlns:foo="http://servicemix.org/cheese/"> + + <application-data identifier="jbi">org.servicemix.components.drools.JbiHelper</application-data> + <application-data identifier="context">javax.jbi.component.ComponentContext</application-data> + <application-data identifier="deliveryChannel">javax.jbi.messaging.DeliveryChannel</application-data> + + <rule name="Ignore 2 message"> + <parameter identifier="exchange"> + <class>javax.jbi.messaging.MessageExchange</class> + </parameter> + + <jbi:condition>/*/@id != 2</jbi:condition> + <jbi:forward service="foo:receiver,foo:receiver"/> + </rule> + +</rule-set> +<!-- END SNIPPET: drools -->
