drools-server empty response body
by lhorton
I am new to calling Rest services and using drools-server. I configured the
camel-server.xml and knowledge-services.xml rest service to use xstream
marshalling, added my rules and pojo model to the war, and deployed it on
tomcat. I wrote a java http client to run the rest service. This is the
batch command that I'm sending:
<set-global identifier="logger">
<org.apache.commons.logging.impl.Log4JLogger>
<name>com.abclegal.rules.integration.StatusChangeTestIntegration</name>
</org.apache.commons.logging.impl.Log4JLogger>
</set-global>
<insert>
<com.abclegal.domain.step.VenueValidationStep>
<id>0</id>
<parentTaskId>0</parentTaskId>
<status>PENDING</status>
<activatable>false</activatable>
<abortable>false</abortable>
<completable>false</completable>
</com.abclegal.domain.step.VenueValidationStep>
</insert>
<fire-all-rules/>
</batch-execution>
this is the rule:
rule "Activate VenueValidationStep"
dialect "mvel"
when
$step : VenueValidationStep(activatable == false, status ==
Status.PENDING)
then
logger.debug("activating VenueValidationStep");
modify($step) {
setActivatable(true),
setStatus(Status.ACTIVE);
};
return($step);
end
when I run the client, I can see on the server log that the global was set
and the correct rule is running (it writes to the log using the global
logger), and i get a 200 response on the http post. However, the response
body is empty except for the enclosing xml tags. it contains only:
<?xml version='1.0' encoding='UTF-8'?><execution-results/>
The behaviour I would like to happen is that the modified $step would be
returned from the http post.
Apologies if this is another dumb noob question - I hope it's just something
simple I've missed. thanks for the help.
--
View this message in context: http://drools.46999.n3.nabble.com/drools-server-empty-response-body-tp319...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 4 months
order of injected events
by Chris Richmond
I am running a simple test like so:
package com.sample;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.KnowledgeSessionConfiguration;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.conf.ClockTypeOption;
import org.drools.runtime.rule.WorkingMemoryEntryPoint;
import com.sample.DroolsTest.Message;
public class FusionMain {
public static final void main(String[] args) {
try {
KnowledgeSessionConfiguration config =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
config.setOption( ClockTypeOption.get("realtime") );
KnowledgeBase kbase;
kbase = readKnowledgeBase();
final StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
WorkingMemoryEntryPoint myStream =
ksession.getWorkingMemoryEntryPoint("My Stream");
Thread t = new Thread(new Runnable(){
@Override
public void run() {
ksession.fireUntilHalt();
}
});
t.start();
for (float x = 0.0f; x < 20.0f; x++){
DataReading dr = new DataReading("Reading " + x, x);
myStream.insert(dr);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
}
With the following rule in the sample.drl file:
package com.sample
import com.sample.DroolsTest.Message;
import java.util.Date;
declare DataReading
@role( event )
end
rule "MyGuidedRule"
dialect "mvel"
when
$dr: DataReading( reading > "10.0" ) from entry-point "My Stream"
then
System.err.println("Reading: " + $dr.name + " > 10.0 " +
System.currentTimeMillis());
end
know I am running fireUntilHalt on a seperate thread as you can see, but
events injected fire rules out of order...in fact almost the exact
opposite order in which they were inserted to the stream every time:
Reading: Reading 19.0 > 10.0 1311325346490
Reading: Reading 18.0 > 10.0 1311325346491
Reading: Reading 17.0 > 10.0 1311325346491
Reading: Reading 16.0 > 10.0 1311325346491
Reading: Reading 15.0 > 10.0 1311325346491
Reading: Reading 14.0 > 10.0 1311325346491
Reading: Reading 13.0 > 10.0 1311325346491
Reading: Reading 12.0 > 10.0 1311325346491
Reading: Reading 11.0 > 10.0 1311325346491
I want to eventually perform temporal reasoning, but how can I expect
that to work if events are not evaluated in the order they were inserted.
Perhaps I am setting up my session/kb improperly?
Thanks,
Chris
13 years, 4 months
how to invoke rest service on drools server with serialized objects
by Lisa Horton
I installed drools-server (5.2 final) in tomcat and was able to invoke the sample Soap service using SoapUI using Salaboy's excellent blog post instructions. I have modified knowledge-services.xml to add my rule base using a knowledge agent, and changed camel-server.xml to marshal/unmarshal using serialization. The drools-server starts up without error, but when I try to call the rest service from my java client, I get HTTP response: status code = 415, status message = [Unsupported Media Type].
Any suggestions or example of how to do this? I am attaching my xml files. the application-Context-rulesTestIntegrationExamples.xml is the spring bean definition for my client java program.
13 years, 4 months
Dynamic facts
by Marc Heinz
Hello everyone,
I need some enlightening about Drools "dynamic facts" (a term used in the
documentation, for facts that could be updated from outside the rule
engine).
The current documentation always list the "insert" method of a
StatefulKnowledgeSession being able to take an additional boolean
argument, stating that the corresponding fact supports the
PropertyChangeSupport related methods.
However, it seems that this method do not exists anymore for already some
time now...
After googling for a while it appears that some possible workaround were
modifyInsert (apparently removed from the API as well) and the
@propertyChangeSupport meta-data annotation, but I didn't manage to make
it work (actually I wasn't able to find any reference from it in the API,
so I guess that it is also not available anymore).
So, this left us with the "session.update" method. Which seems to works
great, except that it will invalidate the whole fact into the working
memory, even if only some of the fields were changed.
Is this some current limitation of Drools? Does it have something to do
with those "Shadows Fact"? (that would be somehow immutable?)
If we effectively can't fire update targeted to some specific fields, this
has probably some big implications on performances (even for simple fact
with only a few fields). It would also means that one should always aim at
the finest granularity for better performances, by somehow "flattening"
the object structure into the knowledge base (which in turn could make
complicated to reuse those same Pojo in other frameworks, such as
hibernate).
Did I miss something?
Any feedback deeply appreciated,
Thanks!
M. H.
13 years, 4 months
Problem with Guvnor 5.1.1, <save> frequently does not save...
by David Shields
I have spent several days writing rules and tests for them in Guvnor, and
kept having strange results. A test would sometimes fail, repeatedly, and
then finally start working after I would delete and recreate some portion
of it, or change a value.
After two of us spent many hours trying to identify the extent of the
problem, we concluded the following:
1. The problem happens under both IE and Firefox.
2. The problem happens less frequently under Firefox if we install and
turn on a third-party plug-in which disables Firefox caching web pages.
3. Saving a new rule or test will allow us to work with it (edit - save -
test scenarios). However, frequently the rule or test will just disappear
once we log out.
4. A "Save" and "Check-in" will often work correctly if we cross our
fingers and do the following:
a. Save it once (the screen updates, and you can check the
version history)
b. Refresh the browser
c. Make the change again
d. Save it a second time
5. After doing a "Save" and "Check-in", you can immediately do a "view
source" and see your changes in place. However, if you then close the
test (or rule) and re-open it, you will often find that the change is
gone, and the test or rule looks like it did before you made the change.
A sample screenshot appears below. In this case, I created the test with
the "performedTime" set to 20-Sep-2008. I ran the test and it failed,
because the rule was checking for greater than or equal to 21-Sep-2008. I
then changed the date on the test to 21-Sep-2008, did a "save changes" and
a "Check-in", and then ran the scenario again.
As you can see below, the asserted object contains the date 20-Sep-2008,
even though the test clearly shows 21-Sep-2008.
Does anybody have any ideas on this? If I copy the above test into a new
test, it will often work the first time, but then it may disappear, once I
logout, even though it was saved and checked-in.
It almost seems like there is something wrong with the imbedded
repository, and / or the first running of the test created fact objects
that are persisting and being found the second time I ran the changed
test. ...
We are running the Final release of Drools Guvnor 5.1.1 found in
drools-5.1.1-guvnor.zip downloaded on 4-Sep-2010
We are running under Tomcat 6.0, with the recommended jar files replaced.
Thanks for your help!
--------------------------------------------------
David Shields
Division of Clinical Informatics
Department of Community and Family Medicine
Duke University Medical Center
Phone (864) 787-8551
13 years, 4 months
How to write rules with optional parts?
by Edward Johnson
How do you do rules that are a sequence of events where some of them are optional?
Example:
Alert if DAVID enters a room after ALICE or after ALICE and BOB
If it were a string, this is roughly equivalant to the regex /ALICE( BOB)? DAVID/
So:
Alice then David => alert
Alice then Bob then David => alert
Alice then Charles then David => no alert
I could write this as two rules but as the rules get more complex it could by hard to manage the resulting combatorial explosion. Here it is as two rules:
Rule 1:
$p1:person (name=="Alice")
$p2:person (name=="David", this after[0,1] $p1)
Rule 2:
$p1:person (name=="Alice")
$p2:person (name=="Bob", this after[0,1] $p1)
$p3:person (name=="David", this after[0,1] $p2)
13 years, 4 months
JBPM processes in Guvnor
by DonC
Hi,
I'm pretty new to guvnor and jbpm. I have guvnor 5.2.0 final running, I'm
trying to extract the processes attached to a package using the
KnowledgeAgent api. I've successfully managed to create a process under the
mortgages package, however when I build a snapshot of the package the
processes do not show.
When I use eclipse to view the repository I can see my process in the
snapshot. When I'm in java using the knowledgeAgent, I can not get the
process out. How am I able to extract the process and execute it?
String url =
"http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/mort...";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newUrlResource( url ), ResourceType.PKG );
assert(kbuilder.hasErrors());
Collection<KnowledgePackage> packageList = kbuilder.getKnowledgePackages();
for (KnowledgePackage kp : packageList) {
System.out.println("package name = " + kp.getName());
Collection<Process> processList = kp.getProcesses();
for (Process p : processList) {
System.out.println(p.getName());
}
}
the size of processList is always 0?
Any help will be appreciated.
Thanks
Don
--
View this message in context: http://drools.46999.n3.nabble.com/JBPM-processes-in-Guvnor-tp3191390p3191...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 4 months
Fusion confusion
by Chris Richmond
I have attached my program project with my main FusionMain.java and two
small classes and my rule file Sample.drl.
It's a zip file i have modified to be .piz for mail server reasons.
In the Main I set up and run as STREAM mode session and execute on a
background thread .fireUntilHalt().
Then I inject two objects(DataReading and ConfigEvent)
The Sample.drl rule has the rules:
declare DataReading
@role( event )
end
declare ConfigEvent
@role( event )
end
rule "Detect high data reading"
when
$dr: DataReading(reading > 10.0) from entry-point "My Stream"
then
System.err.println("Data reading > 10");
end
rule "Wait for follup config"
lock-on-active
when
$dr: DataReading(reading > 10.0) from entry-point "My Stream"
not($de: ConfigEvent(this after[0s,10s] $dr))
then
System.err.println("Action");
end
rule "Detect config event"
when
$ce: ConfigEvent() from entry-point "My Stream"
then
System.err.println("Config Event");
end
What I expect is that I would see the DataReading rule fire right
away(it does)
then 5 seconds later when I insert the ConfigEvent I would see it's rule
fire(it does)
But the "Wait for follup config" rule fires no matter what.
To me, that rule should wait and make sure no ConfigEvent object was
inserted within 10 seconds after the DataReading object, but no matter
what that rule fires after 10 seconds. How can I make my inserted
ConfigEvent(inserted within the 10 seconds) satisfy that condition so it
cancels that rule from firing? I am using the latest download from the
site (5.2.0 final) binaries.
Does Fusion in fact work or am I doing something wrong? The zip file
has the entire runnable program and project(have to modify lib
references to point to correct Drools 5.2 binaries).
If the zip file does not come through I will attach the files
individually next.
Thanks,
Chris
13 years, 4 months