Accessing the local session bean

An application accesses the appropriate local session bean through the home interface of the bean.

Why and when to perform this task

The session bean can be either the LocalBusinessFlowManager session bean for process applications or the LocalHumanTaskManager session bean for human task applications.

Steps for this task

  1. Add a reference to the local session bean to the application deployment descriptor. Add the reference to one of the following files:
    • The application-client.xml file, for a Java™ 2 Platform, Enterprise Edition (J2EE) client application
    • The web.xml file, for a Web application
    • The ejb-jar.xml file, for an Enterprise JavaBeans™ (EJB) application
    The reference to the local home interface for process applications is shown in the following example:
    <ejb-local-ref>
    	<ejb-ref-name>ejb/LocalBusinessFlowManagerHome</ejb-ref-name>
    	<ejb-ref-type>Session</ejb-ref-type>
    	<local-home>com.ibm.bpe.api.LocalBusinessFlowManagerHome</local-home>
    	<local>com.ibm.bpe.api.LocalBusinessFlowManager</local>
    </ejb-local-ref>
    The reference to the local home interface for task applications is shown in the following example:
    <ejb-local-ref>
    	<ejb-ref-name>ejb/LocalHumanTaskManagerHome</ejb-ref-name>
    	<ejb-ref-type>Session</ejb-ref-type>
    	<local-home>com.ibm.task.api.LocalHumanTaskManagerHome</local-home>
    	<local>com.ibm.task.api.LocalHumanTaskManager</local>
    </ejb-local-ref>

    If you use WebSphere® Integration Developer to add the EJB reference to the deployment descriptor, the binding for the EJB reference is automatically created when the application is deployed. For more information on adding EJB references, refer to the WebSphere Integration Developer documentation.

  2. Make the local home interface of the local session bean available to the application, using Java Naming and Directory Interface (JNDI) lookup mechanisms. The following example shows this step for a process application:
    // Obtain the default initial JNDI context
    InitialContext initialContext = new InitialContext();
    
      // Lookup the local home interface of the LocalBusinessFlowManager bean
     
       LocalBusinessFlowManagerHome processHome = 
            (LocalBusinessFlowManagerHome)initialContext.lookup
            ("java:comp/env/ejb/LocalBusinessFlowManagerHome");
    The home interface of the local session bean contains a create method for EJB objects. The method returns the local interface of the session bean.
  3. Access the local interface of the local session bean. The following example shows this step for a process application:
    LocalBusinessFlowManager process = processHome.create();
  4. Call the business functions exposed by the service interface. The following example shows this step for a process application:
    process.initiate("MyProcessModel",input);
    Calls from applications are run as transactions. A transaction is established and ended in one of the following ways:
    • Automatically by WebSphere Application Server (the deployment descriptor specifies TX_REQUIRED).
    • Explicitly by the application. You can bundle application calls into one transaction:
      // Obtain user transaction interface
         UserTransaction transaction= 
             (UserTransaction)initialContext.lookup("jta/usertransaction");
      
         // Begin a transaction
         transaction.begin();
      
           // Applications calls ...
      
         // On successful return, commit the transaction
         transaction.commit();
Here is an example of how steps 2 through 4 might look for a task application.
// Obtain the default initial JNDI context
InitialContext initialContext = new InitialContext();

  // Lookup the local home interface of the LocalHumanTaskManager bean
 
   LocalHumanTaskManagerHome taskHome = 
        (LocalHumanTaskManagerHome)initialContext.lookup
        ("java:comp/env/ejb/LocalHumanTaskManagerHome");

...
//Access the local interface of the local session bean
LocalHumanTaskManager task = taskHome.create();

...
//Call the business functions exposed by the service interface
task.callTask(tkiid,input);

Terms of use | | Broken links

Last updated: Tue Feb 21 17:21:50 2006

(c) Copyright IBM Corporation 2005.
This information center is powered by Eclipse technology (http://www.eclipse.org)