How to add a rule via DRL dynamically by a WorkItemHandler in BPMS 6.1 ?
Environment
- Red Hat JBoss BPM Suite
- 6.1
Issue
- How to add a rule via DRL dynamically by a WorkItemHandler in BPMS 6.1
We want to import a rule by via DRL text through the custom WorkItemHandler. But when the WorKitemhandler is executed, the fact types which are necessary to compile the rule are obviously not present.
DEBUG [com.sample.jbpm.workitem..CustomWorkItemHandler] (http-/127.0.0.1:8080-4) deploymentId: com.sample:DemoApplication:1.0-SNAPSHOT
ERROR [com.sample.jbpm.workitem..CustomWorkItemHandler] (http-/127.0.0.1:8080-4) ERROR:Unable to resolve ObjectType 'Check'
Resolution
The KnowledgeBuilder must be constructed with a KnowledgebuilderConfiguration which contains the class loader of the WorkItemHandler to be able to find the classes which are needed to compile the rule:
KnowledgeBuilderConfiguration newKnowledgeBuilderConfiguration =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null, this.getClass().getClassLoader());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(newKnowledgeBuilderConfiguration);
kbuilder.add(ResourceFactory.newByteArrayResource(drlText.getBytes()), ResourceType.DRL);
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
