在IBMLotusExpeditor中构建并部署简单的Web服务资源

Web 服务资源框架(Web Services Resource Framework,WSRF)规范为使用 Web 服务有状态地访问资源的机制制定了标准。IBM Lotus ExpediTor 将 WSRF 作为一项特性整合进来,使您可以将 Open Service Gateway initiative(OSGi )服务作为资源公开。本文介绍了 WSRF 所涉及的概念,并阐明了与建模和公开 简单的有状态资源(使用 Web 服务作为 OSGi 包实现)相关的步骤。然后进一步 说明了如何使用 WSRF 规范中所定义的消息交换模式标准集,访问这种有状态资 源。本文使用的示例代码是为 IBM Lotus ExpediTor Client for Desktop V6.1.0 所提供的 OSGi 运行时开发的。

在本文中,您将学习以下内容:

如何建模简单的有状态资源。

如何使用 Lotus ExpediTor Toolkit 来实现 WS-Resource 提供程序端组件。

如何使用 Lotus ExpediTor Toolkit 来创建 WS-Resource 客户端组件。

如何在 Lotus ExpediTor Client 中部署 WS-Resource。

如何开发与 WS-Resource 一起工作的应用程序。

本文假定您已具备核心 Java 开发技能,以及 Web 服务、XML 和 OSGi 的基 础知识。同时,为了运行示例应用程序,您必须在 Windows/Linux 系统上安装以 下软件:

Java 1.4.2

Lotus ExpediTor Client V6.1.0(带有 Web Services Resource Framework 6.1.0.0)

Eclipse 3.2.0 和 Web Tools Project (WTP) 1.5.1

Lotus ExpediTor Toolkit(带有 Mobile Web Services 6.1.0)

Lotus ExpediTor 中的 WS-Resource

WS-Resource 是资源和 Web 服务的组合,通过此 Web 服务可以访问资源。 Lotus ExpediTor Client for Desktop 使用以下组件原型来实现 WS-Resource:

资源

资源是封装了一个或多个必须公开为 WS-Resource 的有状态 OSGi 服务对象 的 OSGi bundle。这些服务对象可以是业务实体视图(如 ShoppingCart 或 PrintJob),或是物理资源的软件 facade(如 Printer)。您需要提供服务对象 的实现作为 OSGi bundle。

Web 服务

Web 服务是充当 WS-Resource 的 Web 服务 facade 的 OSGi bundle。此组件 公开了 WSRF 标准端口类型和定制端口类型,如 WS-Resource 的 Web 服务描述 语言(Web Services Description Language,WSDL)中所述。您可以使用 Mobile Web Services 生成器向导为给定的资源描述生成完整的 Web 服务 bundle。

适配器

适配器是充当 Web 服务 bundle 和资源 bundle 之间桥梁的 OSGi bundle。 它将传入的 Web 服务消息(包括 WSRF 标准端口类型和定制端口类型)发送到请 求方选定的资源实例。资源的任何响应(包括异常)将通过适配器和 Web 服务 bundle 作为正常响应或错误返回给请求方。生成 Web 服务 bundle 时,Mobile Web Services 生成器向导也生成了带有占位符的适配器 bundle。您需要提供将 适配器绑定到资源实例的实现。

客户机存根(client stub)

客户机存根是通过应用程序可用于访问 WS-Resource 并与 WS-Resource 一起 工作的 Java 归档。这种客户端组件(也称为 Web 服务客户机存根)将 Java API 调用转换为订阅由 WS-Resource 发布的 WSDL 文件的 SOAP 消息。您完全可 以使用生成器向导来生成这些客户机存根。

更多信息请参考 Lotus ExpediTor Help 部分的 “Developing Applications for Lotus ExpediTor”。

设置并验证开发环境(Lotus ExpediTor Toolkit)

使用带有 Mobile Web Services 的 Lotus ExpediTor Toolkit 作为 WS- Resource 提供程序组件和 WS-Resource 客户机组件的开发平台,并在此平台上 测试组件。

请按照下面的步骤来设置开发环境:

安装带有 Web Tools Project(WTP)1.5.1 的 Eclipse 3.2.0。

安装 Lotus ExpediTor Toolkit。

重新启动 Eclipse。

注意;Mobile Web Services 6.1.0 是作为 Lotus ExpediTor Toolkit 的一 部分安装的。更多信息请参考 Lotus ExpediTor Toolkit Help。

