Hi,
I have a question with regards to using CDI in work item handlers in jBPM. In our BPM deployment, we have a META-INF/kie-deployment-descriptor.xml. It lists some work item handlers that are needed, among which there are two custom ones, i.e. our item handlers. Declaration of said handlers uses MVEL resolvers and they get created and associate with their respective processes.
<work-item-handler> <resolver>mvel</resolver> <identifier>new com...LoadAppWorkItemhandlerImpl()</identifier> <parameters /> <name>LoadAppService</name>
When created this way however, I can't get any injection to happen. I finally understood that this was because my work item handlers are in fact not declared themselves as CDI beans, so nothing else will follow, as in fact @Inject annotations get ignored?
So I then wrote a producer to create my own work item handler, and at the same time annotate it with CDI annotations. My work item handler producer looks like this:
@ApplicationScoped
public class OgnWorkItemHandlerProducer implements WorkItemHandlerProducer {
@Inject
private DataManager dataManager;
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(String arg0, Map<String, Object> arg1) {
Map<String, WorkItemHandler> handlers = new HashMap<String, WorkItemHandler>();
LoadAppWorkItemhandlerImpl loadAppWorkItemHandler = new LoadAppWorkItemhandlerImpl();
loadAppWorkItemHandler.setDataManager(dataManager);
handlers.put("LoadAppService", loadAppWorkItemHandler);
return handlers;
}
}
What I want to achieve is to enable the injection of my data manager into the work item, so that if and when my handler gets invoked, I can use the data manager to access my database. So if I remove the declaration of the LoadAppWorkItemHandler from kie-deployment-descriptor.xml, the BPM process invocation fails with an error that looks like this:
11:17:38,958 WARN [org.kie.remote.services.cdi.ProcessRequestBean] (http-localhost/127.0.0.1:8080-6) Unable to execute StartProcessCommand/0: org.kie.remote.services.rest.exception.KieRemoteRestOperationException:
[com...LoadAppProcess:1 - Load application:3] -- Could not find work item handler for LoadAppService
...
Caused by: org.jbpm.workflow.instance.WorkflowRuntimeException: [com...LoadAppProcess:1 - Load application:3] -- Could not find work item handler for LoadAppService
...
Caused by: org.drools.core.WorkItemHandlerNotFoundException: Could not find work item handler for LoadAppService
I interpret this as if the work item handler producer was not being called and the process not having a corresponding handler to handle the control over to?
So I guess my question then is how do I trigger the invocation of my work item handler producer and get its injection points satisfied? Just to rule out the obvious, I do have a beans.xml in my META-INF.
All help much appreciated.
Thanks,
Nenad