I've already done this by extendig not only the drools component but also,
the class org.apache.servicemix.drools.model.Message with a method like
this:รน
org.apache.servicemix.drools.model:
public String valueOf(String xpath) throws Exception {
JAXPStringXPathExpression expression = new
JAXPStringXPathExpression(xpath);
if (this.namespaceContext != null)
expression.setNamespaceContext(this.namespaceContext);
String res = (String)expression.evaluate(null, message);
return res;
}
at this point in you can use your dbHelper in drools as follow:
dbh.isDomestic(in.valueOf('/MESSAGE/@par1'),in.valueOf('/MESSAGE/@par2'))
in this example i assume the incoming message is something like:
<MESSAGE par1="PAR1" par2="PAR2">
</MESSAGE>
Andrea Zoppello
Engineering Ing. Informatica.
pksahoo ha scritto:
Hi ,
I am new to Drool and need some help . I have done integration of
Drool with database.
I am calling DB helper class memeber function in
Drool.
In my Drool file (.drl) file, I need to pass 2
parameter as input . Basically, I have to provide
source airport code and destination airport code to my
rule engine. it will call the database and based on
query, it will return domestic or international.
How can I pass the input parameter to Drool as
variable? Right now, it is hard coded in drool file
like dbh.isDomestic("JFK", "YYZ") . Here is the .drl
file:
package org.apache.servicemix.drools
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.drools.model.Exchange;
import loanbroker.DbHelper;
global org.apache.servicemix.drools.model.JbiHelper
jbi;
rule TourType
when
me : Exchange( status == Exchange.ACTIVE, in : in !=
null, operation ==
"{urn:logicblaze:soa:creditagency}getCreditHistoryLength")
then
DbHelper dbh = new DbHelper();
jbi.answer("<TourTypeResponse><name>" +
dbh.isDomestic("JFK", "YYZ") +
"</name></TourTypeResponse>");
end
Please advise.
Regards,
Prasanta