You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by pksahoo <pr...@sabre.com> on 2007/06/28 22:41:25 UTC
How to pass parameter into Servicemix Drool 3.2 rule .
Hi ,
I am new to Servicemix Drool 3.2 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
--
View this message in context: http://www.nabble.com/How-to-pass-parameter-into-Servicemix-Drool-3.2-rule-.-tf3996673s12049.html#a11350560
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Re: How to pass parameter into Drool 3.2 rule .
Posted by Guillaume Nodet <gn...@gmail.com>.
Take a look at conf/jndi.xml in your ServiceMix distribution.
You will find examples of configuring stuff in JNDI.
On 7/3/07, Arif Mohd <ar...@wipro.com> wrote:
>
> Hi gnodet,
>
> I read the blog, can you please elobarate where and how to configure the
> Data base url,username, password inside the servicemix?
>
> You have given the jndiName as follows
> <property name="jndiName" value="java:myDataBase" />
>
> but where is the myDataBase configured?
> One more general question, Is it the right way of putting business
> logic inside ESB?
>
>
> gnodet wrote:
> >
> > Nicely written, Andrea, thanks !
> > Btw, you may be interested in a recent change in servicemix-drools:
> > the ability to inject beans configured inside the xbean.xml into the rules
> > definition file (such as a helper with a configured dataSource for
> > example).
> > See
> > http://gnodet.blogspot.com/2007/06/accessing-databases-in-servicemix.html
> >
> > On 6/29/07, Andrea Zoppello <zo...@tiscali.it> wrote:
> >> 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
> >> >
> >> >
> >> >
> >>
> >>
> >
> >
> > --
> > Cheers,
> > Guillaume Nodet
> > ------------------------
> > Principal Engineer, IONA
> > Blog: http://gnodet.blogspot.com/
> >
> >
>
> --
> View this message in context: http://www.nabble.com/How-to-pass-parameter-into-Servicemix-Drool-3.2-rule-.-tf3996673s12049.html#a11407248
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>
--
Cheers,
Guillaume Nodet
------------------------
Principal Engineer, IONA
Blog: http://gnodet.blogspot.com/
Re: How to pass parameter into Drool 3.2 rule .
Posted by Arif Mohd <ar...@wipro.com>.
Hi gnodet,
can you please reply.
Arif Mohd wrote:
>
> Hi gnodet,
>
> I read the blog, can you please elobarate where and how to configure the
> Data base url,username, password inside the servicemix?
>
> You have given the jndiName as follows
> <property name="jndiName" value="java:myDataBase" />
>
> but where is the myDataBase configured?
> One more general question, Is it the right way of putting business
> logic inside ESB?
>
>
> gnodet wrote:
>>
>> Nicely written, Andrea, thanks !
>> Btw, you may be interested in a recent change in servicemix-drools:
>> the ability to inject beans configured inside the xbean.xml into the
>> rules
>> definition file (such as a helper with a configured dataSource for
>> example).
>> See
>> http://gnodet.blogspot.com/2007/06/accessing-databases-in-servicemix.html
>>
>> On 6/29/07, Andrea Zoppello <zo...@tiscali.it> wrote:
>>> 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
>>> >
>>> >
>>> >
>>>
>>>
>>
>>
>> --
>> Cheers,
>> Guillaume Nodet
>> ------------------------
>> Principal Engineer, IONA
>> Blog: http://gnodet.blogspot.com/
>>
>>
>
>
--
View this message in context: http://www.nabble.com/How-to-pass-parameter-into-Servicemix-Drool-3.2-rule-.-tf3996673s12049.html#a11412574
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Re: How to pass parameter into Drool 3.2 rule .
Posted by Arif Mohd <ar...@wipro.com>.
Hi gnodet,
I read the blog, can you please elobarate where and how to configure the
Data base url,username, password inside the servicemix?
You have given the jndiName as follows
<property name="jndiName" value="java:myDataBase" />
but where is the myDataBase configured?
One more general question, Is it the right way of putting business
logic inside ESB?
gnodet wrote:
>
> Nicely written, Andrea, thanks !
> Btw, you may be interested in a recent change in servicemix-drools:
> the ability to inject beans configured inside the xbean.xml into the rules
> definition file (such as a helper with a configured dataSource for
> example).
> See
> http://gnodet.blogspot.com/2007/06/accessing-databases-in-servicemix.html
>
> On 6/29/07, Andrea Zoppello <zo...@tiscali.it> wrote:
>> 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
>> >
>> >
>> >
>>
>>
>
>
> --
> Cheers,
> Guillaume Nodet
> ------------------------
> Principal Engineer, IONA
> Blog: http://gnodet.blogspot.com/
>
>
--
View this message in context: http://www.nabble.com/How-to-pass-parameter-into-Servicemix-Drool-3.2-rule-.-tf3996673s12049.html#a11407248
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Re: How to pass parameter into Drool 3.2 rule .
Posted by Andrea Zoppello <zo...@tiscali.it>.
Guillaume,
I've just see the blog, very good job.
It's a very elegant and flexible solution. It seems that you've find a
generic way to inject
generic helper class ( not only db ) in the drools endpoint.
I'm just thinking how to support this in the upcoming SpagicStudio to
generate deliverables
for the new configuration :-)
Andrea Zoppello
Engineering Ing. Informatica
Guillaume Nodet ha scritto:
> Nicely written, Andrea, thanks !
> Btw, you may be interested in a recent change in servicemix-drools:
> the ability to inject beans configured inside the xbean.xml into the
> rules
> definition file (such as a helper with a configured dataSource for
> example).
> See
> http://gnodet.blogspot.com/2007/06/accessing-databases-in-servicemix.html
>
> On 6/29/07, Andrea Zoppello <zo...@tiscali.it> wrote:
>> 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
>> >
>> >
>> >
>>
>>
>
>
Re: How to pass parameter into Drool 3.2 rule .
Posted by Guillaume Nodet <gn...@gmail.com>.
Nicely written, Andrea, thanks !
Btw, you may be interested in a recent change in servicemix-drools:
the ability to inject beans configured inside the xbean.xml into the rules
definition file (such as a helper with a configured dataSource for example).
See http://gnodet.blogspot.com/2007/06/accessing-databases-in-servicemix.html
On 6/29/07, Andrea Zoppello <zo...@tiscali.it> wrote:
> 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
> >
> >
> >
>
>
--
Cheers,
Guillaume Nodet
------------------------
Principal Engineer, IONA
Blog: http://gnodet.blogspot.com/
Re: How to pass parameter into Drool 3.2 rule .
Posted by Andrea Zoppello <zo...@tiscali.it>.
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
>
>
>