servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r470499 - in /incubator/servicemix/trunk/servicemix-drools: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/servicemix/ src/main/java/org/apache/servicemix/drools/ src/main/java/org/apa...
Date Thu, 02 Nov 2006 20:08:13 GMT
Author: gnodet
Date: Thu Nov  2 12:08:11 2006
New Revision: 470499

URL: http://svn.apache.org/viewvc?view=rev&rev=470499
Log:
SM-734: Drools 3.0 Service Engine
The SE has currently only been tested with routing, where the SE acts as a proxy to a dynamically selected target

Added:
    incubator/servicemix/trunk/servicemix-drools/   (with props)
    incubator/servicemix/trunk/servicemix-drools/pom.xml
    incubator/servicemix/trunk/servicemix-drools/src/
    incubator/servicemix/trunk/servicemix-drools/src/main/
    incubator/servicemix/trunk/servicemix-drools/src/main/java/
    incubator/servicemix/trunk/servicemix-drools/src/main/java/org/
    incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/
    incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/
    incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/
    incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsComponent.java
    incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java
    incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/
    incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Exchange.java
    incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Fault.java
    incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java
    incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Message.java
    incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/package.html
    incubator/servicemix/trunk/servicemix-drools/src/main/resources/
    incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/
    incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/DISCLAIMER
    incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/LICENSE
    incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/NOTICE
    incubator/servicemix/trunk/servicemix-drools/src/test/
    incubator/servicemix/trunk/servicemix-drools/src/test/java/
    incubator/servicemix/trunk/servicemix-drools/src/test/java/org/
    incubator/servicemix/trunk/servicemix-drools/src/test/java/org/apache/
    incubator/servicemix/trunk/servicemix-drools/src/test/java/org/apache/servicemix/
    incubator/servicemix/trunk/servicemix-drools/src/test/java/org/apache/servicemix/drools/
    incubator/servicemix/trunk/servicemix-drools/src/test/java/org/apache/servicemix/drools/DroolsComponentTest.java
    incubator/servicemix/trunk/servicemix-drools/src/test/resources/
    incubator/servicemix/trunk/servicemix-drools/src/test/resources/router.drl

Propchange: incubator/servicemix/trunk/servicemix-drools/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Nov  2 12:08:11 2006
@@ -0,0 +1,4 @@
+.classpath
+.project
+cobertura.ser
+target