请按照这些步骤来验证开发环境的设置:

运行 Eclipse。

选择 File – New – Other。

在 Select a wizard 窗口中,展开 Mobile Web Services。

验证 WS-Resource Client 和 WS-Resource Provider 是否显示为 Mobile Web Services 的子节点。

构建样本 WS-Resource

在本部分中,将介绍用来开发简单 WS-Resource 的方法和工具,并使用 Lotus ExpediTor Toolkit 进行测试。您可以在本文的 下载部分 找到完整的 WS-Resource 源代码。在本部分,您将按照以下步骤从头开发 WS-Resource 的所 有组件:

构造样本 WS-Resource 的设计模型。

实现 WS-Resource 的资源 bundle。

使用生成器工具来生成提供程序端组件。

实现将适配器组件绑定到资源组件的逻辑。

使用适配器工具来生成客户端组件。

开发并执行测试应用程序。

在后面的部分中,我们将介绍打包并部署 Lotus ExpediTor Client for Desktop 中的 WS-Resource 以及 WS-Resource 的客户机应用程序组件的步骤。 开发并访问安全的 WS-Resource 不在本文讨论的范围内。

建模样本 WS-Resource

为了将精力集中在用来开发 WS-Resource 的方法和工具上,我们将使用一个 非常简单的数据对象(例如 Address)作为 WS-Resource 进行建模。资源的属性 包括 eMailID、preference 和 personDetails(参见图 1)。请注意其中将 PersonDetails 和 ContactInfo 看作是 Address 资源的资源属性。同时,为了 创建多个 Address WS-Resource 实例(并与其一起工作),我们在设计模型中包 含了 AddressFacTory 类。

图 1. Address 资源 —— 设计模型

注意:对自己的 WS-Resource 的进行建模时,请参考 Lotus ExpediTor Help 部分的 “Developing Applications for Lotus ExpediTor”,了解受支持的数 据类型。

开发资源 bundle

现在必须使用 Lotus ExpediTor Toolkit 来将上述设计模型作为 OSGi bundle 实现。使用 Eclipse SDK 3.2.0(或更新版本)的插件开发向导将资源 bundle 作为 Eclipse 插件开发。为此,在插件开发向导中创建新的插件项目时 ,请选择 OSGi Framework 作为标准。

下载部分 给出了资源 bundle 的完整源代码。请注意,在 AddressInterface 中将 Address 资源的资源属性编码为 get/set 方法:

清单 1. com.ibm.wsrf.sampleapp.address.service.AddressInterface

public interface AddressInterface {public void setEmailId(String emailId);public String getEmailId();public boolean getStatus();public void setStatus(boolean status);public String getPreference();public void setPreference(String pref) throws Exception;public float getVersionNumber();public void setVersionNumber(float VersionNumber);public Date getValidUntil();public void setValidUntil(Date ValidUntil);public PersonDetails getPersonDetails();public void setPersonDetails(PersonDetails pDetails);public ContactInfo getContactInfo();/****************************************************** Service Methods          *****************************************************/public ContactDetails[] getContactDetails(int type)throws ContactDetailsNotFoundException, InvalidAddressTypeException;public void addContactDetails(ContactDetails contactObj);public void addDependents(String[] names);}

稍后使用 Mobile Web Services 生成器向导时,这个类似 bean 的接口将用 于描述 WS-Resource 的 Resource Property 文档。

适配器组件将使用 AddressFacToryInterface 来创建新的 Address 资源实例 或定位 Address 实例:

清单 2. com.ibm.wsrf.sampleapp.address.service.AddressFacToryInterface

public interface AddressFacToryInterface {   public String createAddress(String eMailId) throws Exception;   public void deleteAddress(String eMailId) throws Exception;   public AddressInterface getAddress(String eMailId) throws Exception;}

您必须将生成的激活器修改为包含 start() 和 stop() 方法:

清单 3. com.ibm.wsrf.sampleapp.address.bundle.AddressActivaTor

public class AddressActivaTor implements BundleActivaTor {   private ServiceRegistration serviceRegistration = null;   public AddressActivaTor() {   }  public void start(BundleContext context) throws Exception {    Hashtable properties = new Hashtable();    serviceRegistration = context.registerService     (AddressFacToryInterface.class.getName(), new  AddressFacToryImpl(), properties);  }  public void stop(BundleContext context) throws Exception {     serviceRegistration.unregister();  }}

