当开发业务集成应用程序时,您可能需要使用一些资源,例如,JSP 文件、JAR 文件、Web 项目、Java™ 项目和 J2EE 项目。本主题提供了一些信息来帮助您设置项目和资源,以便可以成功地构建它们并将它们部署至 WebSphere® Process Server。
如果 Web 项目在另一个 EAR 文件中,则 JSP 文件在另一个模块中,并且需要执行导入和导出才能使它与另一个模块中的服务一起工作。
以下是一些使用模块组装中的独立引用的样本 JSP 代码:
com.ibm.websphere.sca.Service bankService = (com.ibm.websphere.sca.Service)com.ibm.websphere.sca.ServiceManager.INSTANCE.locateService("BankServicePartner"); => The "BankServicePartner" reference name comes from the sca.references file in the module (e.g. <reference name="BankServicePartner">...). This file will exist after creating a stand-alone reference in the wiring editor. com.ibm.websphere.sca.scdl.OperationType operationType = bankService.getReference().getOperationType("openAccount"); => We will use the operation type to get the DataObject types that need to be passed into the invoke operation com.ibm.websphere.bo.BOFactory factory = (com.ibm.websphere.bo.BOFactory) new com.ibm.websphere.sca.ServiceManager().locateService("com/ibm/websphere/bo/BOFactory"); => Standard way to obtain factory for creating business objects. commonj.sdo.DataObject input = factory.createByType(operationType.getInputType()); => create the proper kind of data object that the operation expects as input commonj.sdo.DataObject customer = input; => assume that we don't have a wrapped input, for now if(operationType.isWrapperType(operationType.getInputType())) { => In order to call the reference in this case, the wrapper defined in the interface's WSDL file must be passed in. So we create the wrapped data object and set it on the wrapper (the property name comes from the inlined schema in the WSDL file). customer = factory.createByType(operationType.getInputType().getProperty("customer").getType()); input.set("customer", customer); } customer.setString("firstName", "Bob"); customer.setString("lastName", "Smith"); customer.setString("address","7 Holly Drive"); customer.setBoolean("isGold", true); customer.setInt("birthYear", 1976); => The above 5 lines set the attributes on Customer. commonj.sdo.DataObject output = (commonj.sdo.DataObject)bankService.invoke("openAccount",input); commonj.sdo.DataObject account = null; if(operationType.isWrapperType(operationType.getOutputType())) account = output.getDataObject("account"); else account = output; => The output returned may or may not be wrapped.
最佳实践:如果需要开发 Java 应用程序或者导入将在业务集成模块中使用的 JAR 文件,则应该为代码创建 Java 项目,并将对 Java 项目的依赖性添加至将使用 Java 代码的模块。
不应改变业务集成库或模块的 Java 属性,因为这样做可能会导致生成部署代码时发生问题。因此,建议您不要开发复杂的 Java 应用程序或者将 JAR 文件导入库或模块中以便使用它们。另外,当为组装图中的组件生成 Java 实现时,应将生成的 Java 实现用作启动点来调用其他 Java 类。
注意,“业务集成”视图将只显示在组装图中所使用的 Java 实现和接口。它们将列示在使用它们的模块下面。如果您需要使用 Java 项目,则可以切换为在 Java 透视图中工作。
切换至 Java 透视图
通过执行下列步骤来打开 Java 透视图:
在 Java 透视图中,两个已打开的透视图显示在“工作台”窗口的右上角,可以通过单击“业务集成”透视图按钮来切换至“业务集成”透视图,如下图所示:
最佳实践:如果您打算在组装图中使用导入和导出,则最好是将导入和导出操作所使用的业务对象和接口放入库中,以便可以共享它们。然后,对使用这些公共资源的所有模块添加对该库的依赖性。应避免将相同的业务对象和接口添加到不同的模块中来使用它们。
如果需要在模块中使用 WSDL 文件,则将它复制到该模块中。(可选)将 WSDL 文件复制到库中,并且在模块中设置对库的依赖性,以便您可以使用该库的资源。如果您试图从另一种类型的项目(例如,Web 项目)中拖动 WSDL 文件,则会产生一条错误消息,提示您将该 WSDL 文件复制到模块或库中。
应避免在依赖性编辑器外部修改模块依赖性。
当您添加对库、Java 项目或 J2EE 项目的依赖性时,就会更改模块的属性。即,更改了模块的属性,如下所示:
使用依赖性编辑器来管理模块和库的项目依赖性,而不是编辑它们的属性。在模块和库的属性中设置了很重要的 Java 假定,因此,您不应修改 Java 属性,例如,更改它们的源文件夹和输出文件夹。