将 Apache SOAP Web Service 迁移到基于 Java EE 标准的 JAX-RPC Web Service

可以将使用 Apache SOAP 开发的 Web Service 迁移到根据 Web Services for Java™ Platform, Enterprise Edition (Java EE) 规范开发的 Java API for XML-based RPC (JAX-RPC) Web Service。

开始之前

如果您已使用基于 Apache SOAP 的 Web Service,但现在想要开发和实现基于 Java 的 Web Service,那么需要迁移使用所有 4.0 版本及 5.0.2 之前的所有 5.0 版本来开发的客户机应用程序。

关于此任务

已除去基于 Apache SOAP 实现的 SOAP 安全性(XML 数字签名)。将应用程序迁移到 Web Service 的 JSR-109 实现并进行重新配置,而不是使用 SOAP-Security。

要根据 Java 标准迁移这些客户机应用程序:

过程

  1. 计划您的迁移策略。 可以使用两种方法中的一种将 Apache SOAP 客户机移植到 JAX-RPC Web Service 客户机:
    • 如果您具有服务的 Web 服务描述语言 (WSDL) 文档或者可以创建服务的 WSDL 文档,请考虑使用 WSDL2Java 命令工具来生成 Web Service 的绑定。将 Apache SOAP 客户机改变为使用已生成的 JAX-RPC 绑定需要进行很多工作,但产生的客户机代码更可靠,并且更易于维护。

      要遵循此方法,请参阅信息中心中有关开发 Web Service 客户机的文章。

    • 如果您没有服务的 WSDL 文档,不想更改服务,并且要用最小的工作量移植 Apache SOAP 客户机,您可以将代码转换为使用类似于 Apache SOAP API 的 JAX-RPC 动态调用接口 (DII)。DII API 不使用 WSDL 或已生成的绑定。
    因为 JAX-RPC 不为用户编写的序列器指定框架,因此 JAX-RPC 不支持使用定制序列化器。如果您的应用程序无法遵循 WebSphere® Application Server 支持的 Java、WSDL 和 XML 技术之间的缺省映射,请不要尝试迁移应用程序。 本主题的以下部分假设您确定使用 JAX-RPC 动态调用接口 (DII) API。
  2. 查看 GetQuote 样本。 可以在信息中心的“样本”部分中找到 Web Service 迁移样本。此样本位于 GetQuote.java 文件中,最初是为 Apache SOAP 用户编写且包含有关迁移到 JAX-RPC DII 接口所需的更改说明。要了解更多信息,请参阅信息中心中的“样本”部分。
  3. 将客户机应用程序从 Apache SOAP 转换到 JAX-RPC DII Apache SOAP API 和 JAX-RPC DII API 的结构类似。您可以在它们中实例化和配置 Call 对象、设置参数、调用操作和处理结果。 您可以在 JAX-RPC 中,使用下列命令创建 Service 对象的一般实例:
    javax.xml.rpc.Service service = ServiceFactory.newInstance().createService(new QName(""));
    in JAX-RPC.
    1. Create the Call object. An instance of the Call object is created with the following code:
      org.apache.soap.rpc.Call call = new org.apache.soap.rpc.Call ()
      in Apache SOAP.
      An instance of the Call object is created by
      java.xml.rpc.Call call = service.createCall();
      in JAX-RPC.
    2. Set the endpoint Uniform Resource Identifiers (URI). The target URI for the operation is passed as a parameter to
      call.invoke:  call.invoke("http://...", "");
      in Apache SOAP.
      The setTargetEndpointAddress method is used as a parameter to
      call.setTargetEndpointAddress("http://...");
      in JAX-RPC.

      Apache SOAP has a setTargetObjectURI method on the Call object that contains routing information for the request. JAX-RPC has no equivalent method. The information in the targetObjectURI is included in the targetEndpoint URI for JAX-RPC.

    3. Set the operation name. The operation name is configured on the Call object by
      call.setMethodName("opName");
      在 JAX-RPC 中使用 setOperationName 方法,其接受 QName 而不是 String 参数,如下面示例中的描述:
      call.setOperationName(new javax.xml.namespace.Qname("namespace", "opName"));
    4. Set the encoding style. The encoding style is configured on the Call object by
      call.setEncodingStyleURI(org.apache.soap.Constants.NS_URI_SOAP_ENC);
      in Apache SOAP.
      The encoding style is set by a property of the Call object
      call.setProperty(javax.xml.rpc.Call.ENCODINGSTYLE_URI_PROPERTY, "http://schemas.
      xmlsoap.org/soap/encoding/");
    5. 声明参数和设置参数值。 Apache SOAP 参数类型和值由参数实例描述,在调用前,将它们收集到向量中并且在 Call 对象上设置,例如:
      Vector params = new Vector (); 
      params.addElement (new org.apache.soap.rpc.Parameter(name, type, value, encodingURI)); 
      // repeat for additional parameters... 
      call.setParams (params);
      对于 JAX-RPC,用参数名和类型(不需要提供它们的值)配置 Call 对象,例如:
      call.addParameter(name, xmlType, mode); 
      // repeat for additional parameters 
      call.setReturnType(type);
      其中:
      • name (type java.lang.String) 是参数的名称
      • xmlType (type javax.xml.namespace.QName) 是参数的 XML 类型
      • mode (type javax.xml.rpc.ParameterMode) 是参数的方式,例如:IN、OUT 或 INOUT
    6. 进行调用。 已通过 Apache SOAP 中的
      org.apache.soap.Response resp = call.invoke(endpointURI, "");
      in Apache SOAP.
      The parameter values are collected into an array and passed to call.invoke as illustrated in the following example:
      Object resp = call.invoke(new Object[] {parm1, parm2,...});
      in JAX-RPC.
    7. Check for faults. You can check for a SOAP fault on the invocation by checking the response:
      if resp.generatedFault then {   
      org.apache.soap.Fault f = resp.getFault;   
      f.getFaultCode();   
      f.getFaultString(); 
      }
      如果调用时发生 SOAP 故障,那么 JAX-RPC 中显示 java.rmi.RemoteException 错误。
      try {   
      ... call.invoke(...) 
      } catch (java.rmi.RemoteException) ...
    8. 检索结果。 在 Apache SOAP 中,如果调用成功并返回结果,那么可以从 Response 对象获取此结果:
      Parameter result = resp.getReturnValue(); return result.getValue();
      In JAX-RPC, the result of invoke is the returned object when no exception is displayed:
      Object result = call.invoke(...);
       ... 
      return result;

结果

您已将 Apache SOAP Web Service 迁移到基于 Java EE 规范的 JAX-RPC Web Service。

下一步做什么

根据 Web Services for Java EE 规范开发 Web Service 客户机。

测试已启用 Web Service 的客户机以确保迁移过程是成功的,并确保您可以在 Java EE 环境中实现这些 Web Service。


指示主题类型的图标 任务主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twbs_migratewbs
文件名:twbs_migratewbs.html