2

我正在寻找问题的解决方案。我将从一个示例开始:我们有一个返回 userData (userName + userAddress) 的 SOAP Web 服务,我正在使用 Web 服务代理来提取 UserData,但是我只想接收 userName - 这需要通过 DataPower 来完成出色地。如何做到这一点?我正在考虑添加另一个 Web 服务代理,但是如何将逻辑添加到只选择用户名的应用程序中?dp中是否有任何消息转换?

用户目录.wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://wtp" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://wtp" xmlns:intf="http://wtp" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
 <wsdl:types>
  <schema elementFormDefault="qualified" targetNamespace="http://wtp" xmlns="http://www.w3.org/2001/XMLSchema">
   <element name="getUserData">
    <complexType/>
   </element>
   <element name="getUserDataResponse">
    <complexType>
     <sequence>
      <element maxOccurs="unbounded" name="getUserDataReturn" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="setUserData">
    <complexType>
     <sequence>
      <element name="userName" type="xsd:string"/>
      <element name="userAddress" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="setUserDataResponse">
    <complexType/>
   </element>
  </schema>
 </wsdl:types>

   <wsdl:message name="setUserDataResponse">

      <wsdl:part element="impl:setUserDataResponse" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="getUserDataRequest">

      <wsdl:part element="impl:getUserData" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="setUserDataRequest">

      <wsdl:part element="impl:setUserData" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="getUserDataResponse">

      <wsdl:part element="impl:getUserDataResponse" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:portType name="UsersCatalog">

      <wsdl:operation name="getUserData">

         <wsdl:input message="impl:getUserDataRequest" name="getUserDataRequest">

       </wsdl:input>

         <wsdl:output message="impl:getUserDataResponse" name="getUserDataResponse">

       </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="setUserData">

         <wsdl:input message="impl:setUserDataRequest" name="setUserDataRequest">

       </wsdl:input>

         <wsdl:output message="impl:setUserDataResponse" name="setUserDataResponse">

       </wsdl:output>

      </wsdl:operation>

   </wsdl:portType>

   <wsdl:binding name="UsersCatalogSoapBinding" type="impl:UsersCatalog">

      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="getUserData">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="getUserDataRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="getUserDataResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="setUserData">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="setUserDataRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="setUserDataResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

   </wsdl:binding>

   <wsdl:service name="UsersCatalogService">

      <wsdl:port binding="impl:UsersCatalogSoapBinding" name="UsersCatalog">

         <wsdlsoap:address location="http://localhost/WebServiceProject/services/UsersCatalog"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>

UsersCatalog.java(UserImpl 类有 2 个字段 - userName 和 userAddress + setter 和 getter 一次在字符串数组中设置/获取它们)

package wtp;

import javax.jws.WebMethod;
import javax.jws.WebService;


@WebService
public class UsersCatalog implements User{
    public static final User userImpl = new UserImpl();


    @Override
    @WebMethod
    public String[] getUserData() {
        System.out.println("getUserData");
        return userImpl.getUserData();
    }

    @Override
    @WebMethod
    public void setUserData(String userName, String userAddress) {
        System.out.println("setUserData");
        userImpl.setUserData(userName, userAddress);
    }
}

我听说过一种叫做 datapower 中的消息转换的东西。如果我可以选择要返回的 xml 实体,这将变得如此简单。

我将添加更多内容以更好地指定我的需求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <getUserDataResponse xmlns="http://wtp">
         <getUserDataReturn>John</getUserDataReturn>
         <getUserDataReturn>New York</getUserDataReturn>
      </getUserDataResponse>
   </soapenv:Body>
</soapenv:Envelope>

这就是我收到的,我希望 DataPower 以某种方式对其进行转换以仅返回第一行 - 仅返回用户名 John。如何收到这样的结果?

4

1 回答 1

0

您可以使用 Transform 操作和 XSLT 来实现此要求。创建 Web 服务代理 (WSP) 时,会自动为每个操作创建处理规则。您可以在 WSP 的 Policy 选项卡中查看这些处理规则。您可以将 Transform 操作添加到为 getUserData 操作创建的规则中。

要了解如何创建 XSLT 以从 XML 中排除元素,您可以查看此页面

于 2018-12-30T18:25:55.523 回答