0 Replies Latest reply on Sep 11, 2013 5:06 PM by RAMBABU NARNE

    REST access of Guvnor for assets(a specific rule)

    RAMBABU NARNE Newbie

      Hi

       

      i am using Guvnor 5.5.0.Final with Tomcat 6.0. Having 2 issues in Guvnor

       

      Issue1:

       

      i am able to access a package of rules using the following code with out any issues and i am able to insert Facts and my rules are getting executed

       

      using a ChangeSet with Package

       

      <change-set xmlns='http://drools.org/drools-5.0/change-set'

          xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'

          xs:schemaLocation='http://drools.org/drools-5.0/change-set http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd' >

          <add>

               <resource   source='http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/clm_demo/LATEST' type='PKG' basicAuthentication="enabled" username="tomcat" password="tomcat"/> 

          </add>

      </change-set>

       

      Code to access Guvnor:

       

      ResourceChangeScanner resChangeScanService = ResourceFactory.getResourceChangeScannerService();

      ResourceChangeScannerConfiguration rconf = resChangeScanService.newResourceChangeScannerConfiguration();

      rconf.setProperty("drools.resource.scanner.interval", "10");

      resChangeScanService.configure( rconf );

      resChangeScanService.start();

      ResourceFactory.getResourceChangeNotifierService().start();

      KnowledgeAgentConfiguration kaconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();

      kaconf.setProperty("drools.agent.scanDirectories", "true");

      kaconf.setProperty("drools.agent.scanResources", "true");

      kaconf.setProperty("drools.agent.newInstance", "false");

      KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "Agent1", kaconf );

      String urlstr="http://localhost:8080/drools-guvnor/rest/packages/clm_demo/assets/test_demo_cs1/binary";

      UrlResource resource = (UrlResource) ResourceFactory.newUrlResource(urlstr);

      resource.setBasicAuthentication("enabled");

      resource.setUsername("tomcat");

      resource.setPassword("tomcat");

      kagent.applyChangeSet(resource );

      KnowledgeBase kbase = kagent.getKnowledgeBase();

      final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

      KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test.log");

       

       

      When i have my Change Set with Asset DRL

       

      <change-set xmlns='http://drools.org/drools-5.0/change-set'

          xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'

          xs:schemaLocation='http://drools.org/drools-5.0/change-set http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd' >

          <add>

        <resource   source='http://localhost:8080/drools-guvnor/rest/packages/clm_demo/assets/CLM_DSL_DTC_Rule1/source' basicAuthentication="enabled" username="tomcat" password="tomcat" type='DRL' />

          </add>

      </change-set>

       

      Code to access Guvnor:


      Changing the following in the above code my Fact which has data for CLM_DSL_DTC_Rule1 is not gettign triggered

      String urlstr="http://localhost:8080/drools-guvnor/rest/packages/clm_demo/assets/CLM_DSL_DTC_Rule1/source";

       

       

      Is this any issue in Guvnor 5.5.0.Final version or the functionality is allowed only for all the Assets in the Package?

       

       

      Issue2:


      i am getting the following error if i directly access the assets in the following form . Please suggest me what is wrong in the code

       

      ERROR:


      java.lang.RuntimeException: java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost:8080/drools-guvnor/rest/packages/clm_demo/assets/CLM_DSL_DTC_Rule1/source

        at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:726)

        at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51)

        at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40)

        at com.clm.demo.GuvnorRulesDRLTest.readKnowledgeBase(GuvnorRulesDRLTest.java:175)

       

      CODE:


      String urlstr="http://localhost:8080/drools-guvnor/rest/packages/clm_demo/assets/CLM_DSL_DTC_Rule1/source";

      UrlResource resource = (UrlResource) ResourceFactory.newUrlResource(urlstr);

      resource.setBasicAuthentication("enabled");

      resource.setUsername("tomcat");

      resource.setPassword("tomcat");

      KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

      kbuilder.add(ResourceFactory.newUrlResource(resource.getURL()),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());

      StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();