[jboss-dev-forums] [Design of JBoss ESB] - Re: Design of a Content Based Routing Service

ddunkin do-not-reply at jboss.com
Thu Nov 2 14:10:27 EST 2006


I think this could be accomplished through DSL and helper classes. Here's some untested code to show the direction:

Here's what the new rules might look like:

  | #created on: Oct 30, 2006
  | package com.jboss.soa.esb.routing.cbr
  | 
  | #list any import classes here.
  | import org.jboss.soa.esb.message.Message;
  | import org.jboss.soa.esb.message.format.MessageType;
  | 
  | #declare any global variables here
  | global java.util.List destinationServices;
  | 
  | expander JBossESB.dsl
  | 
  | rule "Routing Rule - XML based message"
  | 	
  | 	when
  | 		xmlContentMatches "/PurchaseOrder"
  | 	then 
  | 		System.out.println("JBoss_XML"); 
  | 		destinationServices.add("test_category:JBOSS_XMLDestination");
  | end
  | 

The DSL:

  | #JBossESB Content Based Routing DSL
  | [when]xmlContentMatches "{xpath}"=msg : Message( type == MessageType.JBOSS_XML ) and eval( org.jboss.soa.esb.services.routing.cbr.DslHelper.xmlContentMatches(msg, "{xpath}") )
  | [when]xmlContentEquals "{xpath}", "{value}"=msg : Message( type == MessageType.JBOSS_XML ) and eval( org.jboss.soa.esb.services.routing.cbr.DslHelper.xmlContentEquals(msg, "{xpath}", "{value}") )
  | 

Helper class that does the actual XPath matching:

  | package org.jboss.soa.esb.services.routing.cbr;
  | 
  | import java.io.ByteArrayInputStream;
  | 
  | import javax.xml.xpath.XPath;
  | import javax.xml.xpath.XPathConstants;
  | import javax.xml.xpath.XPathExpressionException;
  | import javax.xml.xpath.XPathFactory;
  | 
  | import org.jboss.soa.esb.message.Message;
  | import org.xml.sax.InputSource;
  | 
  | public class DslHelper {
  | 	private static XPathFactory xpf = XPathFactory.newInstance();
  | 	
  | 	public static boolean xmlContentMatches(Message msg, String xpathExp) throws XPathExpressionException {
  | 		XPath xpath = xpf.newXPath();
  | 		InputSource inputSource = new InputSource(new ByteArrayInputStream(msg.getBody().getContents()));
  | 		Object node = xpath.evaluate(xpathExp, inputSource, XPathConstants.NODE);
  | 		return node != null;
  | 	}
  | 	
  | 	public static boolean xmlContentEquals(Message msg, String xpathExp, String value) throws XPathExpressionException {
  | 		XPath xpath = xpf.newXPath();
  | 		InputSource inputSource = new InputSource(new ByteArrayInputStream(msg.getBody().getContents()));
  | 		String node = (String) xpath.evaluate(xpathExp, inputSource, XPathConstants.STRING);
  | 		return value.equals(node);
  | 	}
  | }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3982752#3982752

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3982752



More information about the jboss-dev-forums mailing list