Added: incubator/servicemix/trunk/servicemix-drools/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-drools/pom.xml?view=auto&rev=470499
==============================================================================
--- incubator/servicemix/trunk/servicemix-drools/pom.xml (added)
+++ incubator/servicemix/trunk/servicemix-drools/pom.xml Thu Nov  2 12:08:11 2006
@@ -0,0 +1,124 @@
+<?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.
+
+-->
+<project
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.servicemix</groupId>
+    <artifactId>servicemix</artifactId>
+    <version>3.1-incubating-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>servicemix-drools</artifactId>
+  <packaging>jbi-component</packaging>
+  <name>ServiceMix :: Drools Service Engine</name>
+  <description>A Rules Service Engine based on Drools</description>
+
+  <repositories>
+    <repository>
+      <id>jboss</id>
+      <url>http://repository.jboss.com/maven2</url>
+    </repository>
+  </repositories>
+
+  <properties>
+    <drools-version>3.0.3</drools-version>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.servicemix</groupId>
+      <artifactId>servicemix-shared</artifactId>      
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicemix</groupId>
+      <artifactId>servicemix-core</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.drools</groupId>
+      <artifactId>drools-core</artifactId>
+      <version>${drools-version}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>jung</groupId>
+          <artifactId>jung</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>xstream</groupId>
+          <artifactId>xstream</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>xpp3</groupId>
+          <artifactId>xpp3</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.drools</groupId>
+      <artifactId>drools-compiler</artifactId>
+      <version>${drools-version}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.commons</groupId>
+          <artifactId>commons-jci-janino</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.servicemix.tooling</groupId>
+        <artifactId>jbi-maven-plugin</artifactId>   
+        <version>${servicemix-version}</version>     
+        <extensions>true</extensions>
+        <configuration>
+          <type>service-engine</type>
+          <component>org.apache.servicemix.drools.DroolsComponent</component>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.xbean</groupId>
+        <artifactId>maven-xbean-plugin</artifactId>
+        <version>${xbean-version}</version>
+        <executions>
+          <execution>
+            <configuration>
+              <namespace>http://servicemix.apache.org/drools/1.0</namespace>
+            </configuration>
+            <goals>
+              <goal>mapping</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsComponent.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsComponent.java?view=auto&rev=470499
==============================================================================
--- incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsComponent.java (added)
+++ incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsComponent.java Thu Nov  2 12:08:11 2006
@@ -0,0 +1,54 @@
+/*
+ * 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.drools;
+
+import java.util.List;
+
+import org.apache.servicemix.common.DefaultComponent;
+
+/**
+ * 
+ * @author gnodet
+ * @org.apache.xbean.XBean element="component"
+ */
+public class DroolsComponent extends DefaultComponent {
+
+    private DroolsEndpoint[] endpoints;
+    
+    protected List getConfiguredEndpoints() {
+        return asList(endpoints);
+    }
+
+    protected Class[] getEndpointClasses() {
+        return new Class[] { DroolsEndpoint.class };
+    }
+
+    /**
+     * @return the endpoints
+     */
+    public DroolsEndpoint[] getEndpoints() {
+        return endpoints;
+    }
+
+    /**
+     * @param endpoints the endpoints to set
+     */
+    public void setEndpoints(DroolsEndpoint[] endpoints) {
+        this.endpoints = endpoints;
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java?view=auto&rev=470499
==============================================================================
--- incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java (added)
+++ incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java Thu Nov  2 12:08:11 2006
@@ -0,0 +1,161 @@
+/*
+ * 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.drools;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import javax.jbi.JBIException;
+import javax.jbi.management.DeploymentException;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.common.DefaultComponent;
+import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.common.endpoints.ProviderEndpoint;
+import org.apache.servicemix.drools.model.JbiHelper;
+import org.drools.RuleBase;
+import org.drools.WorkingMemory;
+import org.drools.compiler.RuleBaseLoader;
+import org.springframework.core.io.Resource;
+
+/**
+ * 
+ * @author gnodet
+ * @org.apache.xbean.XBean element="endpoint"
+ */
+public class DroolsEndpoint extends ProviderEndpoint {
+
+    private RuleBase ruleBase;
+    private Resource ruleBaseResource;
+    private URL ruleBaseURL;
+    
+    public DroolsEndpoint() {
+        super();
+    }
+
+    public DroolsEndpoint(DefaultComponent component, ServiceEndpoint endpoint) {
+        super(component, endpoint);
+    }
+
+    public DroolsEndpoint(ServiceUnit su, QName service, String endpoint) {
+        super(su, service, endpoint);
+    }
+
+    /**
+     * @return the ruleBase
+     */
+    public RuleBase getRuleBase() {
+        return ruleBase;
+    }
+
+    /**
+     * @param ruleBase the ruleBase to set
+     */
+    public void setRuleBase(RuleBase ruleBase) {
+        this.ruleBase = ruleBase;
+    }
+
+    /**
+     * @return the ruleBaseResource
+     */
+    public Resource getRuleBaseResource() {
+        return ruleBaseResource;
+    }
+
+    /**
+     * @param ruleBaseResource the ruleBaseResource to set
+     */
+    public void setRuleBaseResource(Resource ruleBaseResource) {
+        this.ruleBaseResource = ruleBaseResource;
+    }
+
+    /**
+     * @return the ruleBaseURL
+     */
+    public URL getRuleBaseURL() {
+        return ruleBaseURL;
+    }
+
+    /**
+     * @param ruleBaseURL the ruleBaseURL to set
+     */
+    public void setRuleBaseURL(URL ruleBaseURL) {
+        this.ruleBaseURL = ruleBaseURL;
+    }
+    
+    public void validate() throws DeploymentException {
+        super.validate();
+        if (ruleBase == null && ruleBaseResource == null && ruleBaseURL == null) {
+            throw new DeploymentException("Property ruleBase, ruleBaseResource or ruleBaseURL must be set");
+        }
+    }
+    
+    public void start() throws Exception {
+        super.start();
+        if (ruleBase == null) {
+            InputStream is = null;
+            try {
+                if (ruleBaseResource != null) {
+                    is = ruleBaseResource.getInputStream();
+                }
+                else if (ruleBaseURL != null) {
+                    is = ruleBaseURL.openStream();
+                }
+                else {
+                    throw new IllegalArgumentException("Property ruleBase, ruleBaseResource or ruleBaseURL must be set");
+                }
+                RuleBaseLoader loader = RuleBaseLoader.getInstance();
+                ruleBase = loader.loadFromReader(new InputStreamReader(is));
+            } catch (Exception e) {
+                throw new JBIException(e);
+            } finally {
+                if (is != null) {
+                    is.close();
+                }
+            }
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.common.endpoints.ProviderEndpoint#process(javax.jbi.messaging.MessageExchange, javax.jbi.messaging.NormalizedMessage)
+     */
+    public void process(MessageExchange exchange) throws Exception {
+        drools(exchange);
+        if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+            fail(exchange, new Exception("No rules have handled the exchange. Check your rule base."));
+        }
+    }
+    
+    protected void drools(MessageExchange exchange) throws Exception {
+        WorkingMemory memory = createWorkingMemory(exchange);
+        populateWorkingMemory(memory, exchange);
+        memory.fireAllRules();
+    }
+    
+    protected WorkingMemory createWorkingMemory(MessageExchange exchange) throws Exception {
+        WorkingMemory memory = ruleBase.newWorkingMemory();
+        return memory;
+    }
+
+    protected void populateWorkingMemory(WorkingMemory memory, MessageExchange exchange) throws Exception {
+        memory.setGlobal("jbi", new JbiHelper(this, exchange, memory));
+    }
+}

Added: incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Exchange.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Exchange.java?view=auto&rev=470499
==============================================================================
--- incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Exchange.java (added)
+++ incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Exchange.java Thu Nov  2 12:08:11 2006
@@ -0,0 +1,122 @@
+/*
+ * 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.drools.model;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOptionalOut;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.messaging.RobustInOnly;
+
+public class Exchange {
+
+    public static final String IN_ONLY = "InOnly";
+    public static final String ROBUST_IN_ONLY = "RobustInOnly";
+    public static final String IN_OUT = "InOut";
+    public static final String IN_OPTIONAL_OUT = "InOptionalOut";
+    
+    public static final String ACTIVE = "Active";
+    public static final String ERROR = "Error";
+    public static final String DONE = "Done";
+    
+    private final MessageExchange exchange;
+    private Message in;
+    private Message out;
+    private Message fault;
+    
+    public Exchange(MessageExchange exchange) {
+        this.exchange = exchange;
+        update();
+    }
+    
+    public MessageExchange getInternalExchange() {
+        return exchange;
+    }
+    
+    public String getMep() {
+        if (exchange instanceof InOnly) {
+            return IN_ONLY;
+        } else if (exchange instanceof RobustInOnly) {
+            return ROBUST_IN_ONLY;
+        } else if (exchange instanceof InOut) {
+            return IN_OUT;
+        } else if (exchange instanceof InOptionalOut) {
+            return IN_OPTIONAL_OUT;
+        } else {
+            return exchange.getPattern().toString();
+        }
+    }
+    
+    public String getStatus() {
+        if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+            return ACTIVE;
+        } else if (exchange.getStatus() == ExchangeStatus.DONE) {
+            return DONE;
+        } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
+            return ERROR;
+        } else {
+            throw new IllegalStateException("Unkown exchange status");
+        }
+    }
+    
+    public String getOperation() {
+        return exchange.getOperation() != null ? exchange.getOperation().toString() : null;
+    }
+    
+    public Object getProperty(String name) {
+        return exchange.getProperty(name);
+    }
+    
+    public void setProperty(String name, Object value) {
+        exchange.setProperty(name, value);
+    }
+    
+    public Message getIn() {
+        return in;
+    }
+    
+    public Message getOut() {
+        return out;
+    }
+    
+    public Message getFault() {
+        return fault;
+    }
+    
+    protected Message getMessage(String name) {
+        NormalizedMessage msg = exchange.getMessage(name);
+        return msg != null ? new Message(msg) : null;
+    }
+    
+    protected void update() {
+        if (in == null) {
+            NormalizedMessage msg = exchange.getMessage("in");
+            in = msg != null ? new Message(msg) : null;
+        }
+        if (out == null) {
+            NormalizedMessage msg = exchange.getMessage("out");
+            out = msg != null ? new Message(msg) : null;
+        }
+        if (fault == null) {
+            javax.jbi.messaging.Fault msg = exchange.getFault();
+            fault = msg != null ? new Fault(msg) : null;
+        }
+    }
+    
+}

Added: incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Fault.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Fault.java?view=auto&rev=470499
==============================================================================
--- incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Fault.java (added)
+++ incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Fault.java Thu Nov  2 12:08:11 2006
@@ -0,0 +1,10 @@
+package org.apache.servicemix.drools.model;
+
+
+public class Fault extends Message {
+
+    public Fault(javax.jbi.messaging.Fault message) {
+        super(message);
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java?view=auto&rev=470499
==============================================================================
--- incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java (added)
+++ incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java Thu Nov  2 12:08:11 2006
@@ -0,0 +1,139 @@
+/*
+ * 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.drools.model;
+
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.client.ServiceMixClientFacade;
+import org.apache.servicemix.drools.DroolsEndpoint;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.resolver.URIResolver;
+import org.apache.servicemix.jbi.util.MessageUtil;
+import org.drools.FactHandle;
+import org.drools.WorkingMemory;
+
+/**
+ * A helper class for use inside a rule to forward a message to an endpoint
+ *
+ * @version $Revision: 426415 $
+ */
+public class JbiHelper {
+    
+    private DroolsEndpoint endpoint;
+    private Exchange exchange;
+    private WorkingMemory memory;
+    private FactHandle exchangeFactHandle;
+
+    public JbiHelper(DroolsEndpoint endpoint, 
+                     MessageExchange exchange,
+                     WorkingMemory memory) {
+        this.endpoint = endpoint;
+        this.exchange = new Exchange(exchange);
+        this.memory = memory;
+        this.exchangeFactHandle = this.memory.assertObject(this.exchange);
+    }
+
+    public DroolsEndpoint getEndpoint() {
+        return endpoint;
+    }
+    
+    public ComponentContext getContext() {
+        return endpoint.getContext();
+    }
+    
+    public DeliveryChannel getChannel() throws MessagingException {
+        return getContext().getDeliveryChannel();
+    }
+    
+    public ServiceMixClient getClient() {
+        return new ServiceMixClientFacade(getContext());
+    }
+
+    public Exchange getExchange() {
+        return exchange;
+    }
+
+    /**
+     * Forwards the inbound message to the given
+     *
+     * @param uri
+     * @param localPart
+     */
+    /*
+    public void forward(String uri) throws MessagingException {
+        if (exchange instanceof InOnly || exchange instanceof RobustInOnly) {
+            MessageExchange me = getChannel().createExchangeFactory().createExchange(exchange.getPattern());
+            URIResolver.configureExchange(me, getContext(), uri);
+            MessageUtil.transferToIn(in, me);
+            getChannel().sendSync(me);
+        } else {
+            throw new MessagingException("Only InOnly and RobustInOnly exchanges can be forwarded");
+        }
+    }
+    */
+
+    public void route(String uri) throws MessagingException {
+        MessageExchange exchange = this.exchange.getInternalExchange();
+        NormalizedMessage in = exchange.getMessage("in");
+        MessageExchange me = getChannel().createExchangeFactory().createExchange(exchange.getPattern());
+        URIResolver.configureExchange(me, getContext(), uri);
+        MessageUtil.transferToIn(in, me);
+        getChannel().sendSync(me);
+        if (me.getStatus() == ExchangeStatus.DONE) {
+            exchange.setStatus(ExchangeStatus.DONE);
+            getChannel().send(exchange);
+        } else if (me.getStatus() == ExchangeStatus.ERROR) {
+            exchange.setStatus(ExchangeStatus.ERROR);
+            exchange.setError(me.getError());
+            getChannel().send(exchange);
+        } else {
+            if (me.getFault() != null) {
+                MessageUtil.transferFaultToFault(me, exchange);
+            } else {
+                MessageUtil.transferOutToOut(me, exchange);
+            }
+            getChannel().sendSync(exchange);
+        }
+        update();
+    }
+    
+    public void fault(String content) throws Exception {
+        MessageExchange exchange = this.exchange.getInternalExchange();
+        if (exchange instanceof InOnly) {
+            exchange.setError(new Exception(content));
+            getChannel().send(exchange);
+        } else {
+            Fault fault = exchange.createFault();
+            fault.setContent(new StringSource(content));
+            exchange.setFault(fault);
+            getChannel().sendSync(exchange);
+        }
+        update();
+    }
+    
+    protected void update() {
+        this.memory.modifyObject(this.exchangeFactHandle, this.exchange);
+    }
+}

Added: incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Message.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Message.java?view=auto&rev=470499
==============================================================================
--- incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Message.java (added)
+++ incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Message.java Thu Nov  2 12:08:11 2006
@@ -0,0 +1,65 @@
+/*
+ * 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.drools.model;
+
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.servicemix.expression.JAXPBooleanXPathExpression;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+
+public class Message {
+
+    private final static SourceTransformer TRANFORMER = new SourceTransformer();
+    
+    private final NormalizedMessage message;
+    
+    public Message(NormalizedMessage message) {
+        this.message = message;
+        // Make sure message is re-readable
+        Source content = message.getContent();
+        if (content != null) {
+            try {
+                content = new DOMSource(TRANFORMER.toDOMElement(content));
+                message.setContent(content);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+        
+    }
+    
+    public NormalizedMessage getInternalMessage() {
+        return this.message;
+    }
+    
+    public boolean xpath(String xpath) throws Exception {
+        JAXPBooleanXPathExpression expression = new JAXPBooleanXPathExpression(xpath);
+        Boolean b = (Boolean) expression.evaluate(null, message);
+        return b.booleanValue();
+    }
+    
+    public Object getProperty(String name) {
+        return message.getProperty(name);
+    }
+    
+    public void setProperty(String name, Object value) {
+        message.setProperty(name, value);
+    }
+    
+}

Added: incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/package.html
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/package.html?view=auto&rev=470499
==============================================================================
--- incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/package.html (added)
+++ incubator/servicemix/trunk/servicemix-drools/src/main/java/org/apache/servicemix/drools/package.html Thu Nov  2 12:08:11 2006
@@ -0,0 +1,27 @@
+<!--
+
+    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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+A component which peforms rules based routing using <a href="http://drools.org/">Drools</a> to decide where to route the message.
+
+</body>
+</html>

Added: incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/DISCLAIMER
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/DISCLAIMER?view=auto&rev=470499
==============================================================================
--- incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/DISCLAIMER (added)
+++ incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/DISCLAIMER Thu Nov  2 12:08:11 2006
@@ -0,0 +1,6 @@
+Apache ServiceMix is an effort undergoing incubation at the Apache Software Foundation (ASF), sponsored by the Geronimo PMC. 
+Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, 
+communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. 
+
+While incubation status is not necessarily a reflection of the completeness or stability of the code, it does 
+indicate that the project has yet to be fully endorsed by the ASF.

Added: incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/LICENSE
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/LICENSE?view=auto&rev=470499
==============================================================================
--- incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/LICENSE (added)
+++ incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/LICENSE Thu Nov  2 12:08:11 2006
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   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.
+

Added: incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/NOTICE?view=auto&rev=470499
==============================================================================
--- incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/NOTICE (added)
+++ incubator/servicemix/trunk/servicemix-drools/src/main/resources/META-INF/NOTICE Thu Nov  2 12:08:11 2006
@@ -0,0 +1,8 @@
+   =========================================================================
+   ==  NOTICE file for use with the Apache License, Version 2.0,          ==
+   ==  in this case for the Apache ServiceMix distribution.               ==
+   =========================================================================
+
+   This product contains software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+

Added: incubator/servicemix/trunk/servicemix-drools/src/test/java/org/apache/servicemix/drools/DroolsComponentTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-drools/src/test/java/org/apache/servicemix/drools/DroolsComponentTest.java?view=auto&rev=470499
==============================================================================
--- incubator/servicemix/trunk/servicemix-drools/src/test/java/org/apache/servicemix/drools/DroolsComponentTest.java (added)
+++ incubator/servicemix/trunk/servicemix-drools/src/test/java/org/apache/servicemix/drools/DroolsComponentTest.java Thu Nov  2 12:08:11 2006
@@ -0,0 +1,164 @@
+/*
+ * 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.drools;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOut;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.components.util.MockServiceComponent;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.tck.ReceiverComponent;
+import org.springframework.core.io.ClassPathResource;
+import org.w3c.dom.Element;
+
+public class DroolsComponentTest extends TestCase {
+
+    private JBIContainer jbi;
+    private DroolsComponent drools;
+    private ServiceMixClient client;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        jbi = new JBIContainer();
+        jbi.setEmbedded(true);
+        jbi.init();
+        client = new DefaultServiceMixClient(jbi);
+    }
+    
+    protected void tearDown() throws Exception {
+        jbi.shutDown();
+    }
+    
+    public void testRouteInOnly() throws Exception {
+        drools = new DroolsComponent();
+        DroolsEndpoint endpoint = new DroolsEndpoint(drools.getServiceUnit(),
+                                                     new QName("drools"), "endpoint");
+        endpoint.setRuleBaseResource(new ClassPathResource("router.drl"));
+        drools.setEndpoints(new DroolsEndpoint[] { endpoint });
+        jbi.activateComponent(drools, "servicemix-drools");
+        
+        ReceiverComponent r1 = new ReceiverComponent(new QName("target1"), "endpoint");
+        ReceiverComponent r2 = new ReceiverComponent(new QName("target2"), "endpoint");
+        ReceiverComponent r3 = new ReceiverComponent(new QName("target3"), "endpoint");
+        jbi.activateComponent(r1, "receiver1");
+        jbi.activateComponent(r2, "receiver2");
+        jbi.activateComponent(r3, "receiver3");
+        
+        jbi.start();
+        
+        InOnly me = client.createInOnlyExchange();
+        me.setService(new QName("drools"));
+        me.getInMessage().setContent(new StringSource("<test id='0' />"));
+        client.sendSync(me);
+        assertEquals(ExchangeStatus.ERROR, me.getStatus());
+        
+        me = client.createInOnlyExchange();
+        me.setService(new QName("drools"));
+        me.getInMessage().setContent(new StringSource("<test id='1' />"));
+        client.sendSync(me);
+
+        me = client.createInOnlyExchange();
+        me.setService(new QName("drools"));
+        me.getInMessage().setContent(new StringSource("<test id='2' />"));
+        client.sendSync(me);
+        
+        me = client.createInOnlyExchange();
+        me.setService(new QName("drools"));
+        me.getInMessage().setContent(new StringSource("<test id='3' />"));
+        me.getInMessage().setProperty("prop", Boolean.TRUE);
+        client.sendSync(me);
+        
+        me = client.createInOnlyExchange();
+        me.setService(new QName("drools"));
+        me.getInMessage().setContent(new StringSource("<test id='4' />"));
+        client.sendSync(me);
+        assertEquals(ExchangeStatus.ERROR, me.getStatus());
+        
+        r1.getMessageList().assertMessagesReceived(1);
+        r2.getMessageList().assertMessagesReceived(1);
+        r3.getMessageList().assertMessagesReceived(1);
+    }
+    
+    public void testRouteInOut() throws Exception {
+        drools = new DroolsComponent();
+        DroolsEndpoint endpoint = new DroolsEndpoint(drools.getServiceUnit(),
+                                                     new QName("drools"), "endpoint");
+        endpoint.setRuleBaseResource(new ClassPathResource("router.drl"));
+        drools.setEndpoints(new DroolsEndpoint[] { endpoint });
+        jbi.activateComponent(drools, "servicemix-drools");
+        
+        MockServiceComponent m1 = new MockServiceComponent(new QName("target1"), "endpoint");
+        m1.setResponseContent(new StringSource("<target1/>"));
+        MockServiceComponent m2 = new MockServiceComponent(new QName("target2"), "endpoint");
+        m2.setResponseContent(new StringSource("<target2/>"));
+        MockServiceComponent m3 = new MockServiceComponent(new QName("target3"), "endpoint");
+        m3.setResponseContent(new StringSource("<target3/>"));
+        jbi.activateComponent(m1, "mock1");
+        jbi.activateComponent(m2, "mock2");
+        jbi.activateComponent(m3, "mock3");
+        
+        jbi.start();
+        
+        InOut me = client.createInOutExchange();
+        me.setService(new QName("drools"));
+        me.getInMessage().setContent(new StringSource("<test id='0' />"));
+        client.sendSync(me);
+        assertNotNull(me.getFault());
+        client.done(me);
+        
+        me = client.createInOutExchange();
+        me.setService(new QName("drools"));
+        me.getInMessage().setContent(new StringSource("<test id='1' />"));
+        client.sendSync(me);
+        Element e = new SourceTransformer().toDOMElement(me.getOutMessage());
+        assertEquals("target1", e.getLocalName());
+        client.done(me);
+
+        me = client.createInOutExchange();
+        me.setService(new QName("drools"));
+        me.getInMessage().setContent(new StringSource("<test id='2' />"));
+        client.sendSync(me);
+        e = new SourceTransformer().toDOMElement(me.getOutMessage());
+        assertEquals("target2", e.getLocalName());
+        client.done(me);
+
+        me = client.createInOutExchange();
+        me.setService(new QName("drools"));
+        me.getInMessage().setContent(new StringSource("<test id='3' />"));
+        me.getInMessage().setProperty("prop", Boolean.TRUE);
+        client.sendSync(me);
+        e = new SourceTransformer().toDOMElement(me.getOutMessage());
+        assertEquals("target3", e.getLocalName());
+        client.done(me);
+
+        me = client.createInOutExchange();
+        me.setService(new QName("drools"));
+        me.getInMessage().setContent(new StringSource("<test id='4' />"));
+        client.sendSync(me);
+        assertEquals(ExchangeStatus.ERROR, me.getStatus());
+        
+    }
+    
+}

Added: incubator/servicemix/trunk/servicemix-drools/src/test/resources/router.drl
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-drools/src/test/resources/router.drl?view=auto&rev=470499
==============================================================================
--- incubator/servicemix/trunk/servicemix-drools/src/test/resources/router.drl (added)
+++ incubator/servicemix/trunk/servicemix-drools/src/test/resources/router.drl Thu Nov  2 12:08:11 2006
@@ -0,0 +1,54 @@
+/*
+ * 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.drools
+ 
+import org.apache.servicemix.drools.model.Exchange;
+
+global org.apache.servicemix.drools.model.JbiHelper jbi;
+ 
+rule "Unspecified id"
+	when
+		me : Exchange( status == Exchange.ACTIVE, in : in != null )
+		eval( in.xpath("/test/@id <= 0") )
+	then
+		jbi.fault( "<fault>Id must be > 0</fault>" );
+end
+
+rule "Route to target1"
+	when
+		me : Exchange( status == Exchange.ACTIVE, in : in != null )
+		eval( in.xpath("/test/@id = 1") )
+	then
+		jbi.route( "service::target1" );
+end
+
+rule "Route to target2"
+	when
+		me : Exchange( status == Exchange.ACTIVE, in : in != null )
+		eval( in.xpath("/test/@id = 2") )
+	then
+		jbi.route( "service::target2" );
+end
+
+rule "Route to target3"
+	when
+		me : Exchange( status == Exchange.ACTIVE, in : in != null )
+		eval( in.getProperty("prop") != null )
+	then
+		jbi.route( "service::target3" );
+end
+



Mime
View raw message