Re: [rules-users] java.lang.ClassCastException: [Lorg.drools.rule.Package; cannot be cast to org.drools.rule.Package
by Manasi
Hi,
I am also getting same error when trying to a call rule stored in guvnor.
Following error I am getting:
Exception in thread "main" java.lang.ClassCastException:
[Lorg.drools.rule.Package; cannot be cast to org.drools.rule.Package
at org.drools.agent.HttpClientImpl.fetchPackage(HttpClientImpl.java:82)
at org.drools.agent.URLScanner.readPackage(URLScanner.java:171)
at org.drools.agent.URLScanner.getChangeSet(URLScanner.java:143)
at org.drools.agent.URLScanner.loadPackageChanges(URLScanner.java:119)
at org.drools.agent.RuleAgent.checkForChanges(RuleAgent.java:427)
at org.drools.agent.RuleAgent.refreshRuleBase(RuleAgent.java:379)
at org.drools.agent.RuleAgent.configure(RuleAgent.java:364)
at org.drools.agent.RuleAgent.init(RuleAgent.java:264)
at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:204)
at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:164)
at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:273)
I am using Drools 5.4 version.
The error is coming when trying to get the RuleAgent:
RuleAgent agent = RuleAgent.newRuleAgent("/com/model/drools.properties");
drools.properties contains:
url =
http://localhost:8080/guvnor/org.drools.guvnor.Guvnor/package/FeltKnapRes...
name=guvnorAgent
enableBasicAuthentication=True
username=admin
password=admin
FeltKnapRestriktionerKundeMedAnl is the package name I have created in
guvnor ,and I want to call one of the rule in this package.
Thanks,
Manasi
--
View this message in context: http://drools.46999.n3.nabble.com/java-lang-ClassCastException-Lorg-drool...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 7 months
Importing functionS from another drl in 5.5.0
by Sonata
If you have defined functions in a drl, in order to use those functions in
another drl of a different package, you will have to import each individual
function, like
package A;
function void func1 () {
System.out.println("Hello");
}
function void func2 () {
System.out.println("There");
}
pacakge B;
import function A.func1.func1;
import function A.func2.func2;
rule Test
when
then func1(); func2(); end
Is there any way to do something like import function A.*; in Drools 5.5.0
to use all the functions defined in another drl?
Thank you
--
View this message in context: http://drools.46999.n3.nabble.com/Importing-functionS-from-another-drl-in...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 7 months
DRL always posting the format as txt instead of model.drl
by learnbrms
Hi,
I am using the following code to post or update the DRL using ATOM. But I am
seeing that DRL is always posted and displayed in Guvnor as .txt
(Format:txt) instead of Format:model.drl.
public int createUpdateTextAsset(String assetLoc, String ruleName, String
ruleDescription, String fileToUpload, String requestMethod)
{
System.out.println("--------Begin createUpdateTextAsset ----------");
System.out.println("assetLoc "+assetLoc+"\nruleName
"+ruleName+"\nruleDescription "+ruleDescription+"\nfileToUpload
"+fileToUpload+"\nrequestMethod "+requestMethod);
String authCode = user+":"+password;
StringBuilder content = null;
Scanner scanner = null;
client = WebClient.create(baseURL);
try
{ File f = new File(fileToUpload);
content = new StringBuilder();
String NL = System.getProperty("line.separator");
scanner = new Scanner(new FileInputStream(f));
while (scanner.hasNextLine()) {
content.append(scanner.nextLine() + NL);
}
String ruleContent=content.toString();
String atom = "";
Response response = null;
String authString = "";
authString = "Basic " + org.apache.cxf.common.util.Base64Utility
.encode(authCode.getBytes());
client.header("Authorization", authString);
atom = "<entry xmlns=\"http://www.w3.org/2005/Atom\"
xml:base=\"";
atom += assetLoc;
atom += "\"><title type=\"text\">";
atom += ruleName;
atom += "</title><summary type=\"text\">";
atom += ruleDescription;
atom += "</summary>";
atom +="<metadata>";
atom +="<property name=\"archived\" value=\"false\" />";
atom +="<property name=\"rule-format\" value=\"model.drl\"/>";
atom +="</metadata>";
atom += "<content type=\"application/xml\">";
atom += ruleContent;
atom += "</content></entry>";
System.out.println("Atom :"+atom);
if(requestMethod=="POST"){
response = client.path(assetLoc).type(MediaType.APPLICATION_ATOM_XML)
.header("slug", ruleName+".drl")
.post(atom);
}else{
response = client.path(assetLoc).type(MediaType.APPLICATION_ATOM_XML)
.put(atom);
}
System.out.println("--------End createUpdateTextAsset ----------status
"+response.getStatus());
return response.getStatus();
}
*Output:*
Title: bre-validation-service-processing-model
Categories:
Last modified : 2013-07-17 00:07
by:
Note:
Initial:
Created on:2013-07-17 00:07
Created by:admin
Package:TestPackage6
Edit
Is Disabled:
*Format:txt*
UUID:c8247b22-1a14-4258-9cdf-5033518adf6b
--
View this message in context: http://drools.46999.n3.nabble.com/DRL-always-posting-the-format-as-txt-in...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 7 months
Business Logic Validation Using Rules
by Shazin Sadakath
Hi
I am currently writing a set of Rules to Validate Some Business Logic and
if The Criteria in When clause is met throw an Exception.
Currently I have two rules. I use a StatelessKnowledgeSession and
CommandExecutor.execute method to fire the rules.
But while testing I created a scenario to fire one of the rules and throw
an exception then created another scenario to not to throw an Exception
(Valid Domain Object). But in this case also it is throwing an Exception
with info related to Failed Domain Object.
Regards,
Shazin Sadakath
12 years, 7 months
Unable to get LastModified for ClasspathResource
by sottostee
Hi everyone,
I have got a problem that me go mad.
Clarify I'm working with a Maven project using Eclipse.
I'm trying to add at my KnowledgeBuilder, after i have correctly created a
new instance of it, a drl file.
In order of this, i call a method: void
org.drools.builder.KnowledgeBuilder.add(Resource arg0, ResourceType arg1),
give it like a Resource "ResourceFactory.newClassPathResource(String: name
of my drl)" and like ResourceType: "ResourceType.DRL".
As long as i run my project into Eclipse, all works well.
But, if i create a jar file of my project, when i run this, i have this
exception:
java.lang.RuntimeException: Unable to get LastModified for ClasspathResource
at
org.drools.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:204)
at
org.drools.io.impl.ClassPathResource.getInputStream(ClassPathResource.java:141)
at org.drools.compiler.DrlParser.parse(DrlParser.java:145)
at org.drools.compiler.DrlParser.parse(DrlParser.java:139)
at
org.drools.compiler.PackageBuilder.drlToPackageDescr(PackageBuilder.java:477)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:466)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:694)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40)
at rec.reasoner.Reasoner.init(Reasoner.java:192)
at rec.reasoner.Reasoner.<init>(Reasoner.java:176)
at rec.reasoner.Reasoner.newReasoner(Reasoner.java:51)
at rec.model.Model.<init>(Model.java:37)
at rec.controller.Controller.<init>(Controller.java:26)
at applet.Demo.<init>(Demo.java:18)
at applet.Demo.main(Demo.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at
org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.io.FileNotFoundException: 'General_multivalue.drl' cannot be
opened because it does not exist
at
org.drools.io.impl.ClassPathResource.getURL(ClassPathResource.java:165)
at
org.drools.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:177)
... 20 more
line 192 is properly:
'builder.add(ResourceFactory.newClassPathResource("General.drl"),
ResourceType.DRL);'
Well....given that in my project I've got some classes which make use of
images, and given that, in this classes I call this method:
getClass().getResource(String of image).getFile() in order to load the
images, and all seems work very well; therefore I'm doing the same thing
with drl file:
I change the old method with:
builder.add(ResourceFactory.newClassPathResource(getClass().getResource("General.drl").getFile()),
ResourceType.DRL);
Now:
1) when i run jar file, the exception is:
java.lang.NullPointerException
at rec.reasoner.Reasoner.init(Reasoner.java:189)
at rec.reasoner.Reasoner.<init>(Reasoner.java:176)
at rec.reasoner.Reasoner.newReasoner(Reasoner.java:51)
at rec.model.Model.<init>(Model.java:37)
at rec.controller.Controller.<init>(Controller.java:26)
at applet.Demo.<init>(Demo.java:18)
at applet.Demo.main(Demo.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at
org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
2) and when i run the project into Eclipse, the exception is:
java.lang.RuntimeException: Unable to get LastModified for ClasspathResource
at
org.drools.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:204)
at
org.drools.io.impl.ClassPathResource.getInputStream(ClassPathResource.java:141)
at org.drools.compiler.DrlParser.parse(DrlParser.java:145)
at org.drools.compiler.DrlParser.parse(DrlParser.java:139)
at
org.drools.compiler.PackageBuilder.drlToPackageDescr(PackageBuilder.java:477)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:466)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:694)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40)
at rec.reasoner.Reasoner.init(Reasoner.java:189)
at rec.reasoner.Reasoner.<init>(Reasoner.java:176)
at rec.reasoner.Reasoner.newReasoner(Reasoner.java:51)
at rec.model.Model.<init>(Model.java:37)
at rec.controller.Controller.<init>(Controller.java:26)
at applet.Demo.<init>(Demo.java:18)
at applet.Demo.main(Demo.java:36)
Caused by: java.io.FileNotFoundException:
'/home/ste/workspace2/REC-mv/target/classes/rec/reasoner/General_multivalue.drl'
cannot be opened because it does not exist
at
org.drools.io.impl.ClassPathResource.getURL(ClassPathResource.java:165)
at
org.drools.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:177)
... 15 more
but in '/home/ste/workspace2/REC-mv/target/classes/rec/reasoner/' the file
'General_multivalue.drl' EXISTS!!!!
Are there anyone who help me please?
Thanks in advance.
sotto
--
View this message in context: http://drools.46999.n3.nabble.com/Unable-to-get-LastModified-for-Classpat...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 7 months
Drools in Hawaii
by Mark Proctor
I'm going to be in Hawaii for 3 weeks in september, visiting honolulu, kauaui and maui.
Is there a Drools community on any of those islands, I could be tempted to attend a user group and do a Drools 6 talk :)
Mark
12 years, 7 months