我試圖運行一個Drools項目,其中包含JBRMS中創建的所有規則。我有一個401例外,並導致零點。BRMS-資源和變更集
package pop.blah.test;
import org.drools.KnowledgeBase;
import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentFactory;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.definition.type.FactType;
@SuppressWarnings("restriction")
public class CarApp {
public static void main(String[] args) {
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("MyAgent5");
kagent.applyChangeSet(ResourceFactory.newUrlResource("http://localhost:8080/jboss-brms/org.drools.guvnor.Guvnor/package/pop.blah.test/CAR"));
KnowledgeBase kbase = kagent.getKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ResourceFactory.getResourceChangeScannerService().start();
try {
FactType carType = kbase.getFactType("pop.blah.test", "Car");
Object bmw = carType.newInstance();
carType.set(bmw,"name","My Car");
carType.set(bmw,"make","BMW");
carType.set(bmw,"year", 1977);
ksession.insert(bmw);
ksession.fireAllRules();
boolean dest = (Boolean) carType.get(bmw, "destroy");
if (dest==true) {
System.out.println("I am gona destroy that car!");
}
else {
System.out.println("I am happy with my car!");
}
}
catch (Exception E) {
E.printStackTrace();
}
finally {
ksession.dispose();
}
}
}
這是我得到的錯誤。
[2011:12:363 14:12:718:debug] KnowledgeAgent building resource map
[2011:12:363 14:12:718:info] KnowledegAgent has started listening for ChangeSet notifications
[2011:12:363 14:12:718:info] KnowledgeAgent created, with configuration:
monitorChangeSetEvents=true scanResources=true scanDirectories=true newInstance=true
[2011:12:363 14:12:765:exception]
java.lang.RuntimeException: Unable to parse ChangeSet
at org.drools.agent.impl.KnowledgeAgentImpl.getChangeSet(KnowledgeAgentImpl.java:393)
at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:168)
at pop.blah.test.CarApp.main(CarApp.java:16)
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost:8080/jboss-brms/org.drools.guvnor.Guvnor/package/pop.blah.test/LATEST
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at org.drools.io.impl.UrlResource.grabStream(UrlResource.java:210)
at org.drools.io.impl.UrlResource.getInputStream(UrlResource.java:146)
at org.drools.io.impl.UrlResource.getReader(UrlResource.java:214)
at org.drools.agent.impl.KnowledgeAgentImpl.getChangeSet(KnowledgeAgentImpl.java:391)
... 2 more
[2011:12:363 14:12:765:exception]
java.lang.RuntimeException: Unable to parse ChangeSet
at org.drools.agent.impl.KnowledgeAgentImpl.getChangeSet(KnowledgeAgentImpl.java:397)
at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:168)
at pop.blah.test.CarApp.main(CarApp.java:16)
[2011:12:363 14:12:765:info] KnowledgeAgent applying ChangeSet
Exception in thread "main" java.lang.NullPointerException
at org.drools.agent.impl.KnowledgeAgentImpl.processChangeSet(KnowledgeAgentImpl.java:215)
at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:183)
at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:168)
at pop.blah.test.CarApp.main(CarApp.java:16)
我得到一個401例外。我是否需要包含屬性文件進行認證與此uri? 我的資源具有聲明性模型和規則。一個簡單的規則是,如果汽車的「年」少於1989年,則將「破壞」的值設置爲真。 我在某個地方出錯了。有人能幫幫我嗎?
我已經編輯了上面的代碼。 URL指向BRMS中的資源。我創建了一個快照並從那裏獲取了URL。 401是一個身份驗證錯誤,那麼這意味着我必須包含屬性文件?如果是的話,我應該把Drools項目放在哪裏? – aps 2011-12-29 21:26:04
剛纔我添加屬性文件按照這張貼:http://stackoverflow.com/questions/5791025/401-exception-in-java-code?answertab=oldest#tab-top現在我沒有得到401例外,但而是在行的錯誤---對象bmw = carType.newInstance(); – aps 2011-12-29 22:03:03