-
1. Re: How can I take process definitions from Guvnor with jBPM5 API?
liliana.iovanovici Feb 13, 2012 4:35 AM (in response to liliana.iovanovici)I allready tried this:
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("MyAgent");
kagent.applyChangeSet( ResourceFactory.newUrlResource(http://localhost:8180/guvnor-5.3.0.Final-jboss-as-7.0/org.drools.guvnor.Guvnor/webdav/packages/defaultPackage/) );
KnowledgeBase kbase = kagent.getKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ProcessInstance processInstnace = ksession.startProcess("myProcess.bpmn");
-
2. Re: How can I take process definitions from Guvnor with jBPM5 API?
liliana.iovanovici Feb 13, 2012 4:36 AM (in response to liliana.iovanovici)But I got an error:
null: 1, 1): Content is not allowed in prolog.
Exception in thread "main" java.lang.IllegalArgumentException: Unknown process ID: myProcess.bpmn
at org.jbpm.process.instance.ProcessRuntimeImpl.createProcessInstance(ProcessRuntimeImpl.java:152)
Does anybody know what is the problem?
Thanks.
Liliana
-
3. Re: How can I take process definitions from Guvnor with jBPM5 API?
eaa Feb 13, 2012 4:36 AM (in response to liliana.iovanovici)In Guvnor, each asset (rule, process, dsl, etc.) has a unique URL that you can use to retrieve its content. Guvnor also keeps a binary (compiled) version of each package containing all its assets that also has a unique URL you can use.
So, in order to get the "source code" of a process "Test" in a pacakge "TestPkg" you can use this URL: http://localhost:8080/drools-guvnor/rest/packages/TestPkg/assets/Test/source
And to get the binary representation of package 'TestPkg': http://localhost:8080/drools-guvnor/rest/packages/TestPkg/binary
Alternatively, you can also use the new Change-Set editor in Guvnor 5.4 to create a bundle of processes that you want to use together: http://docs.jboss.org/drools/release/5.4.0.Beta2/drools-guvnor-docs/html_single/index.html#d0e1703
Then you need to add the definitions and/or the packages and put them into a KnowledgeBuilder. Please refer to the documentation to see how this can be done: http://docs.jboss.org/jbpm/v5.2/userguide/ch04.html#d0e655
Best Regards,
-
4. Re: How can I take process definitions from Guvnor with jBPM5 API?
liliana.iovanovici Feb 13, 2012 8:12 AM (in response to eaa)Thanks for information Esteban.
I tried to put in my example above the URL: http://localhost:8180/guvnor-5.3.0.Final-jboss-as-7.0/rest/packages/defaultPackage/assets/myProcess/source .
And when I'm trying to start a process I got an Error: Exception in thread "main" java.lang.IllegalArgumentException: Unknown process ID: com.myProcess.bpmn (Even in the source I had this id: com.myProcess.bpmn):
<process processType="Private" isExecutable="true" id="com.myProcess.bpmn" name="Sample" tns:packageName="defaultPackage" tns:version="4" >
Do you know that is the problem?
Thanks for your help. I'm new in jBPM.
-
5. Re: How can I take process definitions from Guvnor with jBPM5 API?
eaa Feb 13, 2012 8:21 AM (in response to liliana.iovanovici)The source code of a package only contains Drools related assets like rules, functions, etc., but not processes. What you can do is either to use the binary package (you have to build the package first from Guvnor's UI) or to use the process' source URL instead of the package.
Also remember that KnowledgeBuilder doesn't throw any exception if it fails compiling a package. You have to manually check for errors after you add a resouce by using .hasErrors() and getErrors() methods.
Best Regards,
-
6. Re: How can I take process definitions from Guvnor with jBPM5 API?
liliana.iovanovici Feb 14, 2012 10:11 AM (in response to eaa)You had rights. The knowledge base is created only if the entire package built succesfully.
-
7. Re: How can I take process definitions from Guvnor with jBPM5 API?
cecchisandrone Sep 20, 2012 4:33 AM (in response to liliana.iovanovici)Can you show a code snippet to read a binary package from Guvnor?
Thanks!
-
8. Re: How can I take process definitions from Guvnor with jBPM5 API?
liliana.iovanovici Sep 20, 2012 8:56 AM (in response to cecchisandrone)KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("testKAgent", aconf);
String fileName = "http://localhost:8180/guvnor-5.3.0.Final-jboss-as-7.0/rest/packages/test/assets/";
kagent.applyChangeSet(ResourceFactory.newFileResource(fileName));
KnowledgeBase kbase2 = kagent.getKnowledgeBase();
StatefulKnowledgeSession ksession2 = kbase2.newStatefulKnowledgeSession();
ProcessInstance processInstance = ksession2.startProcess("myProcessTest.bpmn");
-
9. Re: How can I take process definitions from Guvnor with jBPM5 API?
cecchisandrone Sep 20, 2012 10:33 AM (in response to liliana.iovanovici)Thanks liliana, but I can't execute successfully your code (unable to parse ChangeSet error).
I've tried to modify your code as follows:
KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("testKAgent", aconf);
String fileName = "http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/plx/LATEST/ChangeSet.xml";
kagent.applyChangeSet(ResourceFactory.newUrlResource(fileName));
KnowledgeBase kbase2 = kagent.getKnowledgeBase();
StatefulKnowledgeSession ksession2 = kbase2.newStatefulKnowledgeSession();
ProcessInstance processInstance = ksession2.startProcess("plx.SimpleProcess");
But I obtain: Server returned HTTP response code: 401 for URL: http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/plx/LATEST/ChangeSet.xml
Did you remove authentication from Guvnor?
-
10. Re: How can I take process definitions from Guvnor with jBPM5 API?
ahmedza Apr 15, 2013 12:55 AM (in response to cecchisandrone)>>>>>>>>But I obtain: Server returned HTTP response code: 401 for URL: http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/plx/LATEST/ChangeSet.xml
>>>>>>Did you remove authentication from Guvnor?
You can either disable basic-authentication from your guvnor or pass authentication when you call applyChangeSet(URL url). I am adding the code below.
UrlResource urlResource = (UrlResource)ResourceFactory.newUrlResource( "http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/plx/LATEST/ChangeSet.xml" );
urlResource.setBasicAuthentication("enabled"); urlResource.setUsername("admin"); urlResource.setPassword("admin"); kagent.applyChangeSet( urlResource ); So here I am using applyChangeSet(URL url) instead of applyChangeSet(String filePath);
-
11. Re: How can I take process definitions from Guvnor with jBPM5 API?
sherin.syriac Dec 18, 2013 12:14 PM (in response to liliana.iovanovici)I got the error "Unknown process ID" while doing my first "hello world". I am sure by now you would have figured out this. But just for any other first timers. This is what I found . If you are using eclipse take the properties tab for *.bpmn process diagram and give the id you are using (myProcess.bpmn) as the value for Id property. That resolved my error.