请注意,将 AddressFacToryImpl(而不是 AddressImpl)实例注册为服务实 现。这样做是为了简化创建多个 Address 资源,以及定位相关的 Address 资源 实例并与其一起工作。

生成资源 bundle 的提供程序端组件

您可以使用 Lotus ExpediTor Toolkit 的 Mobile Web Services 来生成资源 适配器和 WS-Resource 的 Web 服务 bundle。请参考 Lotus ExpediTor Toolkit Help 部分的 “Developing Applications for Lotus ExpediTor”,查看关于如 何使用生成器向导来生成提供方端组件的说明。

使用 WS-Resource Provider 向导时,请将 AddressFacToryInterface 指定 为资源类。向导将自查 Java 接口以获得 bean 属性,并给出提示,说明它们是 预期的资源属性。您可以选择这些资源属性,或指定新的资源属性名称。这些属 性将用于构造 Resource Property 文档。

在 WS-Resource Provider 向导中,请确保完成以下操作:

选择 WS-Resource Lifetime 和 Expose Service Methods 属性。

未选择 Enable Security 属性。

选择向导的 Resource Property 面板中所列示的所有资源属性。

仅选择向导的 Service Methods 面板中 Address 资源设计模型(图 1)中被 标识为服务方法的那些方法。

根据需要,在向导中编辑插件属性和项目属性。

绑定生成的代码和资源 bundle

WS-Resource Provider 向导将在 Eclipse 工作区中生成两个项目,用于两个 提供程序端 bundle,即适配器 bundle 和 Web 服务 bundle。Web 服务 bundle 不需要修改,可直接进行部署。但是,适配器 bundle 必须进行编辑并绑定到资 源 bundle。

如果浏览所生成的适配器代码,会注意到下面的 Java 类带有 TODO 占位符:

LifeTimeManager.java

PropertyManager.java

在 AddressLifeTimeManager 类中,必须给出 createResource()、 destroyResource() 和 getResource() 操作的实现。这些操作将被绑定,以便使 用由 Address 资源 bundle 中的 AddressFacToryImpl 提供的相应服务。

绑定 createResource() 操作

当客户机应用程序要创建新的 Address 资源时,它会发送 createResource() 消息到 WS-Resource 提供程序。WSRF 将该消息发送到适配器组件的 AddressLifeTimeManager 类。在 ConfigInfo 参数中,将 createResource() 的 初始化参数作为 XML 文档进行发送。在作为 ResourceConfiguration 对象的 AddressLifeTimeManager 的 createResource() 操作中,可以得到该 XML 文档 。

请注意,此初始化参数是从 ResourceConfiguration 中提取出来并随 createAddress() 消息发送到 AddressFacToryImpl 的:

清单 4. createResource 代码片段

public ResourceConfiguration createResource(Element configInfo)         _throws ResourceUnavailableFault, ResourceUnknownFault, Exception {|-------10--------20--------30--------40--------50--------60-------- 70--------80--------9||-------- XML error: The previous line is longer than the max of 90 characters ---------|     Element ele = (Element)configInfo.getElementsByTagName ("eMailID").item(0);     System.out.println(ele.getFirstChild().getNodeValue());     String emailIdfromClient = ele.getFirstChild().getNodeValue ();     String eMailIdValue = getAddressFacTory().createAddress (emailIdfromClient);|-------10--------20--------30--------40--------50--------60-------- 70--------80--------9||-------- XML error: The previous line is longer than the max of 90 characters ---------|     ResourceConfiguration resourceConfiguration = new ResourceConfiguration();     DocumentBuilderFacTory dbf = DocumentBuilderFacTory.newInstance();     DocumentBuilder db = dbf.newDocumentBuilder();     Document document = db.newDocument();     Text text = document.createTextNode(eMailIdValue);     resourceConfiguration.addConfigurationInfo(emailIdQName, text);     return resourceConfiguration;   }

使用 AddressFacTory 创建了资源后,LifeTimeManager 的 createResource 操作将以 ResourceConfiguration(用于以后识别 Address 实例)响应客户机。 ResourceConfiguration 信息将封装在返回到客户机应用程序的 EndPointReference 的 ReferenceParameter 中。

绑定 getResource() 操作

