Try OpenEdge Now
skip to main content
BPM Events User's Guide
Accessing Java objects and EJB components : EJB component invocation
 

EJB component invocation

Invocation of an EJB from rules is similar to using external classes from BPM Events rules. The following sample application illustrates this process. This application, EJBTest, has a very simple rule file as follows:
application EJBTest
using java.lang.*;
using java.util.*;
using common.externalperformers.*;
module EJBTest_rules
{    try{
        val eJBClient = new ~EJBTestClient("t3://milpitas.openedge.com,belgium.openedge.com:8562");
        println(eJBClient.getStatus()) ;
    }catch(err: ~Exception){
        println(err.getMessage());
    }
}
The above application uses a Java class called EJBTestClient which looks up the EJB and calls methods on it. The constructor (which takes the URL of the application server) and the getStatus() method of EJBTestClient are illustrated in the following sample:
public EJBTestClient(String url)
    throws NamingException, CreateException,RemoteException
  {
    this.url = url;
    ejbtest_ref = lookupEJBTest(); //ejbtest_ref is the remote refernce to EJB kept by EJBTestClient
  }
  public String getStatus() throws RemoteException
  {
    System.out.println("Before calling getStatus");
    String s = ejbtest_ref.getStatus();
    System.out.println("After calling getStatus, return string is " + s);
    return s ;
  }
In order to make the EJB call work:
1. Make the EJBTestClient.class part of the common.externalperformers package and copy it to the %OEBPS_HOME%\ebmsapps\common\externalperformers folder.
2. Note the using common.externalperformers.* statement in the rule file, which says that BPM Events will attempt to find EJBTestClient.class in this folder.