Calling drools into the Web Application.
by srinivasasanda
this piece of application is working using drools project, but its not
working in (webapplication)
i had a text box age and income that values i am trying passing this data to
rule and run the rules.
i created one jsp , jsp call servlet, In servelt i called the below piece of
code in servlet but not executing
I am trying to include it this piece of code into webapplication (in servlet
or jsp) it is showing error.
public static final void runMain() {
try {
RuleAgent agent = RuleAgent.newRuleAgent("/guvnor.properties");
RuleBase ruleBase = agent.getRuleBase();
WorkingMemory workingMemory = ruleBase.newStatefulSession();
FactType ft= ruleBase.getFactType("sample.person"); //created
declarative model in guvnor
Object obj=ft.newInstance();
ft.set(obj,"age", 67);
//setting data into into person
ft.set(obj, "income", 1000);
workingMemory.insert(obj);
workingMemory.fireAllRules();
System.out.print(ft.get(obj, "age"));
System.out.print(ft.get(obj, "income"));
} catch (Throwable t) {
t.printStackTrace();
}
}
12:46:44,409 ERROR [STDERR] RuleAgent(default) INFO (Mon Dec 05 12:46:44 GMT
2011): Configuring with
newInstance=false, secondsToRefresh=-1
12:46:44,419 ERROR [STDERR] RuleAgent(default) INFO (Mon Dec 05 12:46:44 GMT
2011): Configuring pack
age provider : URLScanner monitoring URLs:
http://localhost:8082/guvnor-5.2.0.Final-jboss-as-5.1/or
g.drools.guvnor.Guvnor/package/sample/LATEST
12:46:44,669 INFO [STDOUT] INFO 05-12 12:46:44,669
(NilAuthenticator.java:authenticate:35) All
users are guests.
12:46:44,359 ERROR [STDERR] java.lang.IllegalArgumentException: Could not
parse knowledge.
12:46:44,359 ERROR [STDERR] at
com.sample.DroolsTest.readKnowledgeBase(DroolsTest.java:115)
12:46:44,359 ERROR [STDERR] at
com.sample.DroolsTest.FireRools(DroolsTest.java:62)
12:46:44,359 ERROR [STDERR] at p1.Login.doGet(Login.java:37)
12:46:44,359 ERROR [STDERR] at
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
12:46:44,359 ERROR [STDERR] at
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
12:46:44,699 ERROR [STDERR] RuleAgent(default) EXCEPTION (Mon Dec 05
12:46:44 GMT 2011): org.drools.
rule.Package; local class incompatible: stream classdesc serialVersionUID =
510, local class serialV
ersionUID = 400. Stack trace should follow.
12:46:44,699 ERROR [STDERR] java.io.InvalidClassException:
org.drools.rule.Package; local class inco
mpatible: stream classdesc serialVersionUID = 510, local class
serialVersionUID = 400
12:46:44,699 ERROR [STDERR] at
java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:562
)
--
View this message in context: http://drools.46999.n3.nabble.com/Calling-drools-into-the-Web-Application...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
Web client-side rule testing - best practices
by Ronald Albury
I have always thought of Drools-like systems being server-side engines -
and we have many server-side-only uses for rules. However, for a good user
experience you should do checking as close to data entry as possible, and
there is a subset of our server rules that are redundant with the rules
governing client data entry (currently embedded in the Web interface as
Javascript).
Has anyone established a good pattern for using Drools for client-side
testing? I'm guessing that we would need some sort of per-field Ajax
communication back to the server ... but this means per-field communication
(not good for our agents on dial-up or with slow links), and it also means
structuring our rules such that we can easily access only the appropriate
rules.
Would I, for instance, need a separate Fact object type for each field?
This seems like it would really complicate the rules - we have about a
dozen basic data structures for our server-side Facts, and each data
structure will have multiple attributes. I don't look forward to dealing
with a couple hundred Fact types.
Would I need some sort of flag on our data structures to include in the
Fact which restricts the testing to only the field that was just entered?
This would seem to complicate the understanding of our rules. Some rules
(even UI rules) depend on a combination of facts - so would it be a 'set'
of flags? This seems to be moving close to the first idea (separate Fact
object types ... which seems more efficient).
So ... as you can see, I am thrashing about a bit trying to find the
correct pattern. Can someone save me a bunch of time and bad code by
sharing their best practice with me?
Thanks,
Ron
13 years
Re: [rules-users] Guvnor Versioning - eclipse plug-in
by Ronald Albury
I found a way to get Guvnor to make Version 3 the active version. I
shut-down and restart Tomcat.
Surely this can't be the 'standard' way ... and it makes me think that I've
tripped over a bug hiding in there somewhere.
Thoughts?
13 years
Guvnor Functions --how to make available jboss & other util & collection
by srinivasasanda
Hi All
Thank's In Advance, U have clarified many dou't to me , Please try
to give me solution for this also.
I am wring a function in guvnor, --(Guvnor function code contains --> util
package, jboss manager package, and other system defined functions) when i
write code in function and validate i got an error that specified packages
are not able to find. where can i include the packages to make available to
functions.)
Actual need for me...
When the rule satisfy, i want to call a function which
store some data into Hashmap,
i want to call directly the jboss cache data into drools functions. (we can
write some pojo and call it is working, but to increase the performance
issue ) i am going for it.
please any one give me some solution, ... Any way Thank's in Advance...
--
View this message in context: http://drools.46999.n3.nabble.com/Guvnor-Functions-how-to-make-available-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
[MVEL]how to intercept all ASTNode without annotation?
by kapokfly
To be able to intercept against each node, I have to manually update the
expression String to register some interceptors like below, is there any
convenient API can make this enabled without adding such interceptors?
public void testMyInterceptors() {
// Avoid MVEL OOM issue: http://jira.codehaus.org/browse/MVEL-252
// This also disables JIT compilre
// At this time, MVEL does not support per instance configuration of the
JIT due to performance constraints.
OptimizerFactory.setDefaultOptimizer(OptimizerFactory.SAFE_REFLECTIVE);
Interceptor testLeftInterceptor = new Interceptor() {
public int doBefore(ASTNode node,
VariableResolverFactory factory) {
System.out.println("BEFORE left Node: " + node.getName());
System.out.println("BEFORE left Node: node.getClass(): " +
node.getClass());
//node.setAsLiteral();
//node.setLiteralValue("Ivan");
System.out.println("BEFORE left Node: " + node.getLiteralValue());
//node.setAccessor(new MetaDataAccessor());
return 0;
}
public int doAfter(Object val,
ASTNode node,
VariableResolverFactory factory) {
System.out.println("AFTER left Node: " + node.getName());
System.out.println("AFTER left Node: node.getLiteralValue(): " +
node.getLiteralValue());
return 0;
}
};
Interceptor testRightInterceptor = new Interceptor() {
public int doBefore(ASTNode node,
VariableResolverFactory factory) {
System.out.println("BEFORE right Node: " + node.getName());
System.out.println("BEFORE right Node: node.getClass(): " +
node.getClass());
return 0;
}
public int doAfter(Object val,
ASTNode node,
VariableResolverFactory factory) {
System.out.println("AFTER right Node: " + node.getName());
return 0;
}
};
Map<String, Interceptor> interceptors = new HashMap<String,
Interceptor>();
interceptors.put("testLeft", testLeftInterceptor);
interceptors.put("testRight", testRightInterceptor);
String expression = "(@testLeft emailMessage.from == @testRight 'Mark 1'
|| @testLeft myBean.var == 1)";
//compileExpression(expression, null, interceptors);
Map<String, Object> contextObjects = new HashMap<String, Object>();
EmailMessage emailMessage = new EmailMessage();
emailMessage.setFrom("Mark");
contextObjects.put("emailMessage", emailMessage);
MyBean myBean = new MyBean();
myBean.setVar(1);
contextObjects.put("myBean", myBean);
boolean evaluationResult =
executeExpression(compileExpression(expression, null, interceptors),
contextObjects, Boolean.class);
System.out.println(evaluationResult);
}
-----
Ivan, your Panda, forever
--
View this message in context: http://drools.46999.n3.nabble.com/MVEL-how-to-intercept-all-ASTNode-witho...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
[MVEL]Getting Null Context Object with MVEL Inteceptor
by kapokfly
public void testMyInterceptors() {
// Avoid MVEL OOM issue: http://jira.codehaus.org/browse/MVEL-252
// This also disables JIT compilre
// At this time, MVEL does not support per instance configuration of the
JIT due to performance constraints.
OptimizerFactory.setDefaultOptimizer(OptimizerFactory.SAFE_REFLECTIVE);
Interceptor testLeftInterceptor = new Interceptor() {
public int doBefore(ASTNode node,
VariableResolverFactory factory) {
System.out.println("BEFORE left Node: " + node.getName());
System.out.println("BEFORE left Node: node.getClass(): " +
node.getClass());
//node.setAsLiteral();
//node.setLiteralValue("Ivan");
System.out.println("BEFORE left Node: " + node.getLiteralValue());
node.setAccessor(new MetaDataAccessor());
return 0;
}
public int doAfter(Object val,
ASTNode node,
VariableResolverFactory factory) {
System.out.println("AFTER left Node: " + node.getName());
System.out.println("AFTER left Node: node.getLiteralValue(): " +
node.getLiteralValue());
return 0;
}
};
Interceptor testRightInterceptor = new Interceptor() {
public int doBefore(ASTNode node,
VariableResolverFactory factory) {
System.out.println("BEFORE right Node: " + node.getName());
System.out.println("BEFORE right Node: node.getClass(): " +
node.getClass());
return 0;
}
public int doAfter(Object val,
ASTNode node,
VariableResolverFactory factory) {
System.out.println("AFTER right Node: " + node.getName());
return 0;
}
};
Map<String, Interceptor> interceptors = new HashMap<String,
Interceptor>();
interceptors.put("testLeft", testLeftInterceptor);
interceptors.put("testRight", testRightInterceptor);
String expression = "(@testLeft emailMessage.from == @testRight 'Mark'
|| @testLeft myBean.var == 1)";
//compileExpression(expression, null, interceptors);
Map<String, Object> contextObjects = new HashMap<String, Object>();
EmailMessage emailMessage = new EmailMessage();
emailMessage.setFrom("Mark");
contextObjects.put("emailMessage", emailMessage);
MyBean myBean = new MyBean();
myBean.setVar(1);
contextObjects.put("myBean", myBean);
boolean evaluationResult =
executeExpression(compileExpression(expression, null, interceptors),
contextObjects, Boolean.class);
System.out.println(evaluationResult);
}
public class MetaDataAccessor implements Accessor{
public Object getValue(Object ctx, Object elCtx, VariableResolverFactory
variableFactory) {
return null; //To change body of implemented methods use File |
Settings | File Templates.
}
public Object setValue(Object ctx, Object elCtx, VariableResolverFactory
variableFactory, Object value) {
return null; //To change body of implemented methods use File |
Settings | File Templates.
}
public Class getKnownEgressType() {
return null; //To change body of implemented methods use File |
Settings | File Templates.
}
}
When the MetaDataAccessor's geValue was invoked, the ctx and elCtx were
Null, however I am expecting the correct expression and context object
presents?
What is wrong with my codes?
I would expect the value reduce process can be done by my accessor in some
cases but apparently it is not.
-----
Ivan, your Panda, forever
--
View this message in context: http://drools.46999.n3.nabble.com/MVEL-Getting-Null-Context-Object-with-M...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years