应用程序通过 Bean 的 home 接口来访问适当的远程会话 Bean。
执行本任务的原因和时间
会话 Bean 可以是 BusinessFlowManager 会话 Bean(用于流程应用程序)或 HumanTaskManager 会话 Bean(用于任务应用程序)。
本任务的步骤
- 在应用程序部署描述符中添加对远程会话 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 文档。
- 将生成的存根与应用程序打包到一起。
如果该应用程序与 BPEContainer 应用程序或 TaskContainer 应用程序不在同一 Java 虚拟机(JVM)中运行,则完成下列操作:
- 对于流程应用程序来说,请将
<install_root>/ProcessChoreographer/client/bpe137650.jar
文件与应用程序的企业归档(EAR)文件打包到一起。
- 对于任务应用程序来说,请将
<install_root>/ProcessChoreographer/client/task137650.jar
文件与应用程序的 EAR 文件打包到一起。
- 将应用程序模块清单文件中的 Class-Path 参数设置为包括该 JAR 文件。 该应用程序模块可以是 J2EE 应用程序、Web 应用程序或 EJB 应用程序。
- 使应用程序能够通过 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 的远程接口。
- 访问会话 Bean 的远程接口。 以下示例显示了流程应用程序中的此步骤:
BusinessFlowManager process = processHome.create();
- 调用服务接口公布的企业函数。 以下示例显示了流程应用程序中的此步骤:
process.initiate("MyProcessModel",input);
应用程序中执行的调用是作为事务运行的。事务是以下列其中一种方式建立和结束的:
以下是在任务应用程序中执行步骤 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);