You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/02/28 14:38:03 UTC
svn commit: r631970 - in
/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools:
DroolsEndpoint.java model/JbiHelper.java
Author: gnodet
Date: Thu Feb 28 05:38:02 2008
New Revision: 631970
URL: http://svn.apache.org/viewvc?rev=631970&view=rev
Log:
SM-1248: servicemix-drools enhancements
Modified:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java
Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java?rev=631970&r1=631969&r2=631970&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java Thu Feb 28 05:38:02 2008
@@ -19,6 +19,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
+import java.util.List;
import java.util.Map;
import javax.jbi.JBIException;
@@ -49,7 +50,10 @@
private Resource ruleBaseResource;
private URL ruleBaseURL;
private NamespaceContext namespaceContext;
+ private QName defaultTargetService;
+ private String defaultTargetURI;
private Map<String, Object> globals;
+ private List<Object> assertedObjects;
public DroolsEndpoint() {
super();
@@ -171,15 +175,26 @@
*/
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();
+ postProcess(exchange, memory);
+ }
+
+ protected void postProcess(MessageExchange exchange, WorkingMemory memory) throws Exception {
+ if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+ String uri = getDefaultRouteURI();
+ if (uri != null) {
+ JbiHelper helper = (JbiHelper) memory.getGlobal("jbi");
+ helper.route(uri);
+ }
+ }
+ if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+ fail(exchange, new Exception("No rules have handled the exchange. Check your rule base."));
+ }
}
protected WorkingMemory createWorkingMemory(MessageExchange exchange) throws Exception {
@@ -188,10 +203,51 @@
protected void populateWorkingMemory(WorkingMemory memory, MessageExchange exchange) throws Exception {
memory.setGlobal("jbi", new JbiHelper(this, exchange, memory));
+ if (assertedObjects != null) {
+ for (Object o : assertedObjects) {
+ memory.assertObject(o);
+ }
+ }
if (globals != null) {
for (Map.Entry<String, Object> e : globals.entrySet()) {
memory.setGlobal(e.getKey(), e.getValue());
}
+ }
+ }
+
+ public QName getDefaultTargetService() {
+ return defaultTargetService;
+ }
+
+ public void setDefaultTargetService(QName defaultTargetService) {
+ this.defaultTargetService = defaultTargetService;
+ }
+
+ public String getDefaultTargetURI() {
+ return defaultTargetURI;
+ }
+
+ public void setDefaultTargetURI(String defaultTargetURI) {
+ this.defaultTargetURI = defaultTargetURI;
+ }
+
+ public List<Object> getAssertedObjects() {
+ return assertedObjects;
+ }
+
+ public void setAssertedObjects(List<Object> assertedObjects) {
+ this.assertedObjects = assertedObjects;
+ }
+
+ public String getDefaultRouteURI() {
+ if (defaultTargetURI != null) {
+ return defaultTargetURI;
+ } else if (defaultTargetService != null) {
+ String nsURI = defaultTargetService.getNamespaceURI();
+ String sep = (nsURI.indexOf("/") > 0) ? "/" : ":";
+ return "service:" + nsURI + sep + defaultTargetService.getLocalPart();
+ } else {
+ return null;
}
}
}
Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java?rev=631970&r1=631969&r2=631970&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java Thu Feb 28 05:38:02 2008
@@ -27,8 +27,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.JbiConstants;
import org.apache.servicemix.client.ServiceMixClient;
import org.apache.servicemix.client.ServiceMixClientFacade;
+import org.apache.servicemix.common.EndpointSupport;
import org.apache.servicemix.drools.DroolsEndpoint;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jbi.resolver.URIResolver;
@@ -99,13 +101,27 @@
}
}
*/
-
public void route(String uri) throws MessagingException {
+ routeTo(null, uri);
+ }
+
+ public void routeTo(String content, String uri) throws MessagingException {
MessageExchange me = this.exchange.getInternalExchange();
- NormalizedMessage in = me.getMessage("in");
+ String correlationId = (String)exchange.getProperty(JbiConstants.CORRELATION_ID);
+ NormalizedMessage in = null;
+ if (content == null) {
+ in = me.getMessage("in");
+ } else {
+ in = me.createMessage();
+ in.setContent(new StringSource(content));
+ }
MessageExchange newMe = getChannel().createExchangeFactory().createExchange(me.getPattern());
URIResolver.configureExchange(newMe, getContext(), uri);
MessageUtil.transferToIn(in, newMe);
+ // Set the sender endpoint property
+ String key = EndpointSupport.getKey(endpoint);
+ newMe.setProperty(JbiConstants.SENDER_ENDPOINT, key);
+ newMe.setProperty(JbiConstants.CORRELATION_ID, correlationId);
getChannel().sendSync(newMe);
if (newMe.getStatus() == ExchangeStatus.DONE) {
me.setStatus(ExchangeStatus.DONE);
@@ -124,6 +140,10 @@
}
update();
}
+
+ public void routeToDefault(String content) throws MessagingException {
+ routeTo(content, endpoint.getDefaultRouteURI());
+ }
public void fault(String content) throws Exception {
MessageExchange me = this.exchange.getInternalExchange();
@@ -138,6 +158,8 @@
}
update();
}
+
+
public void answer(String content) throws Exception {
MessageExchange me = this.exchange.getInternalExchange();