实现
创建 WebSphere Process Server 模块
遵循以下步骤,创建 WebSphere Process Server 模块:
- 在 WebSphere Integration Developer 6.0.2 中,选择 Open File > New > Project > BusinessIntegration > Module,然后单击 Next。
- 输入一个模块名:
WPSWSATSample,然后选择 Finish。
- 导入 MDM Web 服务 WSDL 文件,如 图 4 所示:
图 4. 导入的 MDM Services 接口
从 下载 小节提供的 WPSServerSideSample.zip 资源中导入 Common.wsdl、PartyBinding.wsdl、PartyPort.wsdl 和 PartyService.wsdl。这些文件与 IBM MDM Server 发行版在 Samples 中提供的 WSDL 文件一样。
导入或创建客户端应用程序所需的接口
如 图 5 所示,从 下载 小节提供的 WPSServerSideSample.zip 资源中导入 WPSPartyService.wsdl。客户端应用程序将调用 WPSPartyService 中定义的操作。
图 5. 导入的客户端接口
将客户端 ASBO 映射到 MDM Web 服务 ASBO
在大多数情况下,当模块中包括业务对象时,使用 GBO。通常,客户端 ASBO 被映射到 GBO,GBO 又被映射到 MDM Web 服务 ASBO。通过使用这种方法,如果任何 ASBO 发生更改,就不需要更改业务流程。只需将 ASBO 重新映射到相应的 GBO。为了将焦点放在事务上下文传播上,本教程省略了 GBO 实现。相反,您将直接将客户端 ASBO 映射到 MDM ASBO。在大多数情况下,本教程为客户端和服务器端使用相同的 ASBO。一个例外是 Control 业务对象,它提供了一个关于如何进行 ASBO-to-ASBO 映射的例子。图 6 展示了简单的 ASBO 映射,其中 Control2 是客户端 ASBO,而 Control ASBO 来自 MDM 服务器:
图 6. 映射 Control ASBO
创建客户端到服务器接口映射
图 7 和 图 8 展示客户端 WPSPartyService.AddParty 操作如何被映射到 MDM Server 提供的
PartyService.AddParty 操作:
图 7. Map AddParty 客户机服务和 AddParty MDM Server 服务
图 8. 映射 AddParty 服务的服务参数
参考 图 7 和 图 8 中所示的映射,对 GetParty 和 SearchParty 服务进行相同的映射。
装配业务集成模块
在装配图中,拖动新创建的 WPSPartyService 接口,使用 Web 服务绑定,类型选择为 export。对于 MDM PartyService 接口,选择的类型应该为 import,实现类型应该为 Web Service binding。对于新创建的接口映射,应该将它的类型设为 component,没有实现类型。图 9 显示了这些参数选择:
图 9. 参与者服务的装配图映射
更新 WebSphere Process Server 模块部署描述符
像下面这样更新 WebSphere Process Server 模块的部署描述符:
- 打开为会话 bean 模块生成的 EJB 项目的部署描述符。
- 在 Global Transaction 选项卡上,勾选 Web Services Atomic Transaction,如图 图 10 所示:
图 10. Global Transaction 选项卡的设置
- 对于 Local Transaction 2.0,选择 BeanMethod,如 图 10 所示。默认情况下,对于本地事务设置,Boundary 被设为 ActivitySession。在这个例子中,要在客户端应用程序中开始一个全局事务。全局事务不能包含 ActivitySession。如果选择 ActivitySession,那么全局事务将被挂起,事务上下文不能传播到 MDM 服务器上。
- 此外,在 Assembly 选项卡下,删除与
ActivitySession 相关的设置,如图 图 11 所示:
图 11. Assembly 选项卡下与 ActivitySession 相关的设置
构建客户机
客户端应用程序用于调用 WebSphere Process Server 模块提供的 Web 服务。这个应用程序模拟另一个 EIS 或服务使用者可能发出的调用。清单 1 提供了一个例子,这个例子在 JTA 事务中调用 MDM 服务,并且还包含模拟的成功/回滚动作。当 JTA 事务开始时,会在 WebSphere Process Server 上调用 WPSPartyService.AddParty 接口。(还记得吗,这是使用很多 MDM 服务创建的一个新的复合服务)。通过这个调用,WS-Coordination 上下文被从客户端应用程序传播到 WebSphere Process Server,然后再传播到 MDM Server。最后,MDM Server 执行 AddParty 服务中的 AddParty 操作,并等待它提交或回滚。在这个例子中,引入了一个失败点,以便演示全局事务的回滚功能。客户机发送用户提供的关于事务类型的输入参数(txType),表明调用服务后提交还是回滚事务,最终完成事务。
清单 1 中的代码是 Invoker.java 类的一个片段,这个类在 WPSClient.zip(参见 下载)中。它提供一个关于如何调用服务进行测试的示例。
清单 1. 测试全局事务的示例代码
try
{
// Set up JTA transaction
InitialContext cxt = new InitialContext();
userTransaction = (UserTransaction) cxt.lookup("java:comp/UserTransaction");
// Start the JTA transction here
userTransaction.begin();
// Invoke MDM addParty Services through WPS
resp=wpsPartyService.addParty(control,person);
// Simulate the failure point if user choose to roll back
if(txType.equals("rollback"))
{
throw new java.rmi.RemoteException("Throw an exception to roll
back the transaction");
}
else
{
// Commit the transaction
userTransaction.commit();
}
}
catch(Exception e)
{
try
{
// Roll back the transaction, so that the party is not added.
userTransaction.rollback();
}
catch (Exception e1)
{
// Do some error handling here.
}
}
|
运行示例
为了运行示例应用程序,需要执行以下步骤:
- 从 下载 小节下载客户端应用程序示例 WPSClient.ear 和 WebSphere Process Server 示例 WPSServerSideSample.zip。
- 将 WPSClient.ear 导入到一个新的 WebSphere Integration Developer 工作区中。
- 将应用程序从 WPSServerSideSample.zip 导入到 WebSphere Integration Developer 工作区:
- 选择 File > Import >
Project Interchange。
- 打开该模块的部署描述符。更新与活动会话相关的事务设置(如 图 10 和 图 11 所示),并部署应用程序。
- 客户端应用程序的名称为 WPSWSAT. Launch wsat.jsp。
- 对于 图 12 中显示的字段,输入以下示例值:
- WPS Service EndPoint:http://localhost:9081/WPSWSATSampleWeb/sca/WPSPartyServiceExport
- WS-AT Test Type:Rollback
- Party Id:1001
- Name:aName
图 12. 新的服务端点 URL
- 选择一个 “WS-AT Test Type”(参见 图 12)。如果选择 Commit,客户机将提交用户事务,参与者被添加到数据库。如果选择 Rollback,那么客户机回滚事务,参与者不添加到数据库。在图 12 所示的例子中,选择的是 Rollback。
“Transaction has been” 这一行显示提交请求后,事务被提交还是被回滚。(如 图
12 所示)。
通过使用客户端应用程序,还可以检查参与者是否已被添加到 MDM Server 数据库。如果 WS-AT 测试类型为 “Committed”,那么输入被添加的参与者的 party id,并提交请求,如图 图 13 所示。在这个例子中,使用的 party id 为 1001。“The party added is” 这一行应该显示被添加到数据库的参与者的 party id。否则,将不显示 party id。在这个例子中,party id 没有显示,因为 图 12 中选择的 WS-AT Test Type 是 Rollback。
图 13. GetParty 操作
当事务上下文在服务器之间传播时,可以使用 TCP/IP 监视器跟踪事务上下文。
- 在 WebSphere Integration Developer 中,选择 Window >
Preferences > Internet > TCP/IP
Monitor。
- 单击 Add 创建一个新的 TCP/IP 监视器。
- 在 local monitoring port 字段中,输入用于跟踪事务上下文的端口。(对于本教程,监视器端口被设置为 65534,如 图 14 所示)。
- 在 Edit Monitor 面板,输入 MDM Server Web Services 的主机名、端口和类型(如 图 14) 所示)。
图 14. TCP/IP Monitor 的配置
- 单击 OK 保存设置,并选择 Start 启动监视器。
- 为了显示 TCP/IP 监视器,选择 Window > Show
view > TCP/IP monitor。
- 更新端点,以便使用被监视的端口。进入 WebSphere Integration Develope 的 Resources 透视图,在 WPSWSATSample 项目中的 PartyServiceImport1.import 中进行更新。在这里,使用的端点是 http://localhost:65534/PartyWS_HTTPRouter/Services/PartyPort。
图 15. TCP/IP 监视器显示上下文的传播
通过 TCP/IP 监视器,可以查看系统之间交换的 SOAP 消息,清单 2 显示了 SOAP 消息的 WS-Coordination 部分: 清单 2. 显示 WS-Coordination 部分的 SOAP 消息片段
<soapenv:Header>
<wscoor:CoordinationContext soapenv:mustUnderstand = "1">
<wscoor:Identifier>
com.ibm.ws.wstx:0000011b43225a88000000030000000144920bc2747b4a13e1f551c8c7e2c29a72921091
</wscoor:Identifier>
<wscoor:Expires>0</wscoor:Expires>
<wscoor:CoordinationType>
http://schemas.xmlsoap.org/ws/2004/10/wsat
</wscoor:CoordinationType>
<wscoor:RegistrationService xmlns:wscoor="http://schemas.xmlsoap.org/ws/2004/10/wscoor">
<wsa:Address xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
http://9.26.117.73:9081/_IBMSYSAPP/wscoor/services/RegistrationCoordinatorPort
</wsa:Address>
<wsa:ReferenceProperties xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
<websphere-wsat:txID xmlns:websphere-wsat="http://wstx.Transaction.ws.ibm.com/extension">
com.ibm.ws.wstx:0000011b43225a88000000030000000144920bc2747b4a13e1f551c8c7e2c29a72921091
</websphere-wsat:txID>
<websphere-wsat:instanceID
xmlns:websphere-wsat="http://wstx.Transaction.ws.ibm.com/extension">
com.ibm.ws.wstx:0000011b43225a88000000030000000144920bc2747b4a13e1f551c8c7e2c29a72921091
</websphere-wsat:instanceID>
</wsa:ReferenceProperties>
<wsa:ReferenceParameters xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
<wsaucf:RoutingInformation xmlns:wsaucf="http://ucf.wsaddressing.ws.ibm.com">
<wsaucf:Fragile>Fragile</wsaucf:Fragile>
</wsaucf:RoutingInformation>
</wsa:ReferenceParameters>
</wscoor:RegistrationService>
</wscoor:CoordinationContext>
</soapenv:Header> |

 |

|
|