同样,当客户机应用程序要访问资源,以便使用其 Resource Property 文档 、销毁 WS-Resource、或是调用 WS-Resource 上的服务方法时,WSRF 首先将尝 试使用 AddressLifeTimeManager 中的 getResource() 操作来获取 Address 资 源实例。在 AddressFacToryImpl 的协助下,ResourceConfiguration 信息再次 用于惟一地识别 Address 资源实例。请注意 getResource() 操作调用了 AddressFacToryImpl 的 getAddress() 方法来定位 Address 对象:

清单 5. getResource 代码片段

public Object getResource(ResourceConfiguration resourceConfiguration)     throws ResourceUnavailableFault, Exception {     Node emailIdValue = resourceConfiguration.getConfigurationInfo(emailIdQName);|-------10--------20--------30--------40--------50--------60-------- 70--------80--------9||-------- XML error: The previous line is longer than the max of 90 characters ---------|     System.out.println(emailIdValue);     Text textInfo = (Text) emailIdValue;     System.out.println(textInfo);     String eid = textInfo.getNodeValue();     System.out.println("ID from getResource::AddressLifeTimeManager :"+eid);     Object addressObj = getAddressFacTory().getAddress(eid);     if(addressObj == null){       throw new ResourceUnavailableFault("Resource Not Available !!", new Exception());|-------10--------20--------30--------40--------50--------60-------- 70--------80--------9||-------- XML error: The previous line is longer than the max of 90 characters ---------|     }else{       return addressObj;     }   }

绑定 destroyResource() 操作

Address 资源可通过客户机应用程序的 destroy() 方法销毁,或者在达到 TerminationTime 后销毁。销毁资源时,资源框架将调用适配器组件的 AddressLifeTimeManager 类中的 destroyResource() 方法。 ResourceConfiguration 信息用于惟一地识别 Address 资源实例:

清单 6. destroyResource 代码片段

public void destroyResource(ResourceConfiguration resourceConfiguration)   throws ResourceUnavailableFault, ResourceNotDestroyedFault,Exception {     Node emailIdValue = resourceConfiguration.getConfigurationInfo(emailIdQName);|-------10--------20--------30--------40--------50--------60-------- 70--------80--------9||-------- XML error: The previous line is longer than the max of 90 characters ---------|     Text textInfo = (Text) emailIdValue;     String eid = textInfo.getNodeValue();     System.out.println("ID from destroyResource::AddressLifeTimeManager :"+eid);|-------10--------20--------30--------40--------50--------60-------- 70--------80--------9||-------- XML error: The previous line is longer than the max of 90 characters ---------|     getAddressFacTory().deleteAddress(eid);   }

绑定 PropertyManager 操作

Resource Property 文档的资源属性值始终由资源实例保存。资源框架不会缓 存这些值;但是框架将为任何给定的 WS-Resource 实例维护 Resource Property 文档中所有有效资源属性名称的列表。导致 WS-Resource 的 Resource Property 文档发生变化的所有 WSRF 消息将由适配器的 PropertyManager 类进行处理。您 可以选择使用消息,也可将这些消息转发给资源 bundle。

在 AddressPropertyManager 类中,生成的代码包含用于所有属性的 get/update/delete/insert 操作的占位符。如前所述,您可以提供实现用来传递 get 或 update 消息到 Address 资源。同样地,您可以选择传递 delete 和 insert 消息到 Address 资源实例。

在本例中,请注意 (a) 将 preference 属性的 update 操作作为 setPreference() 消息发送到 Address 资源实例,(b) 将 get 操作作为 getPreference 消息发送到 Address 资源,(c) 将 insert 操作作为 setPreference() 消息发送到 Address 资源实例,(d) delete 操作没有任何附 加的实现:

清单 7. AddressPropertyManager 代码片段

(a)  public void updatePreference(Object resource, Object value)     throws ResourceUnavailableFault,     UnableToModifyResourcePropertyFault,     UpdateResourcePropertiesRequestFailedFault,     InvalidModificationFault,     BaseFault, Exception {     com.ibm.wsrf.sampleapp.address.service.AddressInterface resourceRef =   (com.ibm.wsrf.sampleapp.address.service.AddressInterface) resource;     java.lang.String inValue = (java.lang.String)value;     resourceRef.setPreference(inValue);   }(b)  public Object getPreference(Object resource)     throws ResourceUnavailableFault, Exception {     com.ibm.wsrf.sampleapp.address.service.AddressInterface resourceRef =   (com.ibm.wsrf.sampleapp.address.service.AddressInterface) resource;     java.lang.String retValue = resourceRef.getPreference();     return retValue;   }(c)  public void insertPreference(Object resource, Object value)      throws ResourceUnavailableFault,     UnableToModifyResourcePropertyFault,     InsertResourcePropertiesRequestFailedFault,     InvalidModificationFault,     BaseFault, Exception {     com.ibm.wsrf.sampleapp.address.service.AddressInterface resourceRef =   (com.ibm.wsrf.sampleapp.address.service.AddressInterface) resource;     java.lang.String inValue = (java.lang.String)value;     resourceRef.setPreference(inValue);   }(d)  public void deletePreference(Object resource)     throws ResourceUnavailableFault,     DeleteResourcePropertiesRequestFailedFault, Exception {     com.ibm.wsrf.sampleapp.address.service.AddressInterface resourceRef =   (com.ibm.wsrf.sampleapp.address.service.AddressInterface) resource;   }

