访问远程会话 Bean

应用程序通过 Bean 的 home 接口来访问适当的远程会话 Bean。

执行本任务的原因和时间

会话 Bean 可以是 BusinessFlowManager 会话 Bean(用于流程应用程序)或 HumanTaskManager 会话 Bean(用于任务应用程序)。

本任务的步骤

  1. 在应用程序部署描述符中添加对远程会话 Bean 的引用。 请添加对下列其中一个文件的引用:
    • application-client.xml 文件(用于 Java™ 2 Platform, Enterprise Edition(J2EE)客户机应用程序)
    • web.xml 文件(用于 Web 应用程序)
    • ejb-jar.xml 文件(用于 Enterprise JavaBeans™(EJB)应用程序)
    以下示例显示了流程应用程序中对远程 home 接口的引用:
    <ejb-ref>
    	<ejb-ref-name>ejb/BusinessFlowManagerHome</ejb-ref-name>
    	<ejb-ref-type>Session</ejb-ref-type>
    	<home>com.ibm.bpe.api.BusinessFlowManagerHome</home>
    	<remote>com.ibm.bpe.api.BusinessFlowManager</remote>
    </ejb-ref>
    以下示例显示了任务应用程序中对远程 home 接口的引用:
    <ejb-ref>
    	<ejb-ref-name>ejb/HumanTaskManagerHome</ejb-ref-name>
    	<ejb-ref-type>Session</ejb-ref-type>
    	<home>com.ibm.task.api.HumanTaskManagerHome</home>
    	<remote>com.ibm.task.api.HumanTaskManager</remote>
    </ejb-ref>

    如果使用 WebSphere® Integration Developer 来在部署描述符中添加 EJB 引用,就会在部署该应用程序时自动为 EJB 引用创建绑定。要了解有关添加 EJB 引用的更多信息,请参阅 WebSphere Integration Developer 文档。

  2. 将生成的存根与应用程序打包到一起。

    如果该应用程序与 BPEContainer 应用程序或 TaskContainer 应用程序不在同一 Java 虚拟机(JVM)中运行,则完成下列操作:

    1. 对于流程应用程序来说,请将 <install_root>/ProcessChoreographer/client/bpe137650.jar 文件与应用程序的企业归档(EAR)文件打包到一起。
    2. 对于任务应用程序来说,请将 <install_root>/ProcessChoreographer/client/task137650.jar 文件与应用程序的 EAR 文件打包到一起。
    3. 将应用程序模块清单文件中的 Class-Path 参数设置为包括该 JAR 文件。 该应用程序模块可以是 J2EE 应用程序、Web 应用程序或 EJB 应用程序。
  3. 使应用程序能够通过 Java 命名和目录接口(JNDI)查询机制来使用该会话 Bean 的 home 接口。 以下示例显示了流程应用程序中的此步骤:
    // Obtain the default initial JNDI context
    InitialContext initialContext = new InitialContext();
    
      // Lookup the remote home interface of the BusinessFlowManager bean
      Object result = 
             initialContext.lookup("java:comp/env/ejb/BusinessFlowManagerHome");
    
    // Convert the lookup result to the proper type
       BusinessFlowManagerHome processHome = 
               (BusinessFlowManagerHome)javax.rmi.PortableRemoteObject.narrow
               (result,BusinessFlowManagerHome.class);
    会话 Bean 的 home 接口包含 EJB 对象的 create 方法。该方法返回该会话 Bean 的远程接口。
  4. 访问会话 Bean 的远程接口。 以下示例显示了流程应用程序中的此步骤:
    BusinessFlowManager process = processHome.create();
  5. 调用服务接口公布的企业函数。 以下示例显示了流程应用程序中的此步骤:
    process.initiate("MyProcessModel",input);
    应用程序中执行的调用是作为事务运行的。事务是以下列其中一种方式建立和结束的:
    • 由 WebSphere Application Server 自动建立和结束(部署描述符指定了 TX_REQUIRED)。
    • 由应用程序显式地建立和结束。可以将多个应用程序调用捆绑成一个事务:
      // 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();
以下是在任务应用程序中执行步骤 3 到 5 的示例。
// Obtain the default initial JNDI context
InitialContext initialContext = new InitialContext();

  // Lookup the remote home interface of the HumanTaskManager bean
  Object result = 
         initialContext.lookup("java:comp/env/ejb/HumanTaskManagerHome");

// Convert the lookup result to the proper type
   HumanTaskManagerHome taskHome = 
           (HumanTaskManagerHome)javax.rmi.PortableRemoteObject.narrow
           (result,HumanTaskManagerHome.class);

...
//Access the remote interface of the session bean.
HumanTaskManager task = taskHome.create();

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

使用条款 |


(c) Copyright IBM Corporation 2005, 2006.
本信息中心基于 Eclipse 技术(http://www.eclipse.org)。