DataPower WebServiceProxy选择数据

时间:2016-12-30 14:05:55

标签: java web-services soap ibm-datapower new-webserviceproxy

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

UsersCatalog.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);
    }
}

我在数据电话中听说过一种叫做消息转换的东西。如果我只能选择要返回的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。如何收到这样的结果?

1 个答案:

答案 0 :(得分:0)

您可以使用“变换”操作和XSLT来满足此要求。创建Web服务代理(WSP)时,将为每个操作自动创建一个处理规则。您可以在WSP的“策略”选项卡中查看那些处理规则。您可以在为getUserData操作创建的规则中添加一个Transform操作。

要了解如何创建XSLT以从XML中排除元素,可以看一下this page