当客户机应用程序要获得 Address 通过 EndPointReference 指向的资源属性 值时,会将带有资源属性的 QName 的 getResourceProperty 消息作为参数进行 传递。资源框架将该消息发送到适配器组件,以便首先获得 Address 资源实例。 AddressLifeTimeManager 的 getResource() 操作获得了 Address 资源实例。接 着,资源框架调用 AddressPropertyManager 中的 getPreference() 操作。然后 ,AddressPropertyManager 的 getPreference() 操作将该消息传递给 Address 资源中相应的操作。

您必须为其它资源属性提供类似的实现。

提示:如果将资源属性设置为只读属性,则不必为这些操作提供任何附加的实 现就可以使用 update 和 insert 消息,或者在 update 和 insert 操作的实现 中抛出异常(例如,InvalidModificationFault)。如果将资源属性设置为强制 属性,则可以在 delete 操作的实现中抛出 DeleteResourcePropertiesRequestFailedFault 异常。

绑定服务管理器操作

WS-Resource 的定制端口类型(也称为服务方法)是适配器组件的 AddressServiceManager 的一部分。默认情况下,代码生成器所生成的代码将这 些操作分别绑定到 Address 资源的方法上。在这方面,您不必对所生成的代码进 行任何更改。

生成样本 WS-Resource 的客户端组件

完成了所有提供程序端组件(资源 bundle、适配器 bundle 和 Web 服务 bundle)的开发后,在 Lotus ExpediTor Toolkit 中将这些 WS-Resource 提供 程序组件部署为 WS-Resource。有关通过 WS-Resource 提供程序 bundle 启动 Client Services Server 的更多信息,请参考 Lotus ExpediTor Help 部分的 “Developing Applications for Lotus ExpediTor”。

若要确定 WS-Resource 是否为使用做好准备,请在浏览器中输入该 URL http://localhost/ws/pid/Address?wsdl,其中 WS-Resource 的 pid 是 Address。浏览器中应显示描述 Address 资源的 WSDL 文件。

现在,您可以使用 Mobile Web Services 工具来生成客户机组件。使用 (Mobile Web Services toolkit 的)WS-Resource Client 向导来生成 client stub 代码。请参考 Lotus ExpediTor Help 部分的 “Developing Applications for Lotus ExpediTor”,获取关于如何使用生成器向导来生成客户端组件的说明 。

您不需要对所生成的代码进行任何更改。

为 WS-Resource 开发简单的测试客户机应用程序

为了测试 WS-Resource,您必须开发测试应用程序。该测试应用程序使用客户 端组件进行以下操作:

创建新的 WS-Resource(Address)实例。

发送标准的 WSRF 消息。

通过定制 portType 调用操作。

测试客户机应用程序的 main() 方法如下所示:

清单 8. 测试客户机代码片段

public static void main(String[] args) {     String resourceUniqueId = "wsrf_support@ibm.com";     TestClient tc = new TestClient();     EndpointReference resEPR = null;     /**     * Creates the WS-Resource with the given resource configuration and     * returns the EPR for further interaction with the WS- Resource.     */     try {       resEPR = tc.createResource(resourceUniqueId);       if (resEPR != null)System.out.println("Resource created !! /n");     } catch (Exception e) {       e.printStackTrace();     }     OperationContext pContextObj = new OperationContext();     opContextObj.setToEPR(resEPR);     AddressSoap_Stub stubObj = new AddressSoap_Stub();     stubObj.setCurrentOperationContext(opContextObj);     boolean updateResult = tc.testUpdateResourceProperty();     if(updateResult == true)System.out.println("Update Resource Property :: SUCCESS");|-------10--------20--------30--------40--------50--------60-------- 70--------80--------9||-------- XML error: The previous line is longer than the max of 90 characters ---------|     else System.out.println("Update Resource Property :: FAILED");     boolean addResult = tc.testAddDependants();     if(addResult == true)System.out.println("Add Dependants :: SUCCESS");     else System.out.println("Add Dependants :: FAILED");   }}

