BRMS- resource and change-set

1.5k views Asked by At

I am trying to run a Drools project with all the rules created inside the JBRMS. I am having a 401 exception and leading to null point.

    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();
        }

    }

}

This is the ERROR I am getting.

[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)

I am getting a 401 exception. Do I need to include property file for authentication with this for that uri? My resource has a declarative model and a rule. A simple rule saying that if "year" of car is less than 1989, set the value of "destroy" to true. I am going wrong somewhere. Can somebody please help me?

2

There are 2 answers

2
salaboy On

If you go to guvnor, what kind of resources points to this URL? http://localhost:8080/jboss-brms/org.drools.guvnor.Guvnor/package/org.pci/EPOCH? Where did you get that URL? do you get a package called org.pci with a resource called EPOCH? Cheers

1
salaboy On

Are you sure that you are including the Car declared type inside the knowledge package?