cancel
Showing results for 
Search instead for 
Did you mean: 

activiti-osgi classloader issue

workflowuser2
Champ in-the-making
Champ in-the-making
Hi,

I have two bundles :
activiti-osgi-karaf: configures and starts process engine (depends on activiti-osgi)
activiti-osgi-process: contains process.bpmn20.xml, java delegates, process-request bean

reference: activiti-in-action book. java delegates are binded into osgi container as service

process-request bean is a java bean I pass into process variables map:
Map<String, Object> params = new HashMap<String, Object>();
params.put("request", new ProcessRequestBean());
processEngine.getRuntimeService().startProcessInstanceByKey(
            "process", params);

Now, when I try to access ProcessRequestBean into a java delegate:

ProcessRequestBean testPayload = (ProcessRequestBean) execution.getVariable("request");

===
The above works for service tasks.
However, if I put activiti:async="true" in the service task definition, I get the following exception:

Exception in thread "pool-13-thread-3" org.activiti.engine.ActivitiException: coudn't deserialize object in variable 'request'
   at org.activiti.engine.impl.variable.SerializableType.getValue(SerializableType.java:60)
   at org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.getValue(VariableInstanceEntity.java:158)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.getVariable(VariableScopeImpl.java:93)
   at com.acme.workflow.delegates.MyDelegate.execute(DiscoveryHandler.java:20)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler.java:50)
   at org.apache.aries.proxy.impl.DefaultWrapper.invoke(DefaultWrapper.java:31)
   at org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:78)
   at $Proxy67.execute(Unknown Source)

It appears to be classpath/loader issue. In the osgi env, I believe that both engine and process bundles class loaders should be available.

Any help is greatly appreciated.
Activiti newbie
6 REPLIES 6

frederikherema1
Star Contributor
Star Contributor
Make sure your ProcessRequestBean implements Serializable. If it's a simple service-task, the process is not persisted and the POJO is still in memory (variable values are cached). Once you have an async, it's serialized to DB and when job-executor does the async work, it's de-serialized again when needed…

If you did implement Serializable, it's indeed an issue with classloading in the job-executor… Can you debug to see what's causing the " org.activiti.engine.ActivitiException: coudn't deserialize object in variable 'request'" in the first place?

workflowuser2
Champ in-the-making
Champ in-the-making
Make sure your ProcessRequestBean implements Serializable. If it's a simple service-task, the process is not persisted and the POJO is still in memory (variable values are cached). Once you have an async, it's serialized to DB and when job-executor does the async work, it's de-serialized again when needed…

If you did implement Serializable, it's indeed an issue with classloading in the job-executor… Can you debug to see what's causing the " org.activiti.engine.ActivitiException: coudn't deserialize object in variable 'request'" in the first place?

frederikheremans

ProcessRequestBean does implements Serializable.
When I debugged, the issue appears to be de-serializing the ProcessRequestBean  bytes  from the db.

It appears to be classloader issue. ProcessRequestBean  classloader, is perhaps, not available in the activiti-osgi-karaf bundle.

Do you think the following may help?
http://forums.activiti.org/en/viewtopic.php?f=4&t=1433&start=0

frederikherema1
Star Contributor
Star Contributor
You should try that approach, indeed (setting the class loader).

workflowuser2
Champ in-the-making
Champ in-the-making
Hi frederikheremans,

I further looked into this issue and it appears that it might be related to OSGi bundling of activiti-engine.
activiti engine need to allow importing client packages in addition to its own dependencies.

Since these packages/classes are not known during activiti-engine bundle/build time, the MANIFEST.MF file should contain something like below:
DynamicImport-Package: *

I looked at libraries similar to activiti and they use the same mechanism to allow loading client packages.

Let me know your thought and if you want me to test/work on this while I am working on other osgi issues.

activiti newbie
You should try that approach, indeed (setting the class loader).

frederikherema1
Star Contributor
Star Contributor
Yes, this would be good to work on and test to allow cross-bundle imports, not know at build-time.

rahulkrs
Champ in-the-making
Champ in-the-making
Did you able to solve this problem? I also got in to a similar issue , when JobExecutor is trying to access the service task which is deployed in a different bundle. I am getting a class not found exception.