请注意,上述代码包括以下步骤:

创建新的 Address 资源并获得 EndPointReference(EPR)。

设置 OperationContext。

测试 WSRF 标准操作,即 preference 资源属性的 updateResourceProperties。

测试服务方法,即 Address 资源的 addDependents 方法,该方法是添加一个 依赖项。

请参考 下载部分 以获得完整代码。

在前面的代码片段中,OperationContext 用于建立客户机和 WS-Resource 之 间的信道。OperationContext 容纳消息源(在 fromEPR 中)和消息目标(在 fromEPR 中)。必须确保 OperationContext 包含有效的 toEPR。在调用 WS- Resource 上的任何操作前,先通过调用 stub 对象的 setCurrentOperationContext(opContextObj) 操作来设置当前的 OperationContext。

如前所述,若要创建新的 Address 资源,在 ConfigInfo 参数和 TerminationTime 属性的初始值中必须将初始化参数作为 XML 文档进行发送。因 为使用 AddressLifeTimeManager 来解析以下 ResourceConfiguration XML 文档 ,所以 ConfigInfo XML 文档具有相同的结构:

清单 9. ConfigInfo XML 文档

            wsrf_support@ibm.com     

用于创建 WS-Resource 的代码如下所示:

清单 10. createResourcein 测试客户机代码片段

