Calling method in bean via (delegate) expression via CDI possible?

Hi,
I use camunda 7.15 with wildfly 20.
I have got a process application (so I have got no ejbs). I want that a service task calls a method in my corresponding bean.
Calling the execute() method is possible when I use this from my service task:
grafik

 public class ThesisWKBusinessLogic implements JavaDelegate{

public void execute(DelegateExecution execution) throws Exception {
	getThesisWorkerViaREST(execution);
}

That works. But I want to use several methods like it is possible with ejb.

I tried the following:

  • Using Delegate Expression (I also tried Expression) in Service task
    grafik

  • adding cdi in pom.xml

      <dependency>
      	<groupId>org.camunda.bpm</groupId>
      	<artifactId>camunda-engine-cdi</artifactId>
      </dependency>
    

with this code:

@BusinessProcessScoped 
public class ThesisWKBusinessLogic implements JavaDelegate,Serializable{	
...
	public void testBeanAccess(DelegateExecution execution) throws Exception {
		System.out.println("Zugriff auf Methode über CDI erfolgreich");
	}

But it does not work, I think I did not understand the concept. Can anyone please help me?
Thank you,
Nicole

Hi Nicole,

we’re using different versions of Camunda on different Wildfly servers (10,16,…) for years.

To already existing EJB SessionBeans we simply added the javax.inject.Named annotation to use them via CDI from Camunda Service Tasks.
By default the name of the CDI managed bean is the name of the class with first letter in lower case, but if you like you can give it your own name, e.g. when there are two classes with same name in different packages (@Named(“aDifferentNameYouLikeMore”)).

Example:

@Stateless
@Named
public class SalesOrder extends ...
{
...
    public void printPickingDocument_sla( final DelegateExecution execution )
    {
    ...
    }
}

Regards, Frank

Hi Frank,

I used it in this way before but now I have got NO EJBs because I have got only a java process application like it is described here: Get started with Camunda and BPMN 2.0 | docs.camunda.org grafik

So I can not use the ejb annotations.
any more ideas?
Thank you, regards,
Nicole

Hello @NickiMueller ,

this looks like you have a tomcat?

A Tomcat has no context by default, you should provide one with a framework (Google Guice maybe).

To use expressions that can be resolved inside your (custom) context, you can extend the org.camunda.bpm.engine.impl.el.ExpressionManager to serve your needs.
org.camunda.bpm.engine.spring.SpringExpressionManager is the implementation that is used inside the spring boot impl.

This expression manager is the bridge from your provided expression to the context that you use.

Hope this helps

Jonathan

Ok, thank you. I will try it.
Regards, Nicole

Hi Nicole,

in my case the class already was an EJB, but it’s not a prerequisite.
Only @Named without @Stateless also works within Wildfly, at least for me.

package biz.mbisoftware.fn.ejb.session.sales;

import javax.inject.Named;

import org.apache.log4j.Logger;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.camunda.bpm.engine.delegate.DelegateExecution;

import biz.mbisoftware.fn.wstypes.sales.SalesOrderKey;

@Named
public class SalesOrderTest
{
    private static final Logger LOGGER = Logger.getLogger( SalesOrder.class );

    public void printPickingDocument_sla( final DelegateExecution execution )
    {
        if ( SalesOrderTest.LOGGER.isDebugEnabled() ) {
            SalesOrderTest.LOGGER.debug( execution );
        }
        try {
            String businessKey = execution.getProcessBusinessKey();
            SalesOrderKey salesOrderKey = new SalesOrderKey( businessKey );
            **SalesOrderTest.LOGGER.info( salesOrderKey );**
        } catch ( Exception e ) {
            throw new BpmnError( e.getMessage() );
        }
        if ( SalesOrderTest.LOGGER.isDebugEnabled() ) {
            SalesOrderTest.LOGGER.debug( "" );
        }
    }
}

image