LSPS documentation logo
LSPS Documentation
Custom Objects as EJBs

When implementing your Task Types and Function in Java, you can implement them as POJOs or as EJBs: it is recommended to use POJOs unless the object needs to use a server service.

In such a case, the EJB must be then registered with the Execution Engine using the ComponentServiceBean.

Registering EJBs

If your custom object needs to inject EJBs, you will need to implement its as EJB and register it with the Execution Engine:

  1. Make sure your implementation is annotated as an EJB.
  2. In your ejb project, edit the ComponentServiceBean class:
    • For custom tasks, use the ExecutableTask interface with the bean name set to the implementing class name.
      @EJB(beanName="SendGoodsTask")
      private ExecutableTask sendGoodsTask;
    • For custom functions, use your local interface that declares all functions used in the model.
      @EJB(beanName="ShippingFeeFunctions")
      private ShippingFeeFunctions shippingFeeFunctions;
    • For pure EJBs, add the bean directly.
      @EJB
      private UserBean userBean;
  3. Register the custom component implementing the registerCustomComponents() method:
    • If you have your interface for your implementation:
      @Override
      protected void registerCustomComponents() {
        //register(<task_instance>, <task_interface>.class);
        register(sendGoodsTask, SendGoodsTask.class);
        //register(<function_instance>, <function_interface_class>.class);
        register(shippingFeeFunctions, ShippingFeeFunctions.class);
      }
      
    • If you do not have an interface for your implementation:
      @Override
      protected void registerCustomComponents() {
        register(<task_instance>, <task_implementation>.class);
        register(<function_instance>, <function_implementation>.class);
      }
      

Handling Exceptions in EJB Functions and Task Types

If a custom a task or function implemented as a session bean fails with an exception on runtime, the current transaction is rolled back and the interpretation fails even if the exception is caught later (for example, by a boundary Error Intermediate Event). Hence make sure to catch all exceptions in your bean.

Use RuntimeExceptionCatcherInterceptor as an interceptor in your stateless beans. This interceptor catches all runtime exceptions thrown from a bean's business methods and converts them to ErrorExceptions, which can be handled in your model by the with the error mechanism of the GO-BPMN Modeling Language.