public EndpointReference createResource(String uniqueId)       throws Exception {     String hostName = "localhost"; // Hostname of the WebService     String serviceName = "Address"; // Service Name of the Resource     String uriString = "http://" + hostName + "/ws/pid/" + serviceName+ "?wsdl";|-------10--------20--------30--------40--------50--------60-------- 70--------80--------9||-------- XML error: The previous line is longer than the max of 90 characters ---------|     WSAddressingService addressingObj = new WSAddressingServiceImpl();     // creating the EPR of resourceFacTory     EndpointReference resourceFacToryEPR = addressingObj.createEndpointReference(uriString);|-------10--------20--------30--------40--------50--------60-------- 70--------80--------9||-------- XML error: The previous line is longer than the max of 90 characters ---------|     // prepare configInfo parameter for createResource()     Node[] configInfo = getConfigInfo(uniqueId);     // prepare initTerminationTime parameter for createResource ()     Calendar initTermTime = Calendar.getInstance();     int curr = initTermTime.get(Calendar.HOUR);     initTermTime.set(Calendar.HOUR, curr + 1);     // Prepare the channel for communicating with Resource FacTory     OperationContext pContextObj = new OperationContext();     opContextObj.setToEPR(resourceFacToryEPR); // Set the resourceFacToryEPR as toEPR|-------10--------20--------30--------40--------50--------60-------- 70--------80--------9||-------- XML error: The previous line is longer than the max of 90 characters ---------|     stubObj.setCurrentOperationContext(opContextObj);// Set the current OperationContext|-------10--------20--------30--------40--------50--------60-------- 70--------80--------9||-------- XML error: The previous line is longer than the max of 90 characters ---------|     // Send createResource() message to the resourceFacTory     EndpointReference resourceEPR = stubObj.createWSResource (configInfo, initTermTime);|-------10--------20--------30--------40--------50--------60-------- 70--------80--------9||-------- XML error: The previous line is longer than the max of 90 characters ---------|     return resourceEPR;   }

请注意清单 10 的以下内容:

为资源工厂构造了 EndpointPointReference 对象。在本例中, EndPointReference 的 URL 与 Address 资源本身的 URL 相同。

创建了从客户机到资源工厂的信道。创建了 OperationContext 对象,并将资 源工厂的 EndPointReference 设置为 toEPR。

使用 Address 资源的 stub 对象将 createResource() 消息发送到资源工厂 。

资源工厂使用新构造的 Address 资源对象的 EndPointReference 进行响应。

最后,执行测试应用程序时,将看到以下结果:

清单 11. 测试客户机的输出

Start Of Program !!   Resource created !!   Update Resource Property :: SUCCESS   Add Dependants :: SUCCESSEnd Of Program !!

设置运行时环境 (Lotus ExpediTor Client V6.1.0)

Lotus ExpediTor Client for Desktop 是用于部署 Address 资源的运行时。 在本部分,我们将介绍运行示例 WS-Resource 的运行时环境的设置步骤。

若要设置运行时,请参考 Lotus ExpediTor Help 中的安装说明,以便在 Windows / Linux 上安装 Lotus ExpediTor Client V6.1.0,以及在 Lotus ExpediTor Client 上安装 WSRF V6.1.0.0。

若要验证运行时设置,请执行以下步骤:

使用 -console 选项,启动 Lotus ExpediTor Client。

在 console 窗口中,键入 ss 来查看所有已安装插件的状态。

在插件列表中,检查 com.ibm.pvcws.osgi_6.1.0 插件和所有 WSRF 插件是否 处于活动状态。如果未处于活动状态,则启动这些插件。

在 Lotus ExpediTor 中部署样本 WS-Resource

启动并运行 Lotus ExpediTor Client for Desktop 后,请按照以下步骤来部 署 Address WS-Resource 提供程序组件。请参考 下载部分 的 README.txt 来部 署 AddressResource 的预构建功能。

为部署准备 Address WS-Resource 特性

若要在 Lotus ExpediTor Client for Desktop 中安装 Address WS-Resource ,则必须将 WS-Resource 打包成一项特性。请按照以下步骤来创建特性:

例如,选择 File – New – AddressFeature,在 Lotus ExpediTor Toolkit 中创建新特性项目。

在 Referenced Plug-ins and Fragments 窗口中,选择 AddressResource、 AddressAdapter 和 AddressWebservice 插件。

单击 Finish。

右键单击新建的特性项目,然后选择菜单中的 Export。

在 Export 窗口中,选择 Deployable features 选项,然后单击 Next。

输入目录并单击 Finish。

将 WS-Resource 部署为特性

若要将 WS-Resource 部署为特性,请执行以下步骤:

在 Lotus ExpediTor Client 中,选择 File – Applications – Install。

选择 “Search for new features to install”,然后单击 Next。

单击 Add Folder Location,选择在上述步骤 5 中导出特性的位置,然后单 击 Finish。

重新启动 Lotus ExpediTor Client 使部署生效。

验证 WS-Resource 的部署

启动 Lotus ExpediTor Client (带有 -console 选项)后,通过检查 console 窗口来确保已启动新安装的插件。

在浏览器中输入 URL http://HostAddress:Port/ws/pid/ResourcePID?wsdl, 可以验证是否正确发布了 Address 资源的 WSDL,其中 HostAddress 是承载 Lotus ExpediTor Client 的节点的 IP 地址,Port 是运行 Web 服务的端口, ResourcePID 是资源的名称。

例如,示例 URL 可能是 http://localhost/ws/pid/Address?wsdl,假定 Lotus ExpediTor Client V6.1.0 Web 容器组件运行在端口 80 上并接受所有 IP 地址。

执行样本客户机应用程序

在 Lotus ExpediTor Client for Desktop 中部署了 Address 资源后,您可 以执行本文所提供的样本客户机应用程序。该示例应用程序是基于 Standard Widget Toolkit(SWT)的 Java 程序,允许您发送各种 WSRF 标准消息以及由 Address 资源定义的定制消息。

该客户机应用程序演示了 Lotus ExpediTor Client 的 WSRF 的所有 API 特 性。可以使用菜单选项 WSRF Standard Operations 和 WSRF Custom Operations 来研究这些特性。在 WSRF Custom Operations 菜单中,您可以尝试工厂和服务 方法(参见图 2)。

图 2. WSRF Custom Operations 菜单

在 WSRF Standard Operations 菜单中,您可以尝试所有 WSRF 资源属性操作 和 WSRF lifetime 操作(参见图 3)。

图 3. WSRF Standard Operations 菜单

结束语

您已经学习了如何构建简单的 WS-Resource 以及如何将其部署到 Lotus ExpediTor Client for Desktop。另外,还学习了用于生成提供程序端和客户端 组件的工具,以及如何开发可用来测试本文中所开发的 WS-Resource 的测试客户 机。

本文配套源码

别为坎坷阻力而叹息,用乐观心态面对人生遭遇,

在IBMLotusExpeditor中构建并部署简单的Web服务资源

相关文章:

你感兴趣的文章